My boss threw this code in my direction, and it's hard for me to understand how the last ON statement works. I do not think that he fully understands this (but he is doing his job). It's actually just interesting to learn more about how SQL works. Thank you very much!
Here is the On instruction
and (A.Submitted_Date > X.Submitted_Date)))
And here is the request
SELECT AA.ID, AA.Submitted_Date as Date_Status FROM Report as AA where AA.Submitted_Date in --START ( SELECT X.Submitted_Date FROM Report as A inner join --Start Find All Dates Submitted ( SELECT [ID],[Submitted_Date] FROM Report where not(Submitted_Date is null and Cleared_Date is null) group by ID, Submitted_Date) as X --End Find all Dates Submittd --below is the conditions of the join ON A.ID = X.ID and A.ID= AA.ID --THIS IS THE CONDITION I AM CONFUSED ABOUT!!!! and (A.Submitted_Date > X.Submitted_Date))) group by X.Submitted_Date) and not AA.Submitted_Date is null group by AA.ID, AA.Submitted_Date
Here is an example of dates from table A
2012-11-27 00:00:00.000 2012-11-27 00:00:00.000 2012-11-27 00:00:00.000 2012-12-10 00:00:00.000 2012-11-27 00:00:00.000 2012-11-27 00:00:00.000 2012-11-29 00:00:00.000 2012-12-05 00:00:00.000 2012-12-12 00:00:00.000
Here is an example of dates from table X
2012-11-27 00:00:00.000 2012-11-29 00:00:00.000 2012-12-05 00:00:00.000 2012-12-10 00:00:00.000 2012-12-12 00:00:00.000
Here is the result before the last state
2012-11-27 00:00:00.000 2012-11-29 00:00:00.000 2012-12-05 00:00:00.000 2012-12-10 00:00:00.000 2012-12-12 00:00:00.000
Here is the result with A.Sub> X.Sub
2012-11-27 00:00:00.000 2012-11-29 00:00:00.000 2012-12-05 00:00:00.000 2012-12-10 00:00:00.000
I am confused why these dates appear. What compares between A and X? Will the values ββin invariable like X always be, therefore, do not lead to final data? Thanks for the help!