海蘭,我有多個值,我需要檢查
列表 例如:
1,2,4,
3,4,
應該是:逗號分隔值到多個位列
day1 day2 day3 day4
_1____1____0____1
_0____0____1____1
一種方法是
CAST(CASE WHEN PATINDEX('1,', [day]) > 0 THEN 1 ELSE 0 END AS BIT) as [day1],
CAST(CASE WHEN PATINDEX('2,', [day]) > 0 THEN 1 ELSE 0 END AS BIT) as [day2],
CAST(CASE WHEN PATINDEX('3,', [day]) > 0 THEN 1 ELSE 0 END AS BIT) as [day3],
CAST(CASE WHEN PATINDEX('4,', [day]) > 0 THEN 1 ELSE 0 END AS BIT) as [day4]
請幫助我一個更好的方法,因爲我有多個列
謝謝
你可以有1,2,4,15000作爲輸入?什麼限制? –
這裏是一篇關於它的文章:http://www.sqlteam.com/article/parsing-csv-values-into-multiple-rows – Chris
@Chris我知道我可以返回一個包含多行的表,但我需要多個'Columns ' – Zyku