i have split function:
create function splitstring (@input nvarchar(max), @character char(1)) returns @output table (item nvarchar(1000)) begin declare @startindex int, @endindex int set @startindex = 1 if substring(@input, len(@input) - 1, len(@input)) <> @character begin set @input = @input + @character end while charindex(@character, @input) > 0 begin set @endindex = charindex(@character, @input) insert @output(item) select substring(@input, @startindex, @endindex - 1) set @input = substring(@input, @endindex + 1, len(@input)) end return end go i want use function in stored procedure, procedure doing insert:
insert table1 (key, description) values (select ident_current('table2'), select item webreports.splitstring('a','b','c') ) the target table has 2 columns key , description. key column sourced other identity column table, , description column inserted result of function, sub-string.
the procedure not working properly.
no need use values:
insert table1 ([key], descrption) select ident_current('table2'), item dbo.splitstring('a,b,c', ',') as side note, splitstring function not optimal. should doing set-based fashion rather rbar. aaron bertrand wrote article on different ways split strings. can read here.
Comments
Post a Comment