April 26, 2022 at 5:28 am
Hi
I want if multiple records are returned by inner query then Docno of all records should get concatenated with comma separation.
Select T1.Itemcode,T1.name ,(select docno from order where id = T0.id)
from tbl1 T0 inner join tbl2 on T0.itemcode = t1.itemcode
Thanks
April 27, 2022 at 6:10 am
Thanks for posting your issue and hopefully someone will answer soon.
This is an automated bump to increase visibility of your question.
April 27, 2022 at 3:23 pm
STRING_AGG() is your friend
April 27, 2022 at 3:30 pm
STRING_AGG isn't available before SQL 2016, right?
Select T1.Itemcode,T1.name ,
stuff((select ', ' + docno
from [order] o
where o.id = T0.id
order by docno
for xml path(''), type).value('.', 'varchar(8000)'), 1, 2, '') as docnos
from tbl1 T0
inner join tbl2 on T0.itemcode = t1.itemcode
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy