When I try to create the store procedure with following code, I am getting errors.
create procedure Currentmonth(
@Completeddatekey varchar(20) )
as
begin
Getting the current date and formatting it
Declare @currentdate varchar(30)
set @currentdate = convert(Varchar(20), getdate()-1, 101)
print @currentdate
Getting DayofMonth and EndofMonth from DimDate
Declare @dayofmonth int
Declare @endofmonth varchar(20)
select @dayofmonth = DayofMonth, @endofmonth = EndofMonthDateKey from DimDate
where datekey = @currentdate
Getting HierMonthEndKey
declare @hiermonthendkey int
select @hiermonthendkey = MAX(HierMonthEndKey) from DimHospiceHiearchy
where HierMonthEndKey <= @currentdate+1
Declare @day
For Loop
Declare @i int = 0
declare @startdate varchar(20)
select @startdate = CAST(CAST(YEAR(convert(Varchar(20), getdate()-1, 101)) AS VARCHAR(4))
+ '/' + CAST(MONTH(convert(Varchar(20), getdate()-1, 101)) AS VARCHAR(2)) + '/01' AS DATETIME)+1
While @i <=@dayofmonth
(
set @startdate = @startdate+@i
Call MA010103(@completeddatekey,@hiermonthendkey)
set @i = @i+1
)
end
I am getting these errors when I try to create the above store procedure
Msg 156, Level 15, State 1, Procedure Currentmonth, Line 34
Incorrect syntax near the keyword 'set'.
Msg 102, Level 15, State 1, Procedure Currentmonth, Line 35
Incorrect syntax near 'Call'.
Msg 102, Level 15, State 1, Procedure Currentmonth, Line 37
Incorrect syntax near ')'.