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.
| Author |
Topic |
|
Sambasivam
Starting Member
36 Posts |
Posted - 2008-11-25 : 11:59:37
|
| I have 2 tables linked asTable A=======Field1 - (FK to Table B)Field2 - (Integer value)Table B=======Field1 - Id (PK)Field2 - Name(x,y,z)I have these data in Table A=============================Field1 Field21 101 52 7 3 6Table B Data============Field1 Field21 X2 Y3 ZNow I need a query which will have aggregate SUM of Table A.Field2 for all id in TableB and aggregate SUM of Table A.Field2 for all id in TableB except id 2 asSELECT SUM (Table A.Field2) for all id of Table B, SUM (Table A.Field2) for all id of Table B except id 2FROM Table A, TableBWHERE .......Is it possible to have it in single query? If so how can we do it? Please help me. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-25 : 12:04:58
|
| [code]SELECT SUM (a.Field2) AS Toatl,SUM (CASE WHEN b.Field1<> 2 THEN a.Field2 ELSE 0 END) AS Total2FROM TableA aJOIN TableB bON a.Field1=b.Field1[/code] |
 |
|
|
Sambasivam
Starting Member
36 Posts |
Posted - 2008-11-25 : 12:11:08
|
| Thank You. It worked perfectly as I wanted. Im very very delighted with your help. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-25 : 12:14:49
|
You're welcome |
 |
|
|
|
|
|