IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[Qsy_xcdk]') AND type = 'V')
DROP VIEW [dbo].[Qsy_xcdk]
GO




CREATE VIEW [dbo].[Qsy_xcdk]
AS
SELECT     jh.ord_id AS 主表ID, mx.ord2_id AS 明细ID, jh.ord_no AS 业务单号, jh.ord_ygtx AS 员工体系, jh.ord_createdepart AS 建单部门, da.ord_gh AS 建单人工号, jh.ord_creator AS 建单人, 
                      da.ord_zhij AS 职级, CONVERT(varchar(100), jh.ord_ksrq, 23) AS 开始日期, CONVERT(varchar(100), jh.ord_jsrq, 23) AS 结束日期, jh.ord_gzsm AS 上周总结, jh.ord_jhym AS 本周计划, 
                      mx.ord2_xclx AS 行程类型, CONVERT(varchar(100), mx.ord2_kssj, 23) AS 行程开始时间, CONVERT(varchar(100), mx.ord2_jssj, 23) AS 行程结束时间, mx.ord2_xcmdd AS 行程目的地,mx.ord2_dpbh 店铺编号,
                      mx.ord2_xcms, 
                      jh.ord_updated 行程状态,--审核时间
                      --mx.ord2_status AS 行程状态2, 
                      CONVERT(varchar(100), dk.ord_sjdqsj, 23) AS 打卡日期, dk.ord_sjdqsj AS 实际打卡时间, dk.ord_dkdd AS 打卡地点, dk.ord_ycxc AS 异常说明, 
                      (CASE WHEN isnull(dk.ord_photos, '') = '' THEN NULL ELSE 'http://ebs.shesyea.com.cn' + dbo.[chaifenlie](dk.ord_photos, '|', 1) END) AS firstphoto, (CASE WHEN dbo.[chaifenlie](dk.ord_photos, '|', 1) 
                      = dbo.[chaifenlie](dk.ord_photos, '|', 2) THEN NULL ELSE 'http://ebs.shesyea.com.cn' + dbo.[chaifenlie](dk.ord_photos, '|', 2) END) AS secondphoto, (CASE WHEN dbo.[chaifenlie](dk.ord_photos, '|', 2) 
                      = dbo.[chaifenlie](dk.ord_photos, '|', 3) THEN NULL ELSE 'http://ebs.shesyea.com.cn' + dbo.[chaifenlie](dk.ord_photos, '|', 3) END) AS thirdphoto
FROM         dbo.order_89 AS jh INNER JOIN
                      dbo.order_89_2 AS mx  LEFT OUTER JOIN
                      dbo.order_91 AS dk ON mx.ord2_id = dk.ord_xcmxord2id ON jh.ord_id = mx.ord2_ordid INNER JOIN
                      dbo.mps_employee AS cu ON jh.ord_createcuid = cu.cu_id INNER JOIN
                      dbo.order_40 AS da ON cu.cu_code = da.ord_gh
WHERE     jh.ord_status = '已完成'  and mx.ord2_status<>'已取消'