c# - split values separated by comma's in different lines -


hi trying retrieve values database. have row has multiple image names separated ",". want display them in different lines. using following code working fine 2 values. when have 3 or more values gives two. query:

;with tmp(imageurl,heritageid)  (  select  left(imageurl, charindex(',',imageurl+',')-1),     stuff(imageurl, 1, charindex(',',imageurl+','), '') shop.dbo.images heritageid=@heritageid union select  right(imageurl, charindex(',',imageurl+',')-1),     stuff(imageurl, 1, charindex(',',imageurl+','), '') images imageurl > '' , heritageid=@heritageid ) select  imageurl tmp 

your query looks attempt use recursive cte split string. case should this.

;with tmp(imageurl,rest)  (  select  left(imageurl, charindex(',',imageurl+',')-1),     stuff(imageurl, 1, charindex(',',imageurl+','), '') images heritageid=@heritageid union select  left(rest, charindex(',',rest+',')-1),     stuff(rest, 1, charindex(',',rest+','), '') tmp rest > '' ) select  imageurl tmp 

use cte in recursive part instead of table.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -