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