dkilby
asked on
MS SQL + Query pulling data by week
I have a table with a date, customerid, and then dollar amount. the date represents the start of the week.
what i am trying to do is pull a list of all the customerids with a dollar value in a week, which is the easy part.
i am then trying to pull 7 previous weeks worth of data for each customerid that is in the initial query, so the final query would show all the customerids from the first week and then 7 previous weeks of data, the other part is if the customerid doesnt have a value in a week previous then a null value would be shown.
is this possible and if so how?
what i am trying to do is pull a list of all the customerids with a dollar value in a week, which is the easy part.
i am then trying to pull 7 previous weeks worth of data for each customerid that is in the initial query, so the final query would show all the customerids from the first week and then 7 previous weeks of data, the other part is if the customerid doesnt have a value in a week previous then a null value would be shown.
is this possible and if so how?
ASKER
here is the first part that pulls the initial data
Declare @reportDate datetime
select @reportDate = '01/13/2013'
select cid, dollarspent
from Customers
where dateweek = @reportDate
Declare @reportDate datetime
select @reportDate = '01/13/2013'
select cid, dollarspent
from Customers
where dateweek = @reportDate
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you - worked exactly how i needed
Absolutely. Post your SQL query as it stands now. This way we have the correct table names and columns.