sql: 生日三个月内有效

WBOY
發布: 2016-06-07 17:37:26
原創
1085 人瀏覽過

DECLARE @birthday datetime,@stat datetime,@end datetime,@statbirthday datetime,@endbirthday datetime,@thirdbirthday datetime,@firthbirthday datetime, @year int,@month int , @day int,@str varchar(20),@total int,@firthmonth int,@thirmonth in

DECLARE @birthday datetime,@stat datetime,@end datetime,@statbirthday datetime,@endbirthday datetime,@thirdbirthday datetime,@firthbirthday datetime, @year int,@month int , @day int,@str varchar(20),@total int,@firthmonth int,@thirmonth int,@now datetime,@vipno nvarchar(10) --参数 set @vipno='8888888' set @now='2014-01-25' set @year=Year(@now) select @birthday=birthday from vip1 where vipno=@vipno set @month=month(@birthday) set @day=day(@birthday) set @str=cast(@year as varchar(4))+'-'+cast(@month as varchar(2))+'-'+cast(@day as varchar(2)) set @birthday=cast(@str as datetime) --會員生日有效生首日起至3個月內有效 set @firthbirthday=DATEADD(mm, DATEDIFF(mm,0,@birthday)-2, 0)--DATEADD(mm, DATEDIFF(mm,0,@birthday), 0) --当月的第一天 --set @thirdbirthday=DATEADD(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+3, 0)) --后三个月最后的一天 SELECT @firthbirthday=DATEADD(MONTH,-2,DATEADD(MONTH,DATEDIFF(MONTH,0,@birthday),0)) --select cast(@firthbirthday as datetime) --set @firthbirthday=DATEADD(MONTH,-2,DATEADD(MONTH,DATEDIFF(MONTH,0,@birthday),0))--DATEADD(Month,0,CONVERT(datetime,CONVERT(char(8),getdate(),120)+'1')) --select @firthbirthday --DATEADD(mm,0, DATEDIFF(mm,0,@birthday), 0) --前三个月的第一天 --set @firthbirthday=convert(datetime, @thirdbirthday) --SELECT 三個月有效 塗聚文 涂聚文 set @firthmonth=month(@now)-2 set @thirmonth=month(@now) set @thirdbirthday=DATEADD(ms,-3,DATEADD(mm, DATEDIFF(mm,0,@now)+1, 0)) --当月最后的一天 set @thirdbirthday=cast(@thirdbirthday as datetime) set @statbirthday=DATEADD(mm, DATEDIFF(mm,0,@birthday)-13, 0) set @endbirthday=DATEADD(ms,-3,DATEADD(mm, DATEDIFF(mm,0,@birthday)-1, 0)) --select @statbirthday,@endbirthday,@firthbirthday,@thirdbirthday,@birthday,@firthmonth,@thirmonth --以月份來吧 SELECT * FROM View_birthdayVipdlyList WHERE DATEDIFF(month,NowBirthday,@now)>=0 and DATEDIFF(month,NowBirthday,@now)@statbirthday AND indate=@firthmonth and month(birthday)@statbirthday AND indate=@firthmonth and month(birthday)=0 and DATEDIFF(month,NowBirthday,getdate())

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!