Question : CASE STATEMENT SQL 2005

In crystal reports, I had a formula like this:

if (
{cusASIISC_ImmunizationsGet.Category} = "Diphtheria, Tetanus, Pertussis" or
{cusASIISC_ImmunizationsGet.ImmunCode} = "90696" or
{cusASIISC_ImmunizationsGet.ImmunCode} = "90723" or
{cusASIISC_ImmunizationsGet.ImmunCode} = "90698"
) then
{cusASIISC_ImmunizationsGet.ImmunDte} else
date(9999,9,9)

In SQL, I want to create the same as a field. Would this be the equivalent?

CASE WHEN #temp.Sequence = 0 AND
                  #temp.Category = 'Diphtheria, Tetanus, Pertussis' OR
                  #temp.ImmunCode = '90696' OR
                  #temp.ImmunCode = '90723' OR
                  #temp.ImmunCode = '90698'
                  THEN #temp.ImmunDte
        END AS DTPInjectionDate1

Answer : CASE STATEMENT SQL 2005

most likely you want to use brackets there
condition1 and condition2 or condition3
is true when only condition3 is true
condition1 and (condition2 or condition3)
is true only when condition1 and one of the following two is true

in your SQL code you are missing ELSE part

i think your case should look like that:

SELECT

CASE WHEN .Sequence = 0
  AND (
                  Category = 'Diphtheria, Tetanus, Pertussis' OR
                  ImmunCode = '90696' OR
                  ImmunCode = '90723' OR
                  ImmunCode = '90698'
   )
                  THEN #temp.ImmunDte
   ELSE
        END AS DTPInjectionDate1

FROM #temp
Random Solutions  
 
programming4us programming4us