/****** Object:  View [dbo].[ViwAccFactorDetail]    Script Date: 06/11/1404 01:39:32 ب.ظ ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

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


