How to select specific data between Quotes (")

孤者浪人 提交于 2019-12-25 18:54:09

问题


I am reposting my question as I am new to SQL 2012.

I want to fetch the numeric data between quotes (") in the following rows,

row1:'asdalknd,"1,2,3,4",slknsdl,"5,6,7,8",snlsn'

row2:'asknd,"111,267,387,4756",snsdl,"534,646,767,348",snlssdsdsdsjkvkn'

row3'....

row4'....

row5'....

row6'...

row7'...

row8'....

The above mentioned are the rows of a single column.

I just want to extract the numerics(may be in another column for each rows)

Can anybody pls help, as this is way above my basic knowledge of t-sql.

Thanks


回答1:


this is Ugly, but will eventually work:

COLUMN = 'jksjdksls#$#$@@kskjfjf,"123,456,789" lsnslkdswfnslsjfls'

left( right(COLUMN,len(COLUMN)-instr(COLUMN,"""")), instr( right(COLUMN,len(COLUMN)-instr(COLUMN,"""")), """") -1 )

--> 123,456,789

This is what is done:

  • We take this string 'jksjdksls#$#$@@kskjfjf,"123,456,789" lsnslkdswfnslsjfls'
  • find the first occurence of " with instr(COLUMN,"""") --> returns 24
  • take the right end of the string with. Therefore we need to take the length of the string with len(COLUMN)--> 55 and substract the position of the first " (24)
  • then we need to find the second " with instr()in the right string, which we need to create again with right(COLUMN,len(COLUMN)-instr(COLUMN,"""")) and substract 1 for the ".


来源:https://stackoverflow.com/questions/24704629/how-to-select-specific-data-between-quotes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!