我正在尝试为以下要求编写存储过程。我无法解决这个问题。你可以帮帮我吗?
获取当前日期并格式化
Declare @currentdate varchar(30)
set @currentdate = convert(Varchar(20), getdate()-1, 101)
print @currentdate
从DimDate获取DayofMonth和EndofMonth
Declare @dayofmonth int
Declare @endofmonth varchar(20)
select @dayofmonth = DayofMonth, @endofmonth = EndofMonthDateKey from DimDate
where datekey = @currentdate
获取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 01_0_03_MA(@startdate,@hiermonthendkey)
set @i = @i+1
)