sql - List unique values from column based on an ID Field -


warning i'm newbie sorry if there wrong question or explanation ...

i have table 'xyz' list of attachments (origfilename) , field uniqueattchid on header table 'abc' record link can query attachments relate record.

i need bring results of records uniqueattchid equal on header , add them header 'abc' field called 'udattch' memo field formatted , separator

this around limitation of reporting functionality available me can use actual field database not related table.

current setup:-

xyz table uniqueattchid    origfilename ----------      ------------- 18181818181   |   filename1 18181818181   |   filename2 18181818181   |   filename3 18181818182   |   filename1 
abc table -  description|field2|uniqueattchid| test item  |test  |18181818181 test item 2|test2 |18181818182  

desired result:-
(xyz table remain unchanged)

 abc table -  description|field2|uniqueattchid|udattch| test item  |test  |18181818181  |filename1, filename2, filename3| test item 2|test2 |18181818182  |filename1| 

i've tried using coalesce doesn't give me separate record each uniqueattchid 1 records, , select distinct produced first record in origfilename

i can generate stored procedure run required , update record when new files added attachments.

please try:

select      *,      stuff((select ',' + origfilename        xyz b b.uniqueattchid=a.uniqueattchid         xml path(''),type).value('.','nvarchar(max)'),1,1,'') [udattch] abc 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -