sql server - SQL reading from a comma delimited field and then bringing data back in comma delimited format -


i have data in string format 3,2,1 in table column. have lookup table tells me file name associated file

table looks this

id (int) name ------------------   1      file 1   2      file 2 

what want send string 3,2,1 , data file 1, file 2 separate column can refer in displaying. mind addition existing stored procedure that's why want 1 string row back

thanks in advance help

you may want write code this. below code it's example put on right track. let me know if have questions

declare @input varchar(max) declare @index1 int declare @index2 int declare @id varchar(10) declare @str varchar(max) declare @result varchar(max)  set @input = '3,2,1'; set @str = reverse(@input) set @index1 = 1; set @index2 = charindex(',', @str) set @id = substring(@str, @index1, @index2 -@index1)  set @result = 'file ' + @id + ','  while (@index2 > 0 ) begin      set @str = substring(@str, @index2 + 1, len(@str) -@index1)     set @id = substring(@str,@index1,@index2 -@index1)      set @index1 = @index2     set @index2 = charindex(',', @str)     if len(@id) > 0         set @result = @result + 'file ' + @id + ',' end  set @id = @str; set @result =  @result + 'file ' + @id  select @result 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -