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
 Defining Variable Values in SQL server

Author  Topic 

mgarret
Starting Member

14 Posts

Posted - 2013-03-18 : 11:20:29
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

35 Posts

Posted - 2013-03-18 : 11:43:37
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

52326 Posts

Posted - 2013-03-18 : 12:37:39
yep GO is batch separator and will make variables out of scope.

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

Go to Top of Page
   

- Advertisement -