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
 First 7 days of Campaign

Author  Topic 

fengfeng
Yak Posting Veteran

64 Posts

Posted - 2011-03-24 : 21:35:15
I want to query a table that contains campaign names and there is a start date field and the other fields are data.

How can I choose campaign information for all campaigns but I just want the first 7 days of any given campaign and they all have different start dates?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-24 : 22:18:23
What do you mean by "first 7 days" ? with relative to what date ?

or campaigns that started in the last 7 days from today ?



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

Go to Top of Page

fengfeng
Yak Posting Veteran

64 Posts

Posted - 2011-03-25 : 09:05:03
quote:
Originally posted by khtan

What do you mean by "first 7 days" ? with relative to what date ?

or campaigns that started in the last 7 days from today ?



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





I mean the campaign table has a field called start date, can I say something like sum(sales) of the first 7 days of all campaigns beginning on their start date, group by campaigns, sales.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-03-25 : 09:23:28
Do you have another date field to compare to the start date?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-25 : 12:13:00
just a guess, it seems that your requirements can be fulfilled by Order by Clause ... in case if you are looking for summation of all first seven days compaigns then you may also need to introduce a column composed of Row_Number function to determine first seven days for all campaigns and then use that data set for required purpose.

Cheers
MIK
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-25 : 22:25:11
i think it will be much easier for us to understand your requirement if you can
1. post the DDL of your table
2. post some sample data
3. show us the expected result

please refer to this http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


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

Go to Top of Page

fengfeng
Yak Posting Veteran

64 Posts

Posted - 2011-03-28 : 11:38:29
The output would look like:

Month 1st 7 days
Line_code Views Clicks Views Clicks


The code I have for the entire month would be:

SELECT line_code, Views, Sales

FROM broadway

WHERE date BETWEEN '2011-02-01 00:00:00' AND '2011-02-28 00:00:00'

The part I'm having trouble with is , for those corresponding line_code, I want to see just the first 7 days of the line code only if it has views of over 100.

I could just do date between 2011-02-01 and 2011-02-07 but then some line code dont start having data on 02-01. Is there a way to specify to count the first 7 days of the month when the data actually starts?



Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-28 : 20:45:56
You are not making it easier for us to help you. Please refer to my last post on 03/25/2011 : 22:25:11.

Looking at your other thread, it seems that you are not using Microsoft SQL Server ?


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

Go to Top of Page
   

- Advertisement -