| Author |
Topic |
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2009-03-04 : 03:14:21
|
i have table(TABLE1) that code can return more than one, like:# Code Sum status1 1 100 12 2 200 2 i want that will be flat, i mean when code :1=2 then# Code Sum status Code Sum status1 1 100 100 2 200 2 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-04 : 03:47:05
|
| declare @temp table ( Code int, Sum int, status int)insert into @tempselect 1 , 100 , 1 union allselect 2 , 200 , 2select max(case when code = 1 then code end) code, max(case when code = 1 then sum end) sum, max(case when code = 1 then status end) status, max(case when code = 2 then code end) code, max(case when code = 2 then sum end) sum, max(case when code = 2 then status end) status from @temp |
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-03-04 : 04:31:02
|
try thisdeclare @temp table ( Id Int, Code int, Sum int, status int)insert into @tempselect 1,1 , 100 , 1 union allselect 1,2 , 200 , 2SELECT A.Id,A.CODE, A.SUM, A.status, B.CODE, B.SUM, B.statusFROM @Temp A INNER JOIN @Temp BON A.Id = B.IdAND a.Code = 1AND B.Code = 2 Mangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2009-03-04 : 07:28:57
|
| the query of Mangal Pardeshi ,not work.cause i have 10,000 rows in status 1and 500 in status 2and i get 500,event if i add LEFT JOIN.but i want to get 10,000 rows. |
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-03-04 : 08:11:28
|
| declare @temp table ( Id Int, Code int, Sum int, status int)insert into @tempselect 1,1 , 100 , 1 union allselect 1,2 , 200 , 2 union allselect 2,2 , 200 , 2 union allselect 3,1 , 200 , 2 SELECT A.Id,A.CODE, A.SUM, A.status, B.CODE, B.SUM, B.statusFROM @Temp A FULL JOIN @Temp BON A.Id = B.IdAND a.Code = 1AND B.Code = 2WHERE A.CODE=1 OR B.CODE=2Mangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
|
|
|