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, IF and/or EXISTS

Author  Topic 

dmaxj
Posting Yak Master

174 Posts

Posted - 2009-08-16 : 21:58:04
I am trying to figure out this query. I am thinking that I will have to use the EXISTS Keyword with a JOIN in a subquery along with a CASE statment, but I am really baffled as to how to get the right query.

Here is the scenario, regards:

Please write a SQL statement based on the information below that retrieves the history of each position grouped by organization. If the position is currently vacant, display the number of months the position has been vacant instead of the employee’s name. If the position has always been vacant, display that the position has never been filled instead of the employee’s name.

In database VPositions, there are two tables called Positions and PersonsPositions:

Positions
----------
PositionID
PositionTitle
OrganizationID

PersonPositions
----------------
PersonPositionID
PersonID
PositionID
AssignmentStartDate
AssignmentEndDate

In database VPersons, there is a table called Persons:

Persons
--------
PersonID
LastName
FirstName

In database VOrganizations, there is a table called Organizations:

Organizations
--------------
OrganizationID
OrganizationName

cat_jesus
Aged Yak Warrior

547 Posts

Posted - 2009-08-17 : 15:05:45
Homework?

An infinite universe is the ultimate cartesian product.
Go to Top of Page
   

- Advertisement -