/****** Object:  View [dbo].[ViwAccFactorDetail]    Script Date: 06/11/1404 04:17:26 ب.ظ ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

--SELECT * FROM [ViwAccFactorDetail]

ALTER VIEW [dbo].[ViwAccFactorDetail]
AS
SELECT   Main.ID, Main.FactorID, Main.Request, Main.NetPrice, Main.TotalPrice, 
                Main.RequestUnit, Main.UnitName, Main.OrderTitle, COALESCE (AccDetail2.Title, AccDetail1.Title, dbo.AccControl.Title, dbo.AccTotal.Title, '') AS OtherTitle, 
                Main.OrderTotalID, Main.OrderControlID, Main.OrderDetailID1, Main.OrderDetailID2, Main.DocItemID, 
                Main.DocHeaderID, Main.Status, Main.Selected, Main.UsedDocNumber, Main.DocNumber, 
                Main.OtherTotalID, Main.OtherControlID, Main.OtherDetailID1, Main.OtherDetailID2, Main.Value2, 
                Main.Unit2, Main.Unit2Name, Main.Discont, Main.Avarez, Main.Maliat, Main.Heigh, 
                Main.Lenght, Main.Width, Main.ZowjInUnit, Main.Pakaging, Main.Oft, 
                Main.WarehouseNo, Main.SumInFactor, Main.OrderID, Main.SayerVojoh, Main.Nw, 
                Main.Ssrv, Main.Sscv, coalesce(Main.Haml,0) as Haml, Main.HamlTotalID, Main.HamlControlID, 
                Main.HamlDetailID1, Main.HamlDetailID2
FROM      dbo.AccDetail AS AccDetail2 RIGHT OUTER JOIN
                dbo.ViwAccFactorDetailPhase2 AS Main ON AccDetail2.ID = Main.OtherDetailID2 LEFT OUTER JOIN
                dbo.AccDetail AS AccDetail1 WITH (NOLOCK) ON Main.OtherDetailID1 = AccDetail1.ID LEFT OUTER JOIN
                dbo.AccControl ON Main.OtherControlID = dbo.AccControl.ID LEFT OUTER JOIN
                dbo.AccTotal ON Main.OtherTotalID = dbo.AccTotal.ID
GO


