SQL Query - combining two ISNULL and IF Statements

Posted on 2012-09-05
Last Modified: 2012-09-05
Hi Experts!

Hows it going!

I have two sql query statements which work perfectly, what I want to do is combine these two queries so the results appear in one column.

These are the statements:

ISNULL(CASE WHEN [Box] = 'RS' AND Reject = 1 THEN 'RR' ELSE [Box] END, Containers) AS Something2

ISNULL(CASE WHEN [Box] = 'PS' AND Reject = 1 THEN 'PR' ELSE [Box] END, Containers) AS Something3

Can you please tell how I can combine the above two queries into one query.

Many thanks

Question by:J3D1-KN1G1-1t
    LVL 25

    Accepted Solution

    Does this work for you?

        WHEN isnull(Box, containers) = 'RS' AND Reject = 1 THEN 'RR'
        WHEN isnull(Box, containers) = 'PS' AND Reject = 1 THEN 'PR'
        ELSE isnull(Box, containers)
    END AS Something

    Author Comment

    Below worked for me, thanks for your inspiration.

    ISNULL(CASE WHEN [Box] = 'RS' AND Reject = 1 THEN 'RR'
                         WHEN [Box] = 'PS' AND Reject = 1 THEN 'PR'
                 ELSE [Box] END, containers) AS Recycle_Code4

    Many Thanks Mate
    LVL 25

    Expert Comment

    by:Lee Savidge
    No problem. Glad to help :)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In this article—a derivative of my blog post (—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
    Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now