Subject view porting problem
Author fhasovic
Hi.
I am having some difficulties porting following view from MSSQL2000
to Firebird 1.5:

CREATE view v_MDEntries as
select
*,
left(DLN, 14) as DLNBlock,
(case
when isnull(EC_UsrID, 0) <> 0 then 4
when isnull(KV_UsrID, 0) <> 0 then 3
when isnull(OE_UsrID, 0) <> 0 then 2
when isnull(MD_UsrID, 0) <> 0 then 1
else 0 end) as Status,
(case
when isnull(EC_UsrID, 0) <> 0 then EC_UsrTS
when isnull(KV_UsrID, 0) <> 0 then KV_UsrTS
when isnull(OE_UsrID, 0) <> 0 then OE_UsrTS
when isnull(MD_UsrID, 0) <> 0 then MD_UsrTS
else 0 end) as StatusTS
from m_MDEntries

My attempt finished at:

CREATE VIEW "v_MDEntries"(
"MdentryID",
"DeclID",
DLN,
TIN,
"FromDate",
"ToDate",
"TodID",
"CantonID",
"LOfficeID",
"MD_UsrID",
"MD_UsrTS",
"OE_UsrID",
"OE_UsrTS",
"OE_Timer",
"KV_UsrID",
"KV_UsrTS",
"KV_Timer",
"EC_UsrID",
"EC_UsrTS",
"EC_Timer",
"DecPosted",
"DLNBlock",
"Status",
"StatusTS")
AS
select M.*, SUBSTRING(DLN FROM 1 FOR 14) as "DLNBlock",
case
when COALESCE("EC_UsrID", 0) <> 0 then 4
when COALESCE("KV_UsrID", 0) <> 0 then 3
when COALESCE("OE_UsrID", 0) <> 0 then 2
when COALESCE("MD_UsrID", 0) <> 0 then 1
else 0
end as "Status"
/*case
when "EC_UsrID" <> 0 then "EC_UsrTS"
when COALESCE("KV_UsrID", 0) <> 0 then "KV_UsrTS"
when COALESCE("OE_UsrID", 0) <> 0 then "OE_UsrTS"
when COALESCE("MD_UsrID", 0) <> 0 then "MD_UsrTS"
else 0
end */as "StatusTS"
from "m_MDEntries" M;

but with this part of query
case
when "EC_UsrID" <> 0 then "EC_UsrTS"
when COALESCE("KV_UsrID", 0) <> 0 then "KV_UsrTS"
when COALESCE("OE_UsrID", 0) <> 0 then "OE_UsrTS"
when COALESCE("MD_UsrID", 0) <> 0 then "MD_UsrTS"
else 0
end as "StatusTS"

I get following error
invalid token.
Dynamic SQL Error.
SQL error code = -104.
Datatypes are not comparable in expression CASE.


Can someone, please, help me with this?
Thanks in advance.

Fikret Hasovic
TAMP R&D Team.