こんにちは、データベースから値を取得しようとしています。「、」で区切られた複数の画像名を持つ行があります。それらを別の行に表示したい。2 つの値に対して正常に動作する次のコードを使用しています。しかし、3 つ以上の値がある場合でも、返されるのは 2 つだけです。これは私のクエリです:
;with tmp(ImageURL,HeritageId) as
(
select LEFT(ImageURL, CHARINDEX(',',ImageURL+',')-1),
STUFF(ImageURL, 1, CHARINDEX(',',ImageURL+','), '')
from shop.dbo.Images where HeritageId=@HeritageId
union all
select right(ImageURL, CHARINDEX(',',ImageURL+',')-1),
STUFF(ImageURL, 1, CHARINDEX(',',ImageURL+','), '')
from Images
where ImageURL > '' and HeritageId=@HeritageId
)
select ImageURL
from tmp