Author |
Topic |
joemama
Posting Yak Master
113 Posts |
Posted - 2007-08-16 : 20:08:03
|
i want to make this querySELECT ImpactedID, WMMIDFROM dbo.WMM_IMPACTED_GROUPSWHERE (WMMID = 47)which shows this result3 474 472 476 47show this result47 3 4 2 6can anyone help? |
|
hey001us
Posting Yak Master
185 Posts |
Posted - 2007-08-16 : 22:51:13
|
SELECT (SELECT ImpactedID FROM dbo.WMM_IMPACTED_GROUPS WHERE WMMID = g.WMMID) ImpactedID ,(SELECT WMMID FROM dbo.WMM_IMPACTED_GROUPS WHERE WMMID = g.WMMID) WMMIDFROM dbo.WMM_IMPACTED_GROUPS g WHERE (WMMID = 47)hey |
 |
|
hey001us
Posting Yak Master
185 Posts |
Posted - 2007-08-16 : 22:56:20
|
sorry its wrong the abovehey |
 |
|
ujb
Starting Member
8 Posts |
Posted - 2007-08-17 : 00:31:37
|
SELECT DISTINCT s1.WMMID, STUFF((SELECT ''+CAST(s2.ImpactedID AS VARCHAR(10))+' ' FROM WMM_IMPACTED_GROUPS AS s2 WHERE s2.WMMID = s1.WMMID ORDER BY ImpactedID FOR XML PATH('')), 1, 0, '') AS ImpactedIDFROM WMM_IMPACTED_GROUPS AS s1ORDER BY s1.WMMIDIn all fairness this isn't my code, its modified from something I learned today off another poster - you know who you are! |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-08-17 : 05:07:45
|
Great learning, but the XML PATH option is only available for SQL Server 2005, not SQL Server 2000.There are many concatenation functions here at SQLTeam that can be used for SQL Server 2000. Please feel free to search.Or check out the FAQ in the New to SQL Server forum. E 12°55'05.25"N 56°04'39.16" |
 |
|
sqlfresher2k7
Aged Yak Warrior
623 Posts |
Posted - 2007-08-17 : 10:21:13
|
Try below DECLARE @MT TABLE (TID int,CFLG int )INSERT @MTSELECT 3,47 UNION ALLSELECT 4,47 UNION ALLSELECT 2,47 UNION ALLSELECT 6,47 select CFLG, max( case when TID = '3' then TID else null end) 'colvalue3' ,max( case when TID = '4' then TID else null end) 'colvalue4' ,max( case when TID = '2' then TID else null end) 'colvalue2' ,max( case when TID = '6' then TID else null end) 'colvalue6'FROM @MT CDwhere CFLG =47 group by CFLG |
 |
|
ujb
Starting Member
8 Posts |
Posted - 2007-08-19 : 02:22:19
|
Doh, forgot which forum I was in, sorry about that Joe :-) |
 |
|
joemama
Posting Yak Master
113 Posts |
Posted - 2007-08-21 : 11:33:42
|
cool i will give it a trythanksquote: Originally posted by ujb SELECT DISTINCT s1.WMMID, STUFF((SELECT ''+CAST(s2.ImpactedID AS VARCHAR(10))+' ' FROM WMM_IMPACTED_GROUPS AS s2 WHERE s2.WMMID = s1.WMMID ORDER BY ImpactedID FOR XML PATH('')), 1, 0, '') AS ImpactedIDFROM WMM_IMPACTED_GROUPS AS s1ORDER BY s1.WMMIDIn all fairness this isn't my code, its modified from something I learned today off another poster - you know who you are!
|
 |
|
johnsql
Posting Yak Master
161 Posts |
Posted - 2007-10-11 : 11:56:49
|
quote: Originally posted by joemama i want to make this querySELECT ImpactedID, WMMIDFROM dbo.WMM_IMPACTED_GROUPSWHERE (WMMID = 47)which shows this result3 474 472 476 47show this result47 3 4 2 6can anyone help?
Another try:DECLARE @t TABLE ( id int,gp int )INSERT @tSELECT 3,47 UNION ALLSELECT 4,47 UNION ALLSELECT 2,47 UNION ALLSELECT 6,47 declare @bigString varchar(1000)select distinct @bigString=gp from @tselect @bigString = @bigString + ' ' + convert(varchar,id) from @t-- checkselect @bigString as [result] |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|