sql server - Using standard CAST rather than CONVERT -
these work when retrieving first of month, 6 months ago:
declare @now datetime = sysdatetime(); --1 select convert(int,convert(char(8),dateadd(mm,datediff(mm,0,@now)-5,0),112)); --2 select convert(int,convert(char(6),dateadd(mm,-5,@now),112) + '01'); how achieve same result using standard function cast ?
well, way, doesn't use cast():
select (year(dateadd(mm,datediff(mm,0,@now)-5, 0))*10000 + month(dateadd(mm,datediff(mm,0,@now)-5, 0))*100 +1)
Comments
Post a Comment