Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SELECT question

Author  Topic 

tim8w
Starting Member

10 Posts

Posted - 2010-10-27 : 16:18:24
I have this selection that returns 5 fields. I would like to combine lines returned that have a common 'ReferenceNumber'. Here's my query:

SELECT tabMedia.ReferenceNumber, tabReferenceNoInfo.Title, tabMediaTypeLookup.Media, tabReplicatorLookup.ReplicatorName, tabMedia.FinishDate
FROM tabMedia INNER JOIN
tabReferenceNoInfo ON tabMedia.ReferenceNumber = tabReferenceNoInfo.ReferenceNumber INNER JOIN
tabMediaTypeLookup ON tabMedia.MediaTypeID = tabMediaTypeLookup.MediaTypeID INNER JOIN
tabReplicatorLookup ON tabMedia.ShipToCompanyID = tabReplicatorLookup.ReplicatorID
WHERE (tabMedia.ReferenceNumber IN (
'392185',
'392366',
'392424',
'392717',
'392721',
'392723',
'392798',
'393001',
'444000'
))
ORDER BY tabMedia.ReferenceNumber ASC


This query generates something like this for output:

ReferenceNumber Title ReplicatorName
392424 This is the Title Location1
392424 This is the Title Location2
392424 This is the Title Location3
444000 This is the Title Location2

Is there an easy way to combine the common ReferenceNumber entries to generate something more like this:

ReferenceNumber Title ReplicatorName ReplicatorName ReplicatorName
392424 This is the Title Location1 Location2 Location3

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-11-01 : 12:29:02
will you be certain of the number of ReplicatorNames always?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -