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

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -