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.
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 2Must 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 DATETIMEDECLARE @Report_End_DT DATETIMESET @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_DTGO****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_CHILDFROM [ECMS].[dbo].[B2H_DSP] dWHERE 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. |
|
|
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 MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|