Multiple CASE Statements in SQL Server 2012 Dev Ed

  • Hello,

    How do I properly write a CASE statement for the following business logic:

    I want three of the following fields to be true in order to return 'Y'.

    For example:

    If field name 'Accepted' = 1 AND field 'StepNo' = '1' and field 'Visit' = 'V1'

    Otherwise, I want it to return 'N'.

    I have tried the following code below and it is not working. Any suggestions? Thank you in advance!

    , CASE WHEN Accepted = '1' AND StepNo ='1' AND Visit ='V1'

    THEN 'Y' ELSE 'N' END AS 'StatusQ (Col N)'

  • It seems correct to me. What's the problem? Can you post sample data (check my signature to know how to do it properly)?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • When you say, "not working" what do you mean? Do you get an error? Do you get unexpected results? If unexpected results, what are the values that give you unexpected results and what is the expected result?

    Russel Loski, MCSE Business Intelligence, Data Platform

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply