如何在sqlserver中使用Split函数

问题描述:

嗨朋友们,



我有一张像ShownBelow的桌子...



Hi Friends,

I have one Table like ShownBelow...

Domain Name	Min Years	MaxYears
.com                2               10
.net                4               12
.co                 1               12
.buz                1               13





但是将参数传递给存储过程就像这样.com,.net,.co

现在我需要拆分这个值并检查数据库,然后再次需要返回上表中的数据集





But Am passing parameter to stored procedure like this way .com,.net,.co
Now i need to split this value and check with database and again i need to return dataset like above table

Domain Name	Min Years	MaxYears
.com                2               10
.net                4               12
.co                 1               13
.buz                1               13

AFAIK,SQL Server没有拆分功能。



但是像这个 [ ^ ]可能对您有所帮助。
AFAIK, there is no split function is SQL Server.

However something like this[^] might help you.


您好,



另请参见:



Hi,

See this also:

declare @str varchar(100)
set @str = "val1_val2,val3_val4"


declare @str varchar(100) = 'val1_val2,val3_val4'

select substring(f.value, 0, charindex('_', f.value)) as val1
      ,substring(f.value, charindex('_', f.value) + 1, LEN(f.value) ) as val2
from dbo.fnSplitString(@str, ',') f





也可以查看此链接。

SQL Server中的数组和列表



谢谢



Checkout this link too.
Arrays and Lists in SQL Server

Thanks