|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, January 16, 2013 6:01 PM
Points: 2,
Visits: 1
|
|
Hi to all,
Please bear with me. anyways, this is the tables i have
Table1
Name Company OtherVisaID
Mike ABC 1
Joey CBA 2
Table2
OtherVisaID TypeID Remarks
1 1 test1
1 2 test2
2 3 test3
2 2 test4
2 1 test5
Table3
TypeID Description
1 US
2 UK
3 SG
Result should be like this..
OtherVisaID Name Company List of Visa
1 Mike ABC US;UK
2 Joey CBA US;UK;SG
so as you can see it was separated by ";" hope you understand my question..
thanks in advance.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Wednesday, February 27, 2013 6:54 AM
Points: 40,
Visits: 168
|
|
Hi,
Try:
SELECT t1.OtherVisaID, t1.Name, t1.Company, STUFF( (SELECT ';' + t3.Description FROM Table2 as t2 JOIN Table3 as t3 ON t3.OtherVisaID = t2.OtherVisaID WHERE t2.OtherVisaID = t1.OtherVisaID FOR XML PATH(''), TYPE).value('.', 'varchar(max)') ,1, 1, '') as ListOfVisa, FROM Table1 as t1 Hope this help.
http://www.imoveisemexposicao.com.br
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 1:28 PM
Points: 6,698,
Visits: 11,726
|
|
If you can use SQLCLR you could use GROUP_CONCAT for SQL Server and write your SQL like this:
SELECT t1.OtherVisaID, t1.Name, t1.Company, dbo.GROUP_CONCAT_D(t3.DESCRIPTION, ';') AS ListOfVisa FROM Table1 AS t1 JOIN Table2 AS t2 ON t1.OtherVisaID = t2.OtherVisaID JOIN Table3 AS t3 ON t3.OtherVisaID = t2.OtherVisaID GROUP BY t1.OtherVisaID, t1.Name, t1.Company;
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|