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
 General SQL Server Forums
 New to SQL Server Programming
 null in sql query

Author  Topic 

fazee
Starting Member

1 Post

Posted - 2007-12-20 : 04:18:17

hi
here is sql of query when any of sub query return zero result the result become null though other may have some results

litke

(select * from t1)-(select * from t)
in this case if either of table return zero rows the result will be null

plz help
thnx
faisal iqbal


sELECT bet.Party_id, (((select sum(amount*rate) from bet where team=1 and kl='l' and matchid = 18 and Party_id=1 )*1)-((select sum(amount*rate) from bet where team=1 and kl='k' and matchid = 18 and Party_id=1 )*1)) AS Expr1, (select sum(amount*rate) from bet where team=2 and matchid = 18 and bet.Party_id=1) AS Expr2, (select sum(amount*rate) from bet where team=3 and matchid = 18 and bet.Party_id=1) AS Expr3
FROM bet
GROUP BY bet.Party_id;

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-20 : 04:33:09
[code]SELECT b.Party_id
SUM(CASE WHEN b.team = 1 AND b.k1 = 'l' AND b.matchid = 18 AND b.Party_id = 1 THEN b.amount * b.rate ELSE 0 END) -
SUM(CASE WHEN b.team = 1 AND b.k1 = 'k' AND b.matchid = 18 AND b.Party_id = 1 THEN b.amount * b.rate ELSE 0 END) AS Expr1,
SUM(CASE WHEN b.team = 2 AND b.matchid = 18 AND b.Party_id = 1 THEN b.amount * b.rate ELSE 0 END) AS Expr2,
SUM(CASE WHEN b.team = 3 AND b.matchid = 18 AND b.Party_id = 1 THEN b.amount * b.rate ELSE 0 END) AS Expr3
FROM bet AS b
GROUP BY b.Party_id[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -