sql server - working of charindex,cross apply and substring in single query of sql -


i have query follows display @prodid= ''1,2,10,4,5,6,7,8,13,16,17,3'' string 'dbo.proudction @prodid= ''1,2,10,4,5,6,7,8,13,16,17,3'' ,@stock= 0':

declare @t table(col1 varchar(100)) insert @t values ('dbo.proudction @prodid= ''1,2,10,4,5,6,7,8,13,16,17,3'' ,@stock= 0')  select    substring(col1, start, stop-start) @t   cross apply      (select charindex('''', col1)+1) c1(start)   cross apply     (select charindex('''', col1, start)) c2(stop) 

can me understand working of query, please ?

the first cross apply use charindex locate first quote in string. second cross apply locates second quote in string. substring extract text between first quote , second quote.

result

1,2,10,4,5,6,7,8,13,16,17,3 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -