Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CASE STATEMENT

Status
Not open for further replies.

EPNICO

MIS
Jun 14, 2001
45
US
CASE
WHEN EETERMDATE IS NULL THEN ' '
ELSE CONVERT(CHAR(10),EETERMDATE,101)
END as TerminationDate, --(28)

In the statement above the following if statement is coded
if eetermdate is null then blanks
else convert eetermdate to a date format

What if I wanted to code the following if statement
if status is terminated
if eetermdate is null then blanks
else convert eetermdate to a date format
else terminate field should be blank not nulls.

Is it possible to do it in ms-sql using the case statement?

Any ideas are welcome.

Thanks.

 
Why not just try it out in query analyzer? I did and I found that nested CASE expression are allowed.

Code:
DECLARE @eetermdate DATETIME
DECLARE @statuscode VARCHAR(10)
SET @statuscode = 'terminated'
SET @eetermdate = '10/01/2003'
SELECT
  CASE
    WHEN @statuscode = 'terminated'
      THEN CASE
             WHEN @eetermdate IS NULL THEN 'A'
             ELSE 'B'
           END
    ELSE 'C'
  END

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top