sql - Get a specific string -


it's data , every throughroutesid record has same pattern. 6 number , 5 comma. want 3 , 5 number 2 record template table , same count() value these 2 record.

for example: first record in picture.

throughroutesid(3730,2428,2428,3935,3935,3938,) count(32).

i want result this: 2428 32 3935 32 number want.become 2 record , both have same count value template table

my data picture

you can use xml result, please refer below sample code -

create table #t1( throughroutesid varchar(500) , cnt int)  insert #t1 select '3730,2428,2428,3935,3935,3938,' , len('3730,2428,2428,3935,3935,3938,') union select '1111,2222,3333,4444,5555,6666,' , len('1111,2222,3333,4444,5555,6666,')  select   cast( '<xml><td>' + replace( substring(throughroutesid ,1 , len(throughroutesid)-1),',','</td><td>') + '</td></xml>' xml) xmldata , cnt  #t2  #t1  select xmldata.value('(xml/td)[3]' ,'int' ), cnt ,xmldata.value('(xml/td)[5]' ,'int' ), cnt    #t2 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -