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 6659023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:58:57+00:00 2026-05-26T01:58:57+00:00

New to SQL and I’ve just created a SQL query with assitance: SELECT CASE

  • 0

New to SQL and I’ve just created a SQL query with assitance:

       SELECT CASE

    WHEN exists (SELECT CLIENT_CODE FROM STG_DM_CLIENT      
       WHERE CLIENT_CODE 
      NOT IN (SELECT CLIENT_CODE FROM DM_CLIENT)) THEN 'A'
      else

WHEN  exists (SELECT STG.CLIENT_CODE AS TRAN_TYPE
    FROM  STG_DM_CLIENT STG          
    JOIN DM_CLIENT SRC
    ON SRC.CLIENT_CODE = STG.CLIENT_CODE  
    WHERE (SRC.CLIENT_NAME <> STG.CLIENT_NAME)) THEN 'C'
    END 
FROM DM_CLIENT, STG_DM_CLIENT

Fails to provide the correct resulset, states incorect syntax next to when

Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword ‘WHEN’.

Any ideas as to what I’m doing wrong

  • 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-05-26T01:58:57+00:00Added an answer on May 26, 2026 at 1:58 am

    It’s not clear what your after, this is the closest valid statement;

    SELECT 
        CASE WHEN EXISTS (...) 
            THEN 'A'
        ELSE 
            CASE WHEN EXISTS (...) 
                THEN 'C'
                ELSE 'Neither exists()'
            END
        END
    

    When the 1st exists is matched you will get A
    When the 1st does not exist you will get C if the 2nd does match

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

Sidebar

Related Questions

I am totally new to SQL . I have a simple select query similar
I've just made the switch from MS sql server to Oracle. The query tool
I am writing some new SQL queries and want to check the query plans
If you are a new sql server dba and you just get an account
I created a new SQL Server Database Project within VS 2010, imported the database
We just moved our SQL 2000 databases to a new SQL 2008 box. After
My problem is: each entry in view calls new sql query altough i used
We have moved a database from SQL 2000 to a new SQL 2005 that
Question: The new SQL Server 2008 database returns me values formatted English (date/float). Is
I'm loading a SQL Server 2000 database into my new SQL Server 2005 instance

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.