I'm in the unfortunate situation of developing an app using SQL Server 2005 in the development environment but SQL Server 2000 on the production server. I have a fairly complex SELECT query which works fine on the development/test server but falls over in the production environment:
SELECT tbl_questions.Question, tbl_questions.QuestionCode
FROM tbl_questions INNER JOIN (
SELECT sg.questioncode, sg.gradeB, sg.gradeA, t2.wt
FROM tbl_scoregrade AS sg INNER JOIN (
SELECT t1.QuestionCode, AVG(1.0 * aw.Weight) AS wt
FROM tbl_AnswerWeight AS aw INNER JOIN (
SELECT assa.QuestionCode, assa.Answer
FROM tbl_AllStaffSurveyAnswers AS assa INNER JOIN
tbl_AllStaffSurvey AS ass ON assa.Questionguid = ass.Questionguid
WHERE (ass.Trust = 'RD7') AND (ass.Specialty = '97'))
AS t1 ON aw.questioncode = t1.QuestionCode AND aw.Response = t1.Answer
GROUP BY t1.QuestionCode )
AS t2 ON sg.questioncode = t2.QuestionCode AND sg.gradeA > t2.wt)
AS t3 ON tbl_questions.QuestionCode = t3.questioncode
Can you see anything that should make a difference when run on different versions of SQL server, or indeed any ways of simplifying the query in any case?