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.
| Author |
Topic |
|
jesus4u
Posting Yak Master
204 Posts |
Posted - 2002-10-16 : 13:11:36
|
Given the pic below how can I, in ONE select statement, grab this data by year to date, month to date etc..?thanksI want it to look like this: In the Query Analyzer I get this: |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-10-16 : 13:36:13
|
| Without DDL its going to be next to impossible to give you exact sql ...What's with the reasoning behind the full outer joins?Ever hear of aliasing tables?Jay White{0} |
 |
|
|
jesus4u
Posting Yak Master
204 Posts |
Posted - 2002-10-16 : 13:37:24
|
What is DDL?quote: Without DDL its going to be next to impossible to give you exact sql ...What's with the reasoning behind the full outer joins?Ever hear of aliasing tables?Jay White{0}
|
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-10-16 : 13:42:15
|
| The CREATE TABLE statement that you use to define the table structures. (Data Definition Language=DDL) You can right-click the table in Enterprise Manager and choose Generate SQL Script for it, then paste the code in your reply.I think you can use a CASE expression with some date arithmetic to combine YTD, MTD and Last Month into one SELECT statement, but the percentage column will require a subquery. |
 |
|
|
M.E.
Aged Yak Warrior
539 Posts |
Posted - 2002-10-16 : 13:43:44
|
| Thats some messed up sql there man.... Looks kinda old actually. DDL is the create table statement. This way we can see how your tables are create IE//create table thetracking(company_name varchar(50),ytd int,mtd int)more then likely your statement will look likeselect t.company,t.ytd,t.mtd from thetracking t inner join theuserdetails on key = keyif ytd is a sum of the previous... you can always use the sum statement to add them together and group by company name. will have to see the DDL to help you furtherThe percent might be challenging comparitively.the where statement is there just bulky... Kinda curious... Any reason why you named your tables using like TheTable? I've never seen The used like that in table names before.-----------------------SQL isn't just a hobby, It's an addictionEdited by - m.e. on 10/16/2002 13:46:45 |
 |
|
|
jesus4u
Posting Yak Master
204 Posts |
Posted - 2002-10-16 : 13:44:46
|
quote: Kinda curious... Any reason why you named your tables using like TheTable? I've never seen The used like that in table names before.-----------------------SQL isn't just a hobby, It's an addiction
Just to be different |
 |
|
|
M.E.
Aged Yak Warrior
539 Posts |
Posted - 2002-10-16 : 13:48:41
|
quote: Just to be different
We got some messed up naming conventions here. Most of my table are Tigr_table name. or Tigr_procname_Proc_Insert. Somewhat silly for the proc name... but it seems to workI thought TheTable might have something interesting behind it -----------------------SQL isn't just a hobby, It's an addictionEdited by - m.e. on 10/16/2002 13:49:32 |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-10-16 : 13:49:32
|
Just to be different...quote: Yeah, I know I was supposed to change the world and allBut it looks like the world got to me firstIf you can't beat em, join 'em..Then hurt the team by beating yourself-Sage Francis
Jay White{0} |
 |
|
|
|
|
|
|
|