SQL parse string added to temporary table SQL stored procedure in parameter input workaround
Adding string parsing to a staging table
SELECT * into #临时表 from dbo. Func_splitonecolumntabel (' 001,gf ', ', ')
SELECT * FROM table where ID in (SELECT ID from temp table)
Create function [dbo]. [Func_splitonecolumntabel]
(@str nvarchar (max), @split varchar (10))
Returns @t Table (KeyColumn varchar (200))
As
Begin
While Len (@str) >0
Begin
If CHARINDEX (@split, @str) >0
Begin
INSERT into @t (keycolumn) VALUES (left (@str, CHARINDEX (@split, @str)-1))
Set @str =right (@str, Len (@str)-charindex (@split, @str))
End
Else
Begin
INSERT into @t (keycolumn) VALUES (@str)
Set @str = ' '
End
End
Return
End
How to use
SELECT * FROM dbo. Func_splitonecolumntabel (' 001,gf ', ', ')
Results
KeyColumn
001
Gf
SQL parse string added to temp table in SQL stored procedure in parameter input