Click here to Skip to main content
15,915,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all.In my database i've three tables Empl,Items,Orders as follows



EmpId EmpName

1 Ravi

2 Kumar

3 Sam

4 Telpo



Itemid ItemDesc

1 keyBoard

2 Mouse

3 Harddrive

4 CableBus



OrderId EmpId Itemid

1 1 2

2 1 4

3 2 1

4 2 3



Now i need to display the last table in a GridView as follows

Empname ItemDesc

Kumar CableBus,Harddrive

Ravi keyboard,Mouse

Can anyone please helpme out for this scenario.

Thanks in Advance.
Posted

1 solution

Try this

SQL
DECLARE @ItemDesc VARCHAR(MAX)

select A.EmpName,(SELECT @ItemDesc = COALESCE(@ItemDesc +',' ,'') +  ItemDesc
			FROM  Items
			where Items.Itemid = B.Itemid) as ItemDesc

from Emp A inner join Orders B
On A.EmpId = B.EmpId
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900