Jump to content

Recommended Posts

Posted

i need to get my dates dynamic , in the sense every time i run the code it should fetch past 7months data , say if i run the code in june it should get data from 2013/11/01 and 2014/05/31 , as of now im hardcoding these values in my where clause , any idea on how , next month if i run it should get data from 2013/12/01 till 2014/06/30

thanks in advance

 

Posted

any date colm in tht tbl??

if yes apply where datecolum between getdt and getdate-7months...
convert dates to varchar

Posted

i need to get my dates dynamic , in the sense every time i run the code it should fetch past 7months data , say if i run the code in june it should get data from 2013/11/01 and 2014/05/31 , as of now im hardcoding these values in my where clause , any idea on how , next month if i run it should get data from 2013/12/01 till 2014/06/30

thanks in advance

why hard coding 

 

u can  getdate() and getdate() - 7 months

Posted

any date colm in tht tbl??

if yes apply where datecolum between getdt and getdate-7months...
convert dates to varchar

repost

Posted

Declare Variables and call them

 

DECLARE @Month INT

DECLARE @year INT
DECLARE @dtnow DATETIME

SET @dtnow = GETDATE()

SELECT @Month = MONTH(DATEADD(MONTH,-6, @dtnow ))

 

and use those in where clause

Posted

any date colm in tht tbl??

if yes apply where datecolum between getdt and getdate-7months...
convert dates to varchar

will that give me from begining of the month ? like 2013/11/01  

Posted

will that give me from begining of the month ? like 2013/11/01

use

where datecolm between dateadd(month,0,getdate())-7,0) and dateadd(month,datediff(month,-1,getdate())-1,-1)

convrt dates to varchar..
×
×
  • Create New...