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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-05-03 : 08:03:13
|
| M writes "I am trying to replace some query code in sql server.the original code is qty_avail = SUM(CASE WHEN locationid NOT IN (''00R0T'', ''00R0W'', ''00R0K'') THEN qty ELSE 0 END), and I am trying to replace withqty_avail = SUM(CASE WHEN locationid NOT IN (SELECT LocationID FROM ForecastExcludeLocations (nolock)) THEN qty ELSE 0 END),I get the following msgServer: Msg 130, Level 15, State 1, Line 184Cannot perform an aggregate function on an expression containing an aggregate or a subquery.Server: Msg 156, Level 15, State 1, Line 185Incorrect syntax near the keyword 'THEN'.Server: Msg 156, Level 15, State 1, Line 186Incorrect syntax near the keyword 'THEN'.Server: Msg 156, Level 15, State 1, Line 187Incorrect syntax near the keyword 'THEN'.Server: Msg 170, Level 15, State 1, Line 201Line 201: Incorrect syntax near 'innerdata'.I can I replace this code to look into a table instead of hardcoding values?Thanks" |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-05-03 : 08:24:41
|
| post same sample data.. so that we can understand your issue..If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-03 : 10:53:11
|
| As the error displays, you cant use subquery when you use SUM function. Use Join and filter the recordsSelect sum(qty) from yourtable Twhere not exists(select * from ForecastExcludeLocations where LocationID =T.LocationID )MadhivananFailing to plan is Planning to fail |
 |
|
|
shijobaby
Starting Member
44 Posts |
Posted - 2009-08-21 : 06:22:14
|
| The ways to avoid this error is simple just look into my posthttp://sqlerrormessages.blogspot.com/2009/08/sql-server-error-message-msg-130-cannot.html |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|