question

tsaliki avatar image
tsaliki asked

query related to split function

Hi, ihave a table like below: CREATE TABLE testjob ( jobid INT , jobname VARCHAR(100) , time FLOAT , name VARCHAR(50) ) INSERT INTO testjob VALUES ( 1001, 'java work', 4.5, 'arjun' ) INSERT INTO testjob VALUES ( 1005, 'sql work', 10, 'arjun' ) INSERT INTO testjob VALUES ( 1010, '.net work', 7.5, 'arjun' ) INSERT INTO testjob VALUES ( 1040, 'java work', 5.5, 'ravi' ) INSERT INTO testjob VALUES ( 1023, 'php work', 2.5, 'arjun' ) INSERT INTO testjob VALUES ( 1027, '.net work', 3.5, 'ravi' ) i have a query as below: select jobname from testjob where jobid in (select items from dbo.split('1001,1005',',')) the output is as below: Jobname Javawork sql work Instead i want the output beside like this : i.e i want it side by side. Jobname Javawork,sqlwork
sql-server-2005split
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
ThomasRushton avatar image
ThomasRushton answered
This is the old string concatenation using the XML PATH trick: SELECT STUFF(( SELECT ','+jobname FROM testjob t2 WHERE t2.jobid IN (1001,1005) FOR XML PATH('')), 1, 1, '')
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@Thomas Rushton Thank you.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.