/****** Object:  View [dbo].[ViwAccPersonInfo]    Script Date: 8/5/2024 02:59:52 ب.ظ ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


ALTER VIEW [dbo].[ViwAccPersonInfo]
AS
SELECT        dbo.AccPersonInfo.ID, dbo.AccPersonInfo.Address, RTRIM(dbo.AccPersonInfo.Tel1) AS Tel1, RTRIM(dbo.AccPersonInfo.Tel2) AS Tel2, RTRIM(dbo.AccPersonInfo.Mobile) AS Mobile, RTRIM(dbo.AccPersonInfo.Fax) AS Fax, 
                         RTRIM(dbo.AccPersonInfo.Email) AS Email, dbo.AccPersonInfo.Description, dbo.AccPersonInfo.FinancialCode, 
                         CASE dbo.AccPersonInfo.Type WHEN 0 THEN dbo.AccTotal.Title WHEN 1 THEN dbo.AccControl.Title ELSE dbo.AccDetail.Title END AS Title, 
                         CASE dbo.AccPersonInfo.Type WHEN 0 THEN dbo.AccTotal.Code WHEN 1 THEN dbo.AccControl.Code ELSE dbo.AccDetail.Code END AS AccCode, dbo.AccPersonInfo.Type, dbo.AccPersonInfo.AccID, dbo.AccPersonInfo.MaxCredit, 
                         dbo.AccPersonInfo.Updater, dbo.AccPersonInfo.UpdateDate, RTRIM(dbo.AccPersonInfo.Web) AS Web, RTRIM(dbo.AccPersonInfo.MelliID) AS MelliID, RTRIM(dbo.AccPersonInfo.Name) AS Name, RTRIM(dbo.AccPersonInfo.Code) 
                         AS Code, dbo.AccPersonInfo.Country, dbo.AccPersonInfo.City, dbo.AccPersonInfo.InIran, dbo.AccPersonInfo.RealOrCompany, dbo.AccPersonInfo.CompanyType, dbo.AccPersonInfo.GroupType, dbo.AccPersonInfo.OtherGroupType, 
                         dbo.AccPersonInfo.VizitorTotalID, dbo.AccPersonInfo.VizitorControlID, dbo.AccPersonInfo.VizitorDetailID1, dbo.AccPersonInfo.VizitorDetailID2, RTRIM(dbo.AccPersonInfo.CodePosti) AS CodePosti, 
                         RTRIM(dbo.AccPersonInfo.CodeSabt) AS CodeSabt, dbo.AccPersonInfo.VizitorPercent, dbo.AccPersonInfo.DiscontPercent
FROM            dbo.AccPersonInfo LEFT OUTER JOIN
                         dbo.AccTotal ON dbo.AccPersonInfo.Type = 0 AND dbo.AccPersonInfo.AccID = dbo.AccTotal.ID LEFT OUTER JOIN
                         dbo.AccDetail ON dbo.AccPersonInfo.Type in (2,3) AND dbo.AccPersonInfo.AccID = dbo.AccDetail.ID LEFT OUTER JOIN
                         dbo.AccControl ON dbo.AccPersonInfo.Type = 1 AND dbo.AccPersonInfo.AccID = dbo.AccControl.ID
WHERE        (dbo.AccTotal.Type IN (2, 3)) OR
                         (dbo.AccDetail.Type IN (2, 3)) OR
                         (dbo.AccControl.Type IN (2, 3))
GO


