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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 A month earlier data

Author  Topic 

1sabine8
Posting Yak Master

130 Posts

Posted - 2009-06-01 : 04:42:06
Hi,
I have a query where i get data entered between 2 dates entered as parameters. i need also to get the data that entered a month before the range entered. How can i achieve that?
Thanks in advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-01 : 04:44:15
dateadd(month, -1, @start_date)


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

1sabine8
Posting Yak Master

130 Posts

Posted - 2009-06-01 : 05:10:20
Hi,
Thanks for you quick reply.
So if i want data for 3 months earlier, i'll just have to put -3 ?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-01 : 05:15:59
yes


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

1sabine8
Posting Yak Master

130 Posts

Posted - 2009-06-01 : 09:16:05
Hi,
Can i pass the -1, -3 or -6 as parameters to the query?
I guess yes right?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-01 : 09:25:06
quote:
Originally posted by 1sabine8

Hi,
Can i pass the -1, -3 or -6 as parameters to the query?
I guess yes right?



Did you try ? Nobody is stopping you.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SQLRatankalwa
Starting Member

42 Posts

Posted - 2009-06-01 : 11:18:23
You can do

dateadd(month, -3, @start_date)

if you know the exact number days you can just do

@start_date - 180

or you can pass a parameter to your stored procedure as an Integer value and use it as well.

@start_date - @number_of_days

I hope this should help

Revalsys Technologies Private Limited
http://www.revalsys.com
Go to Top of Page
   

- Advertisement -