开发者

sql column value splitting

I开发者_JAVA技巧 have an sql column which consists of four concatenated words separated with slashes ("/"). The words can be any random words of variable length. How can I retrieve each word separately. What is the query I need to write?

Thanks


Not "the fastest way" but it will work.

with extract1 as 
(
   SELECT substring(data, 1, charindex('/', data)-1) AS data1, 
  substring(data, charindex('/', data)+1, LEN(data)) AS data
  from atable
), extract2
(
   SELECT data1,substring(data, 1, charindex('/', data)-1) AS data2, 
  substring(data, charindex('/', data)+1, LEN(data)) AS data
  from extract1
)
  SELECT data1,data2,substring(data, 1, charindex('/', data)-1) AS data3, 
  substring(data, charindex('/', data)+1, LEN(data)) AS data4
  from extract2
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜