Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 HOW TO GET DATES BASING ON COUNT

Author  Topic 

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2013-04-15 : 02:53:41
HELLO ALL,
IN MY DYNAMIC QUERY I NEED TO GET 10 days or 20 days etc basing on the get date(Present date)..If i pass the count 10 i need to get coming 10 days and if i pass 20 days i need to get coming 20 days


BEGIN
SET @vc_WhereSQL = @vc_WhereSQL +' ' + 'AND CCL.OnlineMembershipExpiryDate = ' + CAST(@i_NoofDays AS VARCHAR)
END



declare @thirtydaysago datetime
declare @now datetime
set @now = getdate()
set @thirtydaysago = dateadd(day,-30,@now)

select @now, @thirtydaysago


how can insert this logic in my dynamic query

P.V.P.MOhan

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-15 : 04:42:37
WHERE DATEDIFF(DD, MESSAGE_DT, GETDATE()) > = @i_NoofDays

--
Chandu
Go to Top of Page

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2013-04-15 : 05:10:21
thanks chandu

P.V.P.MOhan
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-15 : 05:12:00
quote:
Originally posted by mohan123

thanks chandu
P.V.P.MOhan

Welcome

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-15 : 06:26:43
WHERE DATEDIFF(DD, MESSAGE_DT, GETDATE()) > = @i_NoofDays

can be better written as

WHERE MESSAGE_DT <= DATEADD(dd,-@i_NoofDays,GETDATE())

to take advantage of an available index on MESSAGE_DT

see

http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -