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 |
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2011-03-10 : 11:09:29
|
| Is it the right way to use the Not In operator: all i want to make sure is inv_id is not present in tab_paytasks table.SET @Accru_Amt = (select sum(isnull(inv_amt,0)) from Tab_InvTask where element_id=@element_id and inv_id not in (select inv_id from Tab_PayTasks where element_id=@element_id)Thank you very much for the helpful info. |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-03-10 : 11:20:41
|
| select sum(isnull(inv_amt,0)) from Tab_InvTask itwhere element_id=@element_id and not exists(select * from Tab_PayTasks pt where it.inv_id = pt.inv_id )JimEveryday I learn something that somebody else already knew |
 |
|
|
djj55
Constraint Violating Yak Guru
352 Posts |
Posted - 2011-03-10 : 15:53:40
|
| Hello,The ISNULL is not needed for a sum as it ignores null values.Try:SELECT @Accru_Amt = SUM(inv_amt)from Tab_InvTask LEFT JOIN Tab_PayTasks ON Tab_InvTask.inv_id = Tab_PayTasks.inv_id where element_id=@element_id and Tab_PayTasks.inv_id IS NULL |
 |
|
|
|
|
|