Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8470869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:38:19+00:00 2026-06-10T16:38:19+00:00

I am trying to run the below query but keep having an issue with

  • 0

I am trying to run the below query but keep having an issue with people whom have both requirements in my Case statement being pulled out for each instance when i only want a single record to be pulled, even if they have both conditions.

SELECT DISTINCT
    SyCampus.Descrip AS 'Campus',
    dbo.rpt_adAttendanceDetail_vw.instructorname AS 'Instructor Name',
    dbo.rpt_adAttendanceDetail_vw.classcode AS 'Class Code',
    dbo.rpt_adAttendanceDetail_vw.section AS 'Section',
    dbo.rpt_adAttendanceDetail_vw.classdescrip AS 'Class',
    RTRIM(SyStudent.FirstName) + ' ' + ' '  + RTRIM(SyStudent.LastName) AS 'Student Name',
    dbo.rpt_adAttendanceDetail_vw.stunum AS 'Student Number',
    CASE WHEN  CmEvent.CmtemplateID IN (714, 716, 732,734)THEN 'YES' ELSE 'NO' END  AS 'Instructor Contact'


FROM 
    dbo.rpt_adAttendanceDetail_vw
 JOIN
    SyStudent
        ON SyStudent.SyStudentID = dbo.rpt_adAttendanceDetail_vw.SyStudentID
 JOIN
    SyCampus
        ON Sycampus.SycampusID = SyStudent.SyCampusID
 JOIN
    CmEvent
        ON CmEvent.SyStudentID = SyStudent.SyStudentID

WHERE   dbo.rpt_adAttendanceDetail_vw.AttMin = '0'
    AND dbo.rpt_adAttendanceDetail_vw.date = DATEADD(d, DATEDIFF(d, 0, GETDATE()), 0) -1
    AND SyStudent.SySchoolStatusID IN (13, 129, 130, 132, 72, 59, 122, 14)
    AND dbo.rpt_adAttendanceDetail_vw.attendtype <> 'E'
    AND CmEvent.CmEventStatusid = '2'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:38:21+00:00Added an answer on June 10, 2026 at 4:38 pm

    I’m assuming that you have a one-to-many relationship between SyStudent and CmEvent. Given that each SyStudent may have a corresponding CmEvent both in and out of the list (714, 716, 732,734) would explain why your query may return more than one record per SyStudent. If you’d like to know if a SyStudent has a CmEvent.CmtemplateID in the given list or not you can handle it in the join.

    Consider the following changes to your query:

    
    SELECT DISTINCT
        SyCampus.Descrip AS 'Campus',
        dbo.rpt_adAttendanceDetail_vw.instructorname AS 'Instructor Name',
        dbo.rpt_adAttendanceDetail_vw.classcode AS 'Class Code',
        dbo.rpt_adAttendanceDetail_vw.section AS 'Section',
        dbo.rpt_adAttendanceDetail_vw.classdescrip AS 'Class',
        RTRIM(SyStudent.FirstName) + ' ' + ' '  + RTRIM(SyStudent.LastName) AS 'Student Name',
        dbo.rpt_adAttendanceDetail_vw.stunum AS 'Student Number',
        CASE WHEN CmEvent.SyStudentID THEN 'YES' ELSE 'NO' END  AS 'Instructor Contact'
        FROM 
        dbo.rpt_adAttendanceDetail_vw 
    JOIN
        SyStudent
            ON SyStudent.SyStudentID = dbo.rpt_adAttendanceDetail_vw.SyStudentID
     JOIN
        SyCampus
            ON Sycampus.SycampusID = SyStudent.SyCampusID
     LEFT JOIN
        CmEvent
            ON CmEvent.SyStudentID = SyStudent.SyStudentID 
            AND CmEvent.CmEventStatusid = '2'
            AND CmEvent.CmtemplateID IN (714, 716, 732,734)
    WHERE   dbo.rpt_adAttendanceDetail_vw.AttMin = '0'
        AND dbo.rpt_adAttendanceDetail_vw.date = DATEADD(d, DATEDIFF(d, 0, GETDATE()), 0) -1
        AND SyStudent.SySchoolStatusID IN (13, 129, 130, 132, 72, 59, 122, 14)
        AND dbo.rpt_adAttendanceDetail_vw.attendtype <> 'E'
        

    The two significant changes here are the left join and the case statement. Firstly, we’ve moved the CmEvent criteria into the left join. By doing this we will only join to records in the CmEvent that meets our criteria. This will leave out all of the CmEvent records whose template ID’s are outside of our list. Secondly, the case statement is changed. Now we are using the existence of a CmEvent.SyStudentID to determine if the SyStudent has a CmEvent.CmtemplateID in the given list. If the left join produces no match then know they do not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run the sql query below but I'm getting a 505 error
I'm trying to run the below-mentioned code in VB(Excel Macro) but I'm stuck with
I am trying to run the code below but it keeps locking up my
I'm trying to run the example Gearman worker from their documentation (see below), but
I am trying to run an mysql sql statement using the code below; public
I am trying to run a rather simple query, but it seems to return
I have two tables that I am trying to join in a query, but
I am trying to run this update statement but informix doesn't allow me to.
I am trying to run a linq query but I need the result as
I am trying to run a mysql query within some php and have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.