3800: Datatype Mismatch in THEN/ELSE expression.

General
Fan

3800: Datatype Mismatch in THEN/ELSE expression.

Hi, I'm trying to write a query to force value '~' in a date field when date value is null. But I'm getting 3800: Datatype Mismatch in THEN/ELSE expression error in TD. Below is my query

Select Employee_ID,
CASE
WHEN(Joining_DT IS NULL) THEN ( '~' )
ELSE Joining_DT END (CHAR(8))
from Employee;

Any ideas please? Thank you
4 REPLIES
Enthusiast

Re: 3800: Datatype Mismatch in THEN/ELSE expression.

Try this...

Select Employee_ID,
CASE
WHEN Joining_DT IS NULL
THEN cast( '~' as char(8))
ELSE cast (Joining_DT as Char(8)) END
from Employee;
Fan

Re: 3800: Datatype Mismatch in THEN/ELSE expression.

Thank you Suma, It worked. Appreciate it

Re: 3800: Datatype Mismatch in THEN/ELSE expression.

when I am matching the  A.COL1= B.COL1 then populate corresponding B.COL2.

COL1 is char fields, COL2 is date field. I tried as below but didn't worked.

SELECT

CASE WHEN  A.COL1= B.COL1 THEN B.COL2

ELSE CAST('~' AS CHAR(8))

END ORD_DTE

FROM A LEFT OUTER JOIN B ON A.COL1= B.COL1

SELECT Failed. 3800: Datatype Mismatch in THEN/ELSE expression.

plz advice, thanks in advance.

Enthusiast

Re: 3800: Datatype Mismatch in THEN/ELSE expression.

try this

SELECT

CASE WHEN  A.COL1= B.COL1 THEN CAST(B.COL2 AS CHAR(8))

ELSE CAST('~' AS CHAR(8))

END ORD_DTE

FROM A LEFT OUTER JOIN B ON A.COL1= B.COL1