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
 Max Rate

Author  Topic 

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2010-10-26 : 12:07:02
I'm using SQL 2005 and I wrote the following Query. I can get parts of it to run, but when I run the entire query with the sub query the query will not complete. I'm including table names and column names. Does anyone have any ideas what I could do to get this script to execute?

dbo.AdEnroll
SyStudentID
StartDate
GradDate


dbo.AdEnrollSched
ADEnrollID
SyStudentID
StartDate


dbo.AdEnrollDegree
AdEnrollID
AdDegreeID
DateAwarded





SELECT DISTINCT
TOP (100) PERCENT dbo.syStudent.SyStudentId, dbo.AdEnroll.GradDate, dbo.AdEnrollDegree.DateAwarded, dbo.syStudent.LastName,
dbo.syStudent.FirstName, dbo.AdEnrollSched.ExpectedEndDate
FROM 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.SyStudentId
WHERE (dbo.syStudent.LastName = 'Smith') AND (dbo.syStudent.FirstName = 'John') AND (NOT (dbo.AdEnrollSched.ExpectedEndDate IS NULL))

(Select
LastName,
FirstName,
AdEnrollId,
Max(ExpectedEndDate) AS MaxDate
FROM
dbo.AdEnrollSched,
dbo.SyStudent
Group By
LastName, FirstName, AdEnrollID, ExpectedEndDate)

ORDER BY dbo.AdEnrollSched.ExpectedEndDate, dbo.syStudent.LastName

namman
Constraint Violating Yak Guru

285 Posts

Posted - 2010-10-26 : 15:38:03
Could you provide sample data of the tables and expected output?
Go to Top of Page

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2010-10-27 : 09:18:47
It's a comparison of the end date of the last class ExpectedEndDate to the graduation date which is DateAwarded. I also only want the MAX date for the ExpectedEndDate per person.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-27 : 13:40:50
try to post data in below format to help somebody to suggest a solution

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -