1. IF ... else (SQL Server does not have end,oracle in it)
DECLARE @co INT
SET @co = (SELECT COUNT (1) from HGOS_UC.dbo.Emp_Ora_Role Eor WHERE Eor. empid=539 and Eor. DEPID=35)
IF @co =0
SELECT cr.*
From HGOS.dbo.CustomerRM as CR
JOIN HGOS_WF.dbo.Task as T on cr.companycode = t.oid
Left joins HGOS.dbo.Customer_Ora_R as Cor on Cor. CID=CR. Id
WHERE cor.orgid=35
and t.state = 4 and ISNULL (t.isdelete,0) = 0 and ISNULL (CR. isfreeze,0) = 0
and Cr. createuserid=539
ELSE
SELECT cr.*
From HGOS.dbo.CustomerRM as CR
JOIN HGOS_WF.dbo.Task as T on cr.companycode = t.oid
Left joins HGOS.dbo.Customer_Ora_R as Cor on Cor. CID=CR. Id
WHERE cor.orgid=35
and t.state = 4 and ISNULL (t.isdelete,0) = 0 and ISNULL (CR. isfreeze,0) = 0
2. Case ... When ... Then
SELECT
T.id,
Case
when state=1 Then ' approval '
when state=2 Then ' passed '
ELSE ' Dismissed '
END
from HGOS_WF.dbo.Task as T;
SQL Server BASIC Process statements