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 |
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2010-04-16 : 05:29:37
|
| HiI need your help plzcreate table A(id int,name varchar(5),fl varchar(1))create table B(id int,Su int)insert into Avalues (1,'S','N')insert into Avalues (2,'M','Y')insert into Bvalues (1,5)insert into Bvalues (2,6)insert into Bvalues (2,5)insert into Bvalues (2,9)select A.ID,(CASE WHEN A.[fl] = 'Y' THEN SUM(B.[Su]) ELSE B.[Su] END) AS [REV]from A inner join B ON A.id = B.idgroup by A.id, A.fl, B.Suwhat i am getting as belowID REV1 52 52 62 9but need likeID REV1 52 20 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-04-16 : 05:34:42
|
| [code]select A.ID,SUM(CASE WHEN A.[fl] = 'Y' THEN (B.[Su]) ELSE B.[Su] END) AS [REV]from A inner join B ON A.id = B.idgroup by A.id, A.fl[/code]PBUH |
 |
|
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2010-04-16 : 05:51:24
|
| Thanks A LOt... ) |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-04-16 : 06:23:09
|
quote: Originally posted by under2811 Thanks A LOt... )
You are welcome.PBUH |
 |
|
|
|
|
|
|
|