有没有“分裂"?用于 SELECT 查询的 t-sql 中的函数

is there a quot;splitquot; function in t-sql for a SELECT query(有没有“分裂?用于 SELECT 查询的 t-sql 中的函数)
本文介绍了有没有“分裂"?用于 SELECT 查询的 t-sql 中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想像这样使用我的功能

I want to use my function like this

SELECT BaseSplit(line,';') FROM table

有没有办法做到这一点???

is there any way to do that ???

我尝试了 CROSS APPLY 但它不是我想要的

I try CROSS APPLY but it not what I want

我的表格有一列名为 line

My table has a column named line

line 
______
15;2;5
NULL
10;3;6

我想将此列拆分为像

15
2
5
Null
10
3
6

是否有自动执行此操作的字符串函数?
如果没有,是否可以编写自己的函数?

Is there a string function that does this automatically?
If not, is it possible to write my own function?

推荐答案

它应该可以正常工作,但您需要对函数进行模式限定.

It should work fine, but you need to schema-qualify functions.

浏览器:

SELECT dbo.BaseSplit(line,';') FROM table

如果您的函数在与 dbo 不同的架构中,您显然应该改用它.

If your function is in a different schema than dbo you should obviously use that instead.

好的 - 假设它是一个表值函数然后......

OK - assuming its a table valued function then...

SELECT t.Id, f.*  FROM table AS t CROSS APPLY dbo.BaseSplit(line,';') AS f

这将为每个分割线返回一行 + 主表中该条目的 ID(假设主表中存在名为 Id 的列).如果您想要更好,我将需要一个您期望的输出示例

That would return a row for each split line + the ID of the that entry in the main table (assuming a column named Id exists in the main table). If you want better that that I'm going to need an example of what output you expect

这篇关于有没有“分裂"?用于 SELECT 查询的 t-sql 中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
SQL query to group by day(按天分组的 SQL 查询)
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)