自己写的第一个视图(为了纪念)

自己写的第一个视图:

CREATE VIEW [dbo].[view_Returndate]

AS

SELECT     p.htid + ',' + p.inspectingitemAssignment AS htidassign, p.htid AS htid, c.classificationname AS classificationname, item.projectnumber AS result,

                      p.phone AS sampleid, p.times AS statu, p.client AS conversion, p.sampledate AS finishtime, item.projectnumber AS projectnumber,c.classification as classification

FROM         inspectingitem AS item, childinspecting AS c, inspectionpact AS p

WHERE     item.projectnumber IN

                          (SELECT     *

                            FROM          dbo.f_splitstr(cast(p.inspectingitem AS varchar(1024)), ',')) AND item.projectnumber = c.projectnumber AND

                    (p.htid + '' + item.projectnumber+''+c.classification NOT IN

                          (SELECT     r.htid + '' + r.inspectingitem +''+r.classification AS a

                            FROM          returndate AS r))

UNION

SELECT     r.htid + ',' + item.projectnumber AS htidassign, r.htid, c.classificationname AS classificationname, r.result AS result, r.sampleid AS sampleid,

                      r.statu AS statu, r.conversion AS conversion, r.finishtime AS finishtime, r.inspectingitem AS projectnumber,c.classification as classification

FROM         returndate r LEFT JOIN

                      inspectingitem item ON r.inspectingitem = item.projectnumber LEFT JOIN

                      childinspecting c ON r.inspectingitem = c.projectnumber and r.classification=c.classification

 

 

// dbo.f_splitstr这个是自己写的处理字符串的函数

原文地址:https://www.cnblogs.com/wangliansong/p/3517569.html