SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Defining Variable Values in SQL server
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mgarret
Starting Member

14 Posts

Posted - 03/18/2013 :  11:20:29  Show Profile  Reply with Quote
HI all--

I am very new to SQL server and I just inherited the program below. I need to define the values for Report_Start_DT Report_End_DT. I'm not doing it correctly. when I try and run "Budget Query" below I get this error message:

Msg 137, Level 15, State 2, Line 2
Must declare the scalar variable "@Report_Start_DT".

Any assistance with this is greatly appreciated! Thanks.

*****This is the code I wrote.

DECLARE @Report_Start_DT DATETIME
DECLARE @Report_End_DT DATETIME
SET @Report_Start_DT = '2013-02-01 00:00:00.000'
SET @Report_End_DT = '2013-02-28 00:00:00.000'
SELECT @Report_Start_DT , @Report_End_DT
GO

****Budget Query
SELECT COUNT (DISTINCT CLT_NBR) AS Total_Clients
,SUM([dbo].[FN_B2H_AVG_HRS_PER_WK_BUDGET](@Report_Start_DT,@Report_End_DT,
d.START_DT,
d.END_DT,
d.UNITS_PER_MONTH,
d.BILLABLE_UNITS_OF_SERVICE)) AS TOTAL_WT_AVG_WK_HRS_BUDGET
,SUM([dbo].[FN_B2H_AVG_HRS_PER_WK_BUDGET](@Report_Start_DT,@Report_End_DT,
d.START_DT,
d.END_DT,
d.UNITS_PER_MONTH,
d.BILLABLE_UNITS_OF_SERVICE))/COUNT
(DISTINCT CLT_NBR) AS WT_AVG_WK_HRS_BUDGER_PER_CHILD
FROM [ECMS].[dbo].[B2H_DSP] d
WHERE START_DT<=@Report_End_DT AND END_DT>@Report_Start_DT

AND ASSIGNED_AGENCY=1 AND WAIVER_SERVICES NOT IN(1,10,11,12)
AND PROVIDER_NBR<>0

SQLJames
Starting Member

30 Posts

Posted - 03/18/2013 :  11:43:37  Show Profile  Reply with Quote
I would take out the GO statement below the variable declaration. Then run it and it should be fine.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 03/18/2013 :  12:37:39  Show Profile  Reply with Quote
yep GO is batch separator and will make variables out of scope.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000