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 |
|
NEVerton
Starting Member
9 Posts |
Posted - 2012-02-10 : 17:23:31
|
| I am new to SQL and want to understand why this does not work - it returns a zero value. There are loads of values in the call_events table... please tell me what i am doing wrong. Thanks.***Example 1***Declare @closing_wip INTselect @closing_wip = (select sum(event_cost) from call_events where link_to_call = call_ref)from callsselect @closing_wip |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-02-10 : 17:45:55
|
| Which tables do the columns in the where condition belong to? If there are link_to_call and call_ref columns in the call_events table, it will be trying to compare the values from those two columns in call_events table. If one or the other column is not in the call_events table, but is in the calls table, then it will be a correlated query - which could return multiple results. If so, @closing_wip will be assigned one among those results, and if that happens to be zero (because the event_cost happened to be zero for that call_ref), you will get a null.Can you describe what you are trying to do? Some sample data would help as well. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-02-13 : 11:05:14
|
| See what this returnsselect sum(event_cost) from call_events where link_to_call = call_refMadhivananFailing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|