Question : SQL - Combining multiple fields into one

Hello Experts,

I need to build an SQL statement to pull all Lot #s associated with each Issue #. The problem is that the Lot Numbers are stored in two different places (dbo.Incident.LotNumber and dbo.Subform.AdditionalLotNumbers). The two tables are linked on Incident.IncidentID = Subform.ParentID where Subform.Category = ‘Lot Numbers’. Right now, I can pull them all using a UNION query, which has an output like this:

Issue Number'      'Lot Number'
7450      C9118H10
7451      A9048A02
7452      c8108
7452      c8112
7452      C9176
7452      C9174
7452      C9190
7452      C8160
7452      C8154
7452      C9198
7452      C9186

What I’d like to do is generate the output so that all the lots associated in Issue # 7452 are pulled into one field, separated by commas, so it would look like this:

Issue Number'      'Lot Number'
7450      C9118H10
7451      A9048A02
7452      c8108, c8112, C9176, C9176, C9174, C9190, C8160, C8154, C9198, C9186

Can I do this with just SQL, or do I have to create a Stored Procedure? Any ideas?

Answer : SQL - Combining multiple fields into one

There is a Sourceforge project: http://sourceforge.net/projects/ghde/
Random Solutions  
 
programming4us programming4us