if exists(Select name From sysobjects where name =N'GetDays'and type=N'p')
drop procedure GetDays
Go
create procedure GetDays(@StrYear char(4),@StrMonth char(2),@IntDay Smallint output)
as
declare @TempDate Smalldatetime
select @TempDate=@StrYear+@StrMonth+'01'
Select @IntDay=datediff(d,@tempDate,dateadd(m,1,@tempDate))
if @@error>0 return
go
--Test GetDays
declare @IntDay1 smallint
exec GetDays '2008','07',@IntDay1 output
Select @IntDay1
drop procedure GetDays
Go
create procedure GetDays(@StrYear char(4),@StrMonth char(2),@IntDay Smallint output)
as
declare @TempDate Smalldatetime
select @TempDate=@StrYear+@StrMonth+'01'
Select @IntDay=datediff(d,@tempDate,dateadd(m,1,@tempDate))
if @@error>0 return
go
--Test GetDays
declare @IntDay1 smallint
exec GetDays '2008','07',@IntDay1 output
Select @IntDay1
declare @year int, --你要取天数的年份
@month int --你要取天数的月份
if @year is null
set @year=year(getdate())
if @month is null
set @month=month(getdate())
select day(dateadd(day,-1,(convert(datetime,convert(varchar,@year)+'-'+convert(varchar,@month)+'-01'))))
+'-'+cast( month(dateadd(month,1,getdate())) as varchar(2))
+'-01') as datetime)-1)因为12月份可能不过因为每年12月份都有31 所以也没有关系,不过俺就一个查询啊,不要什么过程啊,declare了所以还是给俺加分哦