Guest_imported
New member
- Jan 1, 1970
- 0
Can anyone help me understand why the following code
gets a complaint about @CarDollars not being Declared?
I can cut the results of the print statement into
Query Analyzer and it runs fine with the same
declarations you see below.
SQL 2000 on Win 2000
-----When I run this code------
Declare @DK varchar(12)
Declare @BegDate varchar(12)
Declare @EndDate varchar(12)
Select @DK = '3'
Select @BegDate = '3/1/02'
Select @EndDate = '4/1/02'
Declare @CarDollars varchar(20) --<<<<<<
Declare @Stmt varchar(2000)
Select @Stmt = 'SELECT
@CarDollars = Sum(Case RecType When ''Car'' Then TotalSale Else 0 End)
From PartnerDKTables.dbo.[' + @DK + ']
Where CreationDate >= ''' + @BegDate + ''' And CreationDate < ''' + @EndDate + ''''
Print @Stmt
Exec (@Stmt)
-----I get the following results------
SELECT
@CarDollars = Sum(Case RecType When 'Car' Then TotalSale Else 0 End)
From PartnerDKTables.dbo.[3]
Where CreationDate >= '3/1/02' And CreationDate < '4/1/02'
Server: Msg 137, Level 15, State 1, Line 3
Must declare the variable '@CarDollars'.<-------This variable has been declared
Any help is appreciated.
Thanks
Jeff
gets a complaint about @CarDollars not being Declared?
I can cut the results of the print statement into
Query Analyzer and it runs fine with the same
declarations you see below.
SQL 2000 on Win 2000
-----When I run this code------
Declare @DK varchar(12)
Declare @BegDate varchar(12)
Declare @EndDate varchar(12)
Select @DK = '3'
Select @BegDate = '3/1/02'
Select @EndDate = '4/1/02'
Declare @CarDollars varchar(20) --<<<<<<
Declare @Stmt varchar(2000)
Select @Stmt = 'SELECT
@CarDollars = Sum(Case RecType When ''Car'' Then TotalSale Else 0 End)
From PartnerDKTables.dbo.[' + @DK + ']
Where CreationDate >= ''' + @BegDate + ''' And CreationDate < ''' + @EndDate + ''''
Print @Stmt
Exec (@Stmt)
-----I get the following results------
SELECT
@CarDollars = Sum(Case RecType When 'Car' Then TotalSale Else 0 End)
From PartnerDKTables.dbo.[3]
Where CreationDate >= '3/1/02' And CreationDate < '4/1/02'
Server: Msg 137, Level 15, State 1, Line 3
Must declare the variable '@CarDollars'.<-------This variable has been declared
Any help is appreciated.
Thanks
Jeff