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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Query Help

Author  Topic 

IK1972

56 Posts

Posted - 2014-08-29 : 18:14:17

I have table like this

CID OTID OID
30922 2426 396214
30928 2419 551550
30930 2419 551550
30931 2417 551550
30925 2401 483619
30929 2401 483619
30940 2401 483619

expected result is this. basicaly its group by OID and QTID

CID OTID OID
30922 2426 396214
30928,30930 2419 551550
30931 2417 551550
30925,30929,30940 2401 483619

Thanks

viggneshwar
Yak Posting Veteran

86 Posts

Posted - 2015-01-09 : 01:00:35
select OTID, OID, ( Select CID
from table t
where t.OTID = a.OTID
and t.OID = a.OID )
from table a
group by OTID, OID

Regards
Viggneshwar A
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2015-01-13 : 06:23:57
select distinct OTID, OID, stuff(( Select ','+cast( CID as varchar(50))
from tableName t
where t.OTID = a.OTID
and t.OID = a.OID For XML path('')),1,1,'') CID
from tableName a


--
Chandu
Go to Top of Page
   

- Advertisement -