Sample Call
select @Statecode = ‘IL, IN,KY’
select ColumnData from dbo.fn_CSVToTable(@Statecode)
Create Function dbo.fn_CSVToTable (@CSVList Varchar(3000))
Returns @Table Table (ColumnData Varchar(50))
As
Begin
If right(@CSVList, 1) <> ','
Select @CSVList = @CSVList + ','
Declare @Pos Smallint,
@OldPos Smallint
Select @Pos = 1,
@OldPos = 1
While @Pos < Len(@CSVList)
Begin
Select @Pos = CharIndex(',', @CSVList, @OldPos)
Insert into @Table
Select LTrim(RTrim(SubString(@CSVList, @OldPos, @Pos - @OldPos))) Col001
Select @OldPos = @Pos + 1
End
Return
End
Thanks!
[...] Collection erzeugt, der ist ja leicht zu schreiben. Und die Funktion in T-SQL ist hier beschrieben: http://codebank.wordpress.com/2007/0…sv-to-table-2/ Es gibt auch noch aufwändigere Möglichkeiten. oder man verwendet XML wie in [...]
[...] generally feed my CSVs into a table with something like this…. Simple SQL CSV to Table Code Bank and then I join to the table. __________________ you are the sum of your record [...]