SQL Server BASIC Process statements

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.