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
 Sql Statement Dates Prob

Author  Topic 

tadhg88
Yak Posting Veteran

62 Posts

Posted - 2007-07-24 : 09:57:43
Hi i am trying to write a statement to get the players in a squad based on the StartDate, EndDate of any season and the DateEntered, DateLeft a squad
the possible situations are
Player joins squad after StartDate and is still there (DateLeft Null)
Player joins squad after StartDate and leaves before EndDate
Player joins before StartDate and is still there (DateLeft Null)
Player joins before StartDate and leaves before EndDate

this is my statement at the moment but i am gettin players that are in the squad this season and last season sp if anyone has any ideas i would really appreciate them
select spm.SquadId,Person.Id as ID, IsNull(firstName+ ' ','') + IsNull(MiddleName+ ' ','') + IsNull(LastName,'') as Name, spm.DateEntered, spm.DateLeft
From Person
LEFT JOIN SquadPlayerMapping spm on spm.PlayerId = Person.Id
Where spm.SquadId = 2927
And ((spm.DateLeft IS NULL) Or (spm.DateEntered >= (Select StartDate From Seasons Where ID = 50)))
And spm.DateEntered <= (Select EndDate From Seasons Where ID = 50)
Order by LastName

thanks in advance
Tim

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-07-24 : 11:24:33
You didn't explain very well what it is you are trying to do and what is wrong with your query.

It would be helpful if you also provided table structures, sample data, and your expected output.


CODO ERGO SUM
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-24 : 12:17:59
And spm.DateEntered <= ISNULL((Select EndDate From Seasons Where ID = 50), spm.DateEntered)

Also see
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81373



E 12°55'05"
N 56°04'39"
Go to Top of Page
   

- Advertisement -