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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Must declare the scalar variable

Author  Topic 

cheesecake
Starting Member

11 Posts

Posted - 2010-09-10 : 15:39:46
IF OBJECT_ID(N'dbo.Price_Distribution') IS NOT NULL
DROP Table Price_Distribution
GO

DECLARE @activedate smalldatetime;
SET @activedate = '2010-07-16 12:00:00 AM'

select saledate from nc_price_distribution
INSERT Price_Distribution (VehicleId, StandardDeviation, IntervalHigh, IntervalLow, Imputed)
SELECT KBBVehicleId
, STD_EST
, Price_UCLM
, Price_LCLM
, CASE imputed
WHEN 'NO' Then 0
ELSE 1
END
FROM NC_Price_Distribution
WHERE Price_UCLM is not null and Price_LCLM is not null
AND Percentage = 1 AND SALEDATE >= DateAdd(dd,-6, @activedate) AND SALEDATE <= @activedate


Must declare the scalar variable "@activedate".

If I execute the above, I am getting the error "Must declare the scalar variable "@activedate".. How can I correct this? Please advise. Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-09-10 : 15:49:20
Are you sure you don't have an extra GO in there? And are you sure you are running it in one batch?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -