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
 Merging multiple rows from joins

Author  Topic 

jonnie_r
Starting Member

2 Posts

Posted - 2014-12-15 : 07:13:55
Hi,

I am still fairly new to SQL, having been tasked with creating a csv file from data now someone else has left.

I can do the csv export using sqlcmd and I have the query sorted and am pulling out the right data, but it generates two rows, as one of the tables has multiple records per cardholder. See the query below, I know there is a way of doing it with XML PATH, I think, but it has got me slightly confused.

set nocount on

select dbo.card.EncodedNumber,
dbo.card.IsEnabled,
dbo.Cardholder.FirstName,
dbo.cardholder.LastName,
dbo.card.ExpiryTime,
dbo.PersonalDataString.Value

from dbo.card

inner join dbo.cardholder

on dbo.card.CardholderID = dbo.cardholder.FTItemID

inner join dbo.PersonalDataString

on dbo.card.CardholderID = dbo.PersonalDataString.CardholderID

where dbo.PersonalDataString.PersonalDataFieldID between 1904 and 1905

order by dbo.card.EncodedNumber

Can anyone point me in the right direction?

Thanks,


Jon

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2014-12-15 : 12:35:45
Use "distinct" or "group by"
Go to Top of Page

jonnie_r
Starting Member

2 Posts

Posted - 2014-12-15 : 14:39:51
Ok ta, I'll have a read up on them
Go to Top of Page
   

- Advertisement -