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
 Joining SELECT statements

Author  Topic 

tclose
Starting Member

24 Posts

Posted - 2010-04-22 : 07:26:31
I have the following 2 SELECT statements that I would like to join if possible. I'm using SQL SERVER 2008 and I would like the results to be returned in one row with the headers of 'Exempt' and 'Non-Exempt'. Any advice is appreciated.

SELECT MAX(e.Salary) AS [Exempt] FROM Employee e
INNER JOIN Job_Title m ON e.JobTitleID = m.JobTitleID AND ExemptStatus = 1
SELECT MAX(e.Salary) AS [Non Exempt] FROM Employee e
INNER JOIN Job_Title m ON e.JobTitleID = m.JobTitleID AND ExemptStatus = 0

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-22 : 07:37:50
[code]
SELECT max(case when ExemptStatus = 1 then e.Salary end),
max(case when ExemptStatus = 0 then e.Salary end)
FROM Employee e
INNER JOIN Job_Title m ON e.JobTitleID = m.JobTitleID
[/code]


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

Go to Top of Page

tclose
Starting Member

24 Posts

Posted - 2010-04-22 : 07:45:56
BRAVO! I didn't even know you could put statements into the MAX function. Thank you very much.
Go to Top of Page
   

- Advertisement -