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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:41:19+00:00 2026-06-14T04:41:19+00:00

Column 1: ( CASE WHEN (SELECT edition FROM clients.dbo.service WHERE serv_id = hdr.serv_id) =

  • 0

Column 1:

( CASE
           WHEN (SELECT edition
                 FROM   clients.dbo.service
                 WHERE  serv_id = hdr.serv_id) = 'General' THEN 'G'
           WHEN (SELECT edition
                 FROM   clients.dbo.service
                 WHERE  serv_id = hdr.serv_id) = 'Honors' THEN 'H'
           WHEN (SELECT edition
                 FROM   clients.dbo.service
                 WHERE  serv_id = hdr.serv_id) = 'WhosWho' THEN 'Y'
           WHEN (SELECT edition
                 FROM   clients.dbo.service
                 WHERE  serv_id = hdr.serv_id) = 'Catholic' THEN 'J'
           WHEN (SELECT edition
                 FROM   clients.dbo.service
                 WHERE  serv_id = hdr.serv_id) = 'Conservative' THEN 'B'
           ELSE 'H'
         END )                        AS Edition

Column 2:

(SELECT edition
        FROM   clients.dbo.service
        WHERE  serv_id = hdr.serv_id) AS editiontext,
       ( CASE
           WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
           ELSE ( CASE
                    WHEN si.itmclass = 'Distrib' THEN '-Disc'
                    WHEN si.itmclass = 'PremIR' THEN '0' + '-Disc'
                    WHEN si.itmclass = 'InstResp' THEN '5' + '-Disc'
                    ELSE ''
                  END )
         END )                        AS 'ItemCode'

I need to combine both Edition and ItemCode in a third column. -Disc (ItemCode) should becone like G-Disc but 0-Disc (ItemCode) should become like 0G-Disc.

I need the select as

Select Edition, ItemCode, Edition+ItemCode….

I have used following to create the third column but curious if this could be done in a better way…

( CASE
           WHEN (SELECT edition
                 FROM   clients.dbo.service
                 WHERE  serv_id = hdr.serv_id) = 'General' THEN (
           CASE
             WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
             ELSE( CASE
                     WHEN si.itmclass = 'Distrib' THEN 'G-Disc'
                     WHEN si.itmclass = 'PremIR' THEN '0G' + '-Disc'
                     WHEN si.itmclass = 'InstResp' THEN '5G' + '-Disc'
                     ELSE ''
                   END )
           END )
           WHEN (SELECT edition
                 FROM   clients.dbo.service
                 WHERE  serv_id = hdr.serv_id) = 'Honors' THEN (
           CASE
             WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
             ELSE( CASE
                     WHEN si.itmclass = 'Distrib' THEN 'H-Disc'
                     WHEN si.itmclass = 'PremIR' THEN '0H' + '-Disc'
                     WHEN si.itmclass = 'InstResp' THEN '5H' + '-Disc'
                     ELSE ''
                   END )
           END )
           WHEN (SELECT edition
                 FROM   clients.dbo.service
                 WHERE  serv_id = hdr.serv_id) = 'WhosWho' THEN (
           CASE
             WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
             ELSE( CASE
                     WHEN si.itmclass = 'Distrib' THEN 'Y-Disc'
                     WHEN si.itmclass = 'PremIR' THEN '0Y' + '-Disc'
                     WHEN si.itmclass = 'InstResp' THEN '5Y' + '-Disc'
                     ELSE ''
                   END )
           END )
           WHEN (SELECT edition
                 FROM   clients.dbo.service
                 WHERE  serv_id = hdr.serv_id) = 'Catholic' THEN (
           CASE
             WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
             ELSE( CASE
                     WHEN si.itmclass = 'Distrib' THEN 'J-Disc'
                     WHEN si.itmclass = 'PremIR' THEN '0J' + '-Disc'
                     WHEN si.itmclass = 'InstResp' THEN '5J' + '-Disc'
                     ELSE ''
                   END )
           END )
           WHEN (SELECT edition
                 FROM   clients.dbo.service
                 WHERE  serv_id = hdr.serv_id) = 'Conservative' THEN (
           CASE
             WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
             ELSE( CASE
                     WHEN si.itmclass = 'Distrib' THEN 'B-Disc'
                     WHEN si.itmclass = 'PremIR' THEN '0B' + '-Disc'
                     WHEN si.itmclass = 'InstResp' THEN '5B' + '-Disc'
                     ELSE ''
                   END )
           END )
           ELSE ( CASE
                    WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
                    ELSE( CASE
                            WHEN si.itmclass = 'Distrib' THEN 'H-Disc'
                            WHEN si.itmclass = 'PremIR' THEN '0H' + '-Disc'
                            WHEN si.itmclass = 'InstResp' THEN '5H' + '-Disc'
                            ELSE ''
                          END )
                  END )
         END )                        AS EditionItemCode
  • 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-14T04:41:20+00:00Added an answer on June 14, 2026 at 4:41 am

    You have a number of redundant subqueries in your case statement that I don’t think need to be there. If I understand your tables and queries correct, you should be able to do the following instead. Note I have pulled out the first case statement (Edition column) into a derived-table join, then reference it from the second case statement to make EditionItemCode.

    SELECT s.edition AS editiontext, s.e AS edition,
        CASE
            WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
            WHEN si.itmclass = 'Distrib' THEN '-Disc'
            WHEN si.itmclass = 'PremIR' THEN '0-Disc'
            WHEN si.itmclass = 'InstResp' THEN '5-Disc'
            ELSE ''
        END AS ItemCode,
        CASE
            WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
            WHEN si.itmclass = 'Distrib' THEN s.e + '-Disc'
            WHEN si.itmclass = 'PremIR' THEN '0' + s.e + '-Disc'
            WHEN si.itmclass = 'InstResp' THEN '5' + s.e + '-Disc'
            ELSE ''
        END AS EditionItemCode
    FROM hdr
    LEFT OUTER JOIN
    (
        SELECT serv_id, CASE edition
                   WHEN 'General' THEN 'G'
                   WHEN 'Honors' THEN 'H'
                   WHEN 'WhosWho' THEN 'Y'
                   WHEN 'Catholic' THEN 'J'
                   WHEN 'Conservative' THEN 'B'
                   ELSE 'H'
              END AS e, edition
        FROM clients.dbo.service
    ) s ON s.serv_id = hdr.serv_id
    JOIN si ON ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SELECT CASE Forms!FormName!ComboBox WHEN Is Not Null THEN (ParentTable.Column) FROM (Parent) WHERE (((ParentTable.Column)=Forms!FormName!ComboBox)) ELSE
SELECT CASE Price WHEN '' THEN 0.0 ELSE Price END FROM Table If price
I have a column in my select statement that looks like this: SELECT CASE
select CASE WHEN ( rtt.us_code = 's' ) THEN rtt.name ELSE '' END AS
I have been using SELECT Author, ISNULL(MAX(CASE Status WHEN 'Duplicate' THEN NumDocs END),'') AS
I have the below query: select CASE WHEN rt.ROLE_TYPE_CD = 'SA' THEN ap.APPL_CD +
select (case when t.freeplayabandoned != f.freeplayabandoned then 'freeplayabandoned' when t.freeplaydownloaded != f.freeplaydownloaded then 'freeplaydownloaded'
This works: SELECT (CASE WHEN x = 'value' THEN a.col1 ELSE nvl(a.col1, a.col2) END)
Is there any way to have a CASE SELECT Statement in a PIVOTED Column.
I have code like following: switch(sort.Column) { case code: model = (sort.Direction == SortDirection.Ascending)

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.