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 2000 Forums
 SQL Server Development (2000)
 Multi SELECT - YTD, MTD?

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..?
thanks
I 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}
Go to Top of Page

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}



Go to Top of Page

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.

Go to Top of Page

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 like
select t.company,t.ytd,t.mtd from thetracking t inner join theuserdetails on key = key

if 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 further

The 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 addiction

Edited by - m.e. on 10/16/2002 13:46:45
Go to Top of Page

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

Go to Top of Page

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 work

I thought TheTable might have something interesting behind it

-----------------------
SQL isn't just a hobby, It's an addiction

Edited by - m.e. on 10/16/2002 13:49:32
Go to Top of Page

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 all
But it looks like the world got to me first
If you can't beat em, join 'em..
Then hurt the team by beating yourself
-Sage Francis


Jay White
{0}
Go to Top of Page
   

- Advertisement -