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

  • Home
  • SEARCH
  • 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 8530993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:22:57+00:00 2026-06-11T09:22:57+00:00

I tried Using CASE WHEN statement,But it seems as if i missed something or

  • 0

I tried Using CASE WHEN statement,But it seems as if i missed something or this is not the correct way of doing it.
@APASS parameter makes the query to either return those who passed or those who failed the specified exam.

SELECT   ID, Name,ZipCode,Mobile 
      FROM   tblStudent
      WHERE  (Sex = @Sex) AND (ID IN
      (SELECT StID
      FROM    tblTest
      WHERE   (TestID = @TestID) AND
          CASE WHEN @APass = TRUE THEN (Score IN (27, 28, 29, 30))
          ELSE (Score NOT IN (27, 28, 29, 30))
          END
      GROUP BY StID, TestID
      HAVING        (COUNT(*) = @Times)))
  • 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-11T09:22:58+00:00Added an answer on June 11, 2026 at 9:22 am

    In your case how about:

    WHERE TestID = @TestID
    AND 
    (
        (@APass = 'TRUE' AND Score IN (27, 28, 29, 30))
        OR (@APass = 'FALSE' AND Score NOT IN (27, 28, 29, 30))
    )
    

    Or you could create two separate queries, one for pass, and one for fail. This is probably the most efficient if you care about performance.

    You could also do something cute like:

    WHERE TestID = @TestID
    AND @APass=IF(Score IN (27, 28, 29, 30),'TRUE','FALSE')
    

    But again I wonder if this will truly give you an optimized query.

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

Sidebar

Related Questions

I tried using height: 100% but this makes the div only as high as
Using MS Access, I tried to run an SQL statement but I can't make
i'm using Jquery. This if-statement works: if ($(this).siblings(.numOfMatchedKeywords).text() == 1) { $(this).siblings(.numOfMatchedKeywords).css({'color':'#0099ff'}) } But
I tried using arrays but I don't need every single element, and so it
I tried using date/time, time, but it doesn't help. Exception Details: System.Web.HttpException: DataBinding: 'DatePickerControl.DatePicker'
I tried using the following code for a HTML page, but it doesn't work.
I tried using juggernaut cocoa: https://github.com/fpotter/juggernaut-cocoa Added this line to my code: JuggernautClient *client
I tried using make defconfig to compile the kernel, but as expected, it failed
I tried using both ReadProcessMemory() and WriteProcessMemory() in my application,but in both cases I
This week I took a SQL Statement with 11 case statements with sub query

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.