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 2008 Forums
 Transact-SQL (2008)
 Case or Not??

Author  Topic 

kev8279
Starting Member

6 Posts

Posted - 2012-04-24 : 13:36:40
Could someone help me. I have a staff table and 3 data tables in a join. Some or all of the tables may have data in for one date for a specific staff member. What I am trying to do is use the staff table, join on the sales table, calls table and payments table and group all by date. How can I get a date to come back in my query looking for the date across all tables? I did look at case, however couldn't find any way to do this with more than two arguments.

Help please?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-24 : 14:14:26
Not very clear to me what you are trying to do.

If you have dates in several tables that you have joined, and want to return the date from the first table if that has one, and return the date from the second table if there is none in the first, and return the date from the third table if both 1 and 2 don't have the date, then it may be this:
COALESCE(t1.DateCol, t2.DateCol, t3.DateCol)

Post the query that you have now with some sample data and information about the tables, and surely someone on the forum would be able to help.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-04-24 : 14:31:20
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

kev8279
Starting Member

6 Posts

Posted - 2012-04-26 : 13:59:47
quote:
Originally posted by sunitabeck

Not very clear to me what you are trying to do.

If you have dates in several tables that you have joined, and want to return the date from the first table if that has one, and return the date from the second table if there is none in the first, and return the date from the third table if both 1 and 2 don't have the date, then it may be this:
COALESCE(t1.DateCol, t2.DateCol, t3.DateCol)

Post the query that you have now with some sample data and information about the tables, and surely someone on the forum would be able to help.




Thank you, that worked great. Sorry for my vague explaination!
Go to Top of Page
   

- Advertisement -