1

Can some one help me to figure out the equivalent function to decode in SQL Server.

Here is the statement which I used for Oracle and I want it for SQL Server. I tried but not able to get it.

UPDATE [SCHEMA].TLS_FAC_PRC_ONG 
SET FPO_RID_OWNER = decode(FPO_RID_OUTSTANDNG,'NONE',FPO_PID_FACILITY,NULL,FPO_PID_FACILITY,FPO_RID_OUTSTANDNG),
FPO_CDE_OWNER = decode(FPO_RID_OUTSTANDNG,'NONE','FAC',NULL,'FAC','OST');
0
UPDATE [SCHEMA].TLS_FAC_PRC_ONG
SET FPO_RID_OWNER = 
CASE WHEN FPO_RID_OUTSTANDNG='NONE' THEN FPO_PID_FACILITY
WHEN FPO_RID_OUTSTANDNG IS NULL THEN FPO_PID_FACILITY
ELSE FPO_RID_OUTSTANDNG END,
FPO_CDE_OWNER = 
CASE WHEN FPO_RID_OUTSTANDNG='NONE' THEN 'FAC'
WHEN FPO_RID_OUTSTANDNG IS NULL THEN 'FAC'
ELSE 'OST' END

DECODE function is a shortcut? for CASE

| improve this answer | |
3

You should be able to turn the decode into a case:

UPDATE
  [SCHEMA].TLS_FAC_PRC_ONG
SET
  FPO_RID_OWNER = CASE FPO_RID_OUTSTANDNG
                    WHEN 'NONE' THEN FPO_PID_FACILITY
                    WHEN NULL THEN FPO_PID_FACILITY
                    ELSE FPO_RID_OUTSTANDNG
  FPO_CDE_OWNER = CASE FPO_RID_OUTSTANDNG
                    WHEN 'NONE' THEN 'FAC'
                    WHEN NULL THEN 'FAC'
                    ELSE 'OST'
                  END
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.