select day(cast('2002-3-1' as datetime)-1)

解决方案 »

  1.   

    coowoo(密码已过期):
      你好,你的方法很简单,但取得的结果不对啊?
      

  2.   

    写的长了点,但很实用create procedure get_lastdate11 @thisday  varchar(20)
    as 
     declare @ii int
     declare @ddd  varchar(20)
     declare @nextmonth  varchar(2) 
     declare @mm  int 
     declare @meyear  varchar(4) 
      if @thisday = '' 
        set @thisday = convert(char(10),getdate(),120)
      else
          set @thisday = convert(char(10),rtrim(@thisday),120)    set @mm = convert(varchar(2),month(@thisday))
        if @mm = 12
           begin
              set @nextmonth = '01'
              set @meyear = convert(varchar(4),year(@thisday) + 1)
           end
           else
           begin
              if len(@mm + 1) < 2 
                  set @nextmonth = '0' + convert(char(1),@mm + 1)
              else
                  set @nextmonth = convert(char(2),@mm + 1)
              set @meyear = convert(varchar(4),year(@thisday))
           end
            set  @ii = 0
            set  @ddd = @thisday
            while  (@ddd <> rtrim(@meyear) + '-' +rtrim(@nextmonth) + '-01')
               begin
                  set @ddd = convert(char(10),DATEADD(day, 1, @ddd),120)
                  set @ii =  @ii +1 
               end
         select lastdate = convert(char(10),DATEADD(day,@ii - 1, @thisday),120)
      

  3.   

    wzsswz:
       爽啊!非常ok,谢谢!谢谢!
      

  4.   

    select case month(getdate()) when 2 then (
         day(cast( (cast(year(getdate()) as char(4))+'-3-1') as datetime)-1)
    )
    else substring( '312831303130313130313031',2*month(getdate())-1,2)
    end