jadams0173
Technical User
- Feb 18, 2005
- 1,210
SQL 2000
I'm having a hard time converting these JET function to SQL. I've made several attempts but seem like a dig a deeper hole. I've successfully convert a few more of my JET queries to sql but this one is giving me a hard time.
First the JET query
Now my latest unsuccesful attempt at SQL. I'm stuck on the part in red above.
I'm having a hard time converting these JET function to SQL. I've made several attempts but seem like a dig a deeper hole. I've successfully convert a few more of my JET queries to sql but this one is giving me a hard time.
First the JET query
Code:
SELECT J.JobNumber, J.PreReq, T.CourseNo, T.EmpNo, Max(T.CourseDate) AS TakenOn,
tblSubCourse.SubCourseName, tblSubCourse.ExpirationInMonths,
[red]Max(CDate(Format(IIf(IsNull([T].[EmpNo]),#1/1/1900#,IIf([ExpirationInMonths]=0,#12/31/2099#,
DateAdd("m",cint(([expirationInMonths])),[coursedate]))),"mm/dd/yyyy"))) AS ExpireDate, [/red]
IIf(isnull([Disqualified]),0,[t].[Disqualified])AS Disqual
FROM (tblJobReq AS J LEFT JOIN [SELECT * FROM tblTrainingRecords WHERE EmpNo='06388']. AS T ON J.PreReq = T.CourseNo) LEFT JOIN tblSubCourse ON J.PreReq = tblSubCourse.SubCourseNumber WHERE (((J.JobNumber)= '101')) GROUP BY J.JobNumber, J.PreReq, T.CourseNo, T.EmpNo, tblSubCourse.SubCourseName, tblSubCourse.ExpirationInMonths, IIf(isnull([Disqualified]),0,[t].[Disqualified])
Now my latest unsuccesful attempt at SQL. I'm stuck on the part in red above.
Code:
[COLOR=blue]SELECT[/color] J.JobNumber, J.PreReq, [COLOR=blue]T[/color].CourseNo, [COLOR=blue]T[/color].EmpNo, [COLOR=#FF00FF]Max[/color]([COLOR=blue]T[/color].CourseDate) [COLOR=blue]AS[/color] TakenOn,
tblSubCourse.SubCourseName, tblSubCourse.ExpirationInMonths,
[COLOR=blue]IF[/color] [[COLOR=blue]T[/color]].[EmpNo] [COLOR=blue]IS[/color] NULL
[COLOR=red]'1/1/1900'[/color]
[COLOR=blue]Else[/color]
[COLOR=blue]Begin[/color]
[COLOR=blue]Case[/color] [Tblsubcourse].[ExpirationInMonths]
[COLOR=blue]WHEN[/color] 0 [COLOR=blue]THEN[/color] [COLOR=#FF00FF]CONVERT[/color]([COLOR=#FF00FF]DATETIME[/color],[COLOR=red]'12/31/2099'[/color])
[COLOR=blue]ELSE[/color] [COLOR=#FF00FF]DATEADD[/color] ( M , [Tblsubcourse].[ExpirationInMonths],[COLOR=#FF00FF]Max[/color](([[COLOR=blue]T[/color]].[CourseDate]))
[COLOR=blue]END[/color]) [COLOR=blue]AS[/color] [ExpireDate] ,
[COLOR=blue]End[/color]
IIf([COLOR=#FF00FF]isnull[/color]([Disqualified]),0,[[COLOR=blue]t[/color]].[Disqualified])[COLOR=blue]AS[/color] Disqual
[COLOR=blue]FROM[/color] (tblJobReq [COLOR=blue]AS[/color] J [COLOR=#FF00FF]LEFT[/color] [COLOR=blue]JOIN[/color] ([COLOR=blue]SELECT[/color] * [COLOR=blue]FROM[/color] tblTrainingRecords [COLOR=blue]WHERE[/color] EmpNo=[COLOR=red]'06388'[/color]) [COLOR=blue]AS[/color] [COLOR=blue]T[/color]
[COLOR=blue]ON[/color] J.PreReq = [COLOR=blue]T[/color].CourseNo) [COLOR=#FF00FF]LEFT[/color] [COLOR=blue]JOIN[/color] tblSubCourse [COLOR=blue]ON[/color] J.PreReq = tblSubCourse.SubCourseNumber
[COLOR=blue]WHERE[/color] (((J.JobNumber)= [COLOR=red]'101'[/color]))
[COLOR=blue]GROUP[/color] [COLOR=blue]BY[/color] J.JobNumber, J.PreReq, [COLOR=blue]T[/color].CourseNo, [COLOR=blue]T[/color].EmpNo, tblSubCourse.SubCourseName,
tblSubCourse.ExpirationInMonths, IIf([COLOR=#FF00FF]isnull[/color]([Disqualified]),0,[[COLOR=blue]t[/color]].[Disqualified])