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 |
|
calladrum
Starting Member
6 Posts |
Posted - 2011-09-06 : 08:20:11
|
| Hi AllI'm using a SQL query set up by someone else which has been working well for a while but now is throwing up the following error:Msg 137, Level 15, State 2, Line 17Must declare the variable '@Deduction'.The query code is:DECLARE @YearWeekFrom AS INTEGERDECLARE @YearWeekTo AS INTEGER ------------------------------------------------------------SET @YearWeekFrom = 201105 -- Change this value!SET @YearWeekTo = 201105 -- Change this value!------------------------------------------------------------ SELECT Year, Week, CCode, SUM(ISNULL(NUM_Promos,0)) AS NumPromos, SUM(ISNULL(Total_Value,0)) AS TotalValue, SUM(ISNULL(Commission_Tot,0)) AS TotalCommissionFROM PromosWHERE Deduction_Code_Inverse_Key = @Deduction AND ((Year * 100) + Week) >= @YearWeekFrom AND ((Year * 100) + Week) <= @YearWeekToGROUP BY Year, Week, CCodeORDER BY Year, Week, CCodeAny ideas about why this isn't working?Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-06 : 08:33:13
|
quote: Originally posted by calladrum Hi AllI'm using a SQL query set up by someone else which has been working well for a while but now is throwing up the following error:Msg 137, Level 15, State 2, Line 17Must declare the variable '@Deduction'.The query code is:DECLARE @Deduction AS INTEGERDECLARE @YearWeekFrom AS INTEGERDECLARE @YearWeekTo AS INTEGER ------------------------------------------------------------SET @YearWeekFrom = 201105 -- Change this value!SET @YearWeekTo = 201105 -- Change this value!------------------------------------------------------------ SELECT Year, Week, CCode, SUM(ISNULL(NUM_Promos,0)) AS NumPromos, SUM(ISNULL(Total_Value,0)) AS TotalValue, SUM(ISNULL(Commission_Tot,0)) AS TotalCommissionFROM PromosWHERE Deduction_Code_Inverse_Key = @Deduction AND ((Year * 100) + Week) >= @YearWeekFrom AND ((Year * 100) + Week) <= @YearWeekToGROUP BY Year, Week, CCodeORDER BY Year, Week, CCodeAny ideas about why this isn't working?Thanks
missed declaring iti hope its type is integer else change accordingly------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
calladrum
Starting Member
6 Posts |
Posted - 2011-09-06 : 08:52:06
|
| Thanks, I'll give this a try! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-06 : 11:07:10
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
calladrum
Starting Member
6 Posts |
Posted - 2011-09-07 : 11:39:07
|
| Hello againI added in DECLARE @Deduction AS VARCHAR (32)and now the query appears to run but no results come in (and I know there should be) and there are no error messages. Have checked that all fields do appear in the PROMOS SQL Table. Any suggestions? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-09 : 02:43:32
|
quote: Originally posted by calladrum Hello againI added in DECLARE @Deduction AS VARCHAR (32)and now the query appears to run but no results come in (and I know there should be) and there are no error messages. Have checked that all fields do appear in the PROMOS SQL Table. Any suggestions?
ok. what was the value you passed for @Deduction? without passing a value it assumes NULL value and you wont get any result------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|