Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. select crsVenue, crsBriefDesc, crsDesc, crdDateTime, crdCode , crsGroupCode, crsCourseOrSes, crsCounterID, cntcounterid, isnull(cntCount,888) cntCount,
  2. "NoOfEn" =
  3. (
  4. select sum(cenHeads) from Enrolments
  5. where cenEnrolDate = cd.crdDateTime
  6. and cenCode = crdCode
  7. and cenGroupCode = crdGroupCode
  8. and cenCourseOrSes = crsCourseOrSes
  9. and cenVenue = crsVenue
  10. and cast(cenEnrolDate as DATE) = cast(crdDateTime as DATE)
  11. )
  12. Into #Tmp
  13. from Courses cs
  14. inner join coursedates cd
  15. on cd.crdgroupcode = cs.crsGroupCode and cd.crdCode = cs.crsCode and cd.crdCourseorSes = cs.crsCourseOrSes and cd.crdvenue = cs.crsvenue
  16. left join Counter cn
  17. on cs.crsCounterID = cn.cntCounterID and cs.crsVenue = cn.cntVenue and DATEADD(dd, 0, DATEDIFF(dd, 0, cd.crdDateTime)) = cn.cntDate
  18. where crdDateTime > '01 jan 2013'
  19. and crsCounterID > 0
  20.  
  21. select * from #Tmp
  22. where cntCount <> NoOfEn
  23. order by crdDateTime
  24.  
  25. drop table #Tmp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement