Declare @FromDatetime= '2011-02-12 00:00:00',
@ToDatetime= '2011-04-28 22:30:20';
Select enroll,Dim.regdate, Cls.ID,rn=ROW_NUMBER() over(partitiOnby enrollorderby Dim.regdate)
INTO #Qry From QR2 As Dim
WhereCast(Dim.regdateAsdatetime)between @From And @to
And enroll not in(12345129,124818243)
And Dim.Stud_ID notIN 112409,12349,12139,121349,213140,12134)
Createclusteredindex R_QOn #Qry(ID)
Select enroll,regdate INTO #Q_2 From #Qry Dim
crossapply(Select distinct Cls.ID From Std_title cp
Join Clsannels ClsOn cp.ref=Cls.ID
And cp.Prof_ID=Dim.Stud_IDAnd Cls.classrm=1
And Cls.Classtype=0And Cls.fk_org=500
) Cls
Select*INTO #temp From ( Select q1.rnAs rn1q2.rnAs rn2, q1.enroll,q1.IDAs c1, q2.IDAs c2 From #Q_2 q1 innerhash Join #Q_2 q2 On q1.enroll=q2.enroll And q2.rn=q1.rn+1And q1.ID<>q2.ID
)tmry
DropTable #Qry
DropTable #temp
Error:
Msg 4104, Level 16, State 1, Line 14
The multi-part identifier "Cls.ID" could not be bound
Please help me to resolve this error? Any further advice to reduce the execution time would also be appreciated.
Thanks in advance for your support and help.
Thank You , Shan Ali Khan