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
 automatically selecting dates

Author  Topic 

msugradus
Starting Member

40 Posts

Posted - 2007-06-18 : 09:56:02
I need to run a query that will automatically pull the sales for the last 30 and 90 days with out the user having to add any dates. Ideas?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-18 : 10:00:31
[code]
select *
from sales_table
where datecol >= dateadd(day, -30, getdate()) -- last 30 days
[/code]


KH

Go to Top of Page

msugradus
Starting Member

40 Posts

Posted - 2007-06-18 : 10:12:10
ALTER PROCEDURE dbo.sp_Active_Reps

AS select sum (case when OrderDate >= dateadd(day, -30, getdate()) then 1 else 0) as Month Count

FROM exigo_data_sync.Orders

Get and ADO error, incorrect snytax line 3 near ')'







ALTER PROCEDURE dbo.sp_Active_Reps

AS select sum (case when OrderDate >= dateadd(day, -30, getdate()) then 1 else 0) as Month Count

FROM exigo_data_sync.Orders







Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-18 : 10:15:34
you missed out the end after the else before the )

what are you trying to achieve here ?


KH

Go to Top of Page

msugradus
Starting Member

40 Posts

Posted - 2007-06-18 : 10:22:43
Thanks for the help. I am trying to create a query to build a report that will get the number of people that bought in the last 30 days and 90 days.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-20 : 06:05:52
This would also work

select count(*)
from sales_table
where datecol >= dateadd(day, -30, getdate()) -- last 30 days


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -