SQL Server Database Error: Must declare the scalar variable

I'm getting an error when try to run this SQL code:

SQL Server Database Error: Must declare the scalar variable "@ParamDate"

I can't see where the error is. Anyone have suggestions? Thank you.

delcare @ParamDate  smalldatetime

set @ParamDate = '2013-10-15'

select count(s.SERIAL_NUMBER) as TOTAL_QTY,
sum(case when s.TRANS_TYPE = 'BUILD' then 1 else 0 end)  as BUILD_QTY, 
sum(case when s.TRANS_TYPE = 'REBUILD' then 1 else 0 end)  as REBUILD_QTY, 
sum(case when s.TRANS_TYPE = 'SCRAP' then 1 else 0 end)  as SCRAP_QTY, 
s.PC,
s.USER_ID,
from S_TRANS s 
where 
s.org = '100' 
and s.TRANS_TYPE in ('BUILD', 'REBUILD', 'SCRAP') 
and ms.TRANSACTION_DATE between dateadd(hour, 7, @ParamDate) and dateadd(hour, 29, @ParamDate)

group by m.PC, m.USER_ID

Open in new window

mossmisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee SavidgeCommented:
Try casting it:

delcare @ParamDate  smalldatetime

set @ParamDate = cast('2013-10-15' as smalldatetime)
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
The SQL looks correct.  

<wild guess>
Any chance you had a subset of this code highlighted when you executed it?
If yes, it will only execute what is highlighted, and if that didn't include the Declare statement it would return that error.
0
Lee SavidgeCommented:
If that fails, then make sure your date format is correct.

2013-10-15 might be treated as a US date format is the server is not configured for UK which will result in an out of range error.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

mossmisAuthor Commented:
Isavidge, Didn't work. It still says error line 1 position 19. Must Declare scalar variable.
0
Lee SavidgeCommented:
Try your spelling:

delcare @ParamDate  smalldatetime

should be

declare @ParamDate  smalldatetime
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
del-care.  lsavidge nailed it.
0
mossmisAuthor Commented:
DAMNIT! Why didn't I see that. Thanks for the second set of eyes.
0
Lee SavidgeCommented:
Take a break dude :)

It gets all of us occasionally.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Much better you get the solution by giving points to us than figure this out in front of your coworkers.
0
mossmisAuthor Commented:
Maybe I should, but then the problem it's too early for me to have these issues. I've only been at it for 2 hours. USA EST.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.