功能:输入n年n月,得到n年n月的所有天数的记录.
Create Function F_GetDate(@Year varchar(4), @Month varchar(2))
Returns @Date Table(MonthDate Varchar(10))
As
Begin
Declare @BeginDate DateTime, @EndDate DateTime
Select @BeginDate = @Year + '-' + @Month + '-01', @EndDate = DateAdd(mm, 1, @Year + '-' + @Month + '-01')
Select @EndDate = Convert(Varchar(7), @EndDate, 120) + '-01'
While @BeginDate < @EndDate
Begin
Insert @Date Select Convert(Varchar(10), @BeginDate, 120)
Select @BeginDate = DateAdd(dd, 1, @BeginDate)
End
Return
End
GO
Select * From dbo.F_GetDate('2007', '02')