C # Background SQL statement comments, conditional selection according to the IsNull () method

Source: Internet
Author: User
Tags joins

Select IsNull (B.guid,k.guid) as Project_id,isnull (B.projectno,k.projectno) as Projectno,
IsNull (B.projectname,k.projectname) as projectname,c.companyname as customer,
IsNull (b.project_date,k.project_date) as project_date,d.typecn,a.guid as Apply_id,a.applyname,e.applycreditamt,
Sum (IsNull (f.payamount,0)) Payamount,f.paydate,g.name as pay_user,h.name as SALER,J.TYPECN as Approval_status,
IsNull (B.create_time,k.create_time) as bcreate_time,a.create_time as Acreate_time,
(case when B.guid was Null then ' ZL ' Else ' BL ' end) as ProjectType into #tbl
From Dbo.ffs_projectapply A
Left join Ffs_project B on A.projectid=b.guid
Left join Ffs_projectlease K on A.projectid=k.guid
Left join Ffs_customer C on C.guid=isnull (B.customerid,k.customerid)
Left joins Ffs_publicelement D on D.code=isnull (B.project_type,k.project_type) and d.type= ' Project_type '
Left join Ffs_payment E on E.projectapplyid=a.guid
Left join Ffs_paymentdetail F on F.projectapplyid=a.guid
Left joins Ifs_user G on G.guid=f.payopuser
Left join Ifs_user h on h.guid=a.saler_id
Left join Ffs_customerrefsaler i on I.customer_id=isnull (B.customerid,k.customerid) and i.recordstatus= ' A '
Left joins Ffs_publicelement J on J.code=a.recordstatus and J.type= ' Projectapply_status '
where IsNull (b.project_date,k.project_date) between ' 2017-01-25 ' and ' 2017-04-26 '--and B.project_type in (' 001 ', ' 002 ', ' 003 ', ' 004 ', ' 005 ')
and a.recordstatus= ' payed ' and isnull (b.recordstatus,k.recordstatus) = ' Approved '

In the blue mark, the IsNull () method is used to select the on condition skillfully.

In the red flag, the SQL statement is written in the C # background, using "--" to annotate

C # Background SQL statement comments, conditional selection according to the IsNull () method

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.