SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Case or Not??
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kev8279
Starting Member

United Kingdom
3 Posts

Posted - 04/24/2012 :  13:36:40  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 04/24/2012 :  14:14:26  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3859 Posts

Posted - 04/24/2012 :  14:31:20  Show Profile  Reply with Quote
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

United Kingdom
3 Posts

Posted - 04/26/2012 :  13:59:47  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000