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.
| Author |
Topic |
|
meberg66219
Yak Posting Veteran
65 Posts |
Posted - 2010-11-02 : 16:19:26
|
| I have been trying to write a query that does the following:ddbo.AdEnrollSyStudentIDStartDateGradDatedbo.AdEnrollSchedADEnrollIDSyStudentIDExpectedEndDatedbo.AdEnrollDegreeAdEnrollIDAdDegreeIDDateAwardedI want any student ID that has a DateAwarded Date in dbo.AdEnrollDegreeANDI want to compare the DateAwarded to ExpectedEndDateSELECT DISTINCT TOP (100) PERCENT dbo.syStudent.SyStudentId, dbo.AdEnroll.GradDate, dbo.AdEnrollDegree.DateAwarded, dbo.syStudent.LastName, dbo.syStudent.FirstName, dbo.AdEnrollSched.ExpectedEndDateFROM dbo.AdEnrollSched RIGHT OUTER JOIN dbo.AdEnroll ON dbo.AdEnrollSched.AdEnrollID = dbo.AdEnroll.AdEnrollID LEFT OUTER JOIN dbo.AdEnrollDegree ON dbo.AdEnroll.GradDate = dbo.AdEnrollDegree.DateAwarded RIGHT OUTER JOIN dbo.syStudent ON dbo.AdEnroll.SyStudentID = dbo.syStudent.SyStudentIdWHERE (dbo.AdEnrollSched.ExpectedEndDate IS NOT NULL) AND (dbo.AdEnroll.GradDate IS NOT NULL)This query pulls back the raw data, but when I try to use a group by or MAX Sub Query to compare the tables I get errors.Here is the sub Query I was trying to use:(Select LastName,FirstName,AdEnrollId,Max(ExpectedEndDate) AS MaxDateFROM dbo.AdEnrollSched,dbo.SyStudentGroup ByLastName, FirstName, AdEnrollID, ExpectedEndDate) |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-11-02 : 20:16:15
|
| [code]SELECT s.SyStudentID, s.ExpectedEndDate, d.DateAwarded, DateDiff(day, s.ExpectedEndDate, d.DateAwarded)FROM dbo.AdEnrollSched sJOIN dbo.AdEnrollDegree dOn d.EnrollID = s.EnrollIDWHERE DateArarded is NOT NULL[/code]You may not need the line highlighted in red, can't tell from your post. |
 |
|
|
|
|
|
|
|