V_Order_Service

ALTER VIEW [dbo].[V_Order_Service]   
AS   
SELECT  t.Order_Service_Id, t .Service_Type_Name, t.Service_Type_Id, t.Service_Item_Code, t .Royalty_Rate
 , t .Created_By, t .Created_Name, t .Is_Audited,o.Is_Audit, t .Responsible_Person,t.Responsible_Person_Id
 , t .Customer_Job_No, t .Operators, t .Operators_Uid,o.Order_Id, o.Order_No, o.Order_Time,    
 o.Customers AS Customer_Name, o.Sales_Man AS Salesman_Name, o.Sales_Man_Uid AS Salesman_Id
 , o.Customers_Id AS Customer_Id, o.So_No,o.Rank_Name, o.Port, o.Bill_Credentials, o.Created_Name Order_Created_Name
 , t.Audit_Man, o.Created_Date, Ea_No, o.Is_Audit_Name,o.Cutoff_Date
 , (CASE t.Service_Item_Code WHEN 'L/C' THEN 'L/C' WHEN 'T/T' THEN 'T/T' ELSE si.Item_Name END) AS Service_Item_Name   
FROM (
(SELECT b.Order_Id, b.Order_Shipping_Id AS Order_Service_Id, st.[Service_Name] AS Service_Type_Name
 , st.Service_Type_Flage AS Service_Type_Id, b.Service_Item_Code, b.Royalty_Rate, Created_By, Created_Name
 ,Is_Audited,Audit_Man, Responsible_Person, Customer_Job_No, Operators, Operators_Uid,Responsible_Person_Id
 FROM         dbo.Order_Shipping b INNER JOIN Service_Type st ON st.Service_Type_Flage=4 WHERE is_del = 0)    
/*以上为订舱*/ UNION ALL
(SELECT b.Order_Id, b.Order_Trailer_Id AS Order_Service_Id, st.[Service_Name] AS Service_Type_Name
 , st.Service_Type_Flage AS Service_Type_Id, b.Service_Item_Code, b.Royalty_Rate, Created_By,Created_Name
 , Is_Audited,b.Audit_Man, Responsible_Person, Customer_Job_No, Operators, Operators_Uid,Responsible_Person_Id
FROM dbo.Order_Trailer b INNER JOIN Service_Type st ON st.Service_Type_Flage = 2 WHERE Is_Del = 0)
/*以上为拖车*/ UNION ALL  
(SELECT Order_Id, Order_Express_Id AS Order_Service_Id, st.[Service_Name] AS Service_Type_Name
 , st.Service_Type_Flage AS Service_Type_Id, Service_Item_Code, Royalty_Rate, Created_By, Created_Name
 , Is_Audited,'',Responsible_Person, Customer_Job_No, Operators, Operators_Uid,Responsible_Person_Id
 FROM dbo.Order_Express INNER JOIN Service_Type st ON st.Service_Type_Flage = 512 WHERE is_del = 0)    
 /*以上为快递*/
) t INNER JOIN V_Order o ON t .Order_Id = o.Order_Id LEFT JOIN   
Service_Item si ON si.Service_Item_Code = t .Service_Item_Code
GO

posted @ 2011-09-10 10:14  轩辕法王  阅读(5336)  评论(56编辑  收藏  举报