USE [AIS2025]
GO

/****** Object:  View [dbo].[ZZV_SalOrder]    Script Date: 2025/9/16 11:19:28 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


ALTER VIEW [dbo].[ZZV_SalOrder]
AS 

--SELECT *
--,CONVERT(DECIMAL(23,2),ISNULL((SELECT SUM(f.FAllAmount) FROM T_SAL_ORDERENTRY_F f WITH(NOLOCK) WHERE f.fid=a.fid AND f.FAllAmount>0),0.00)) ZhengShuHeJi
--FROM dbo.T_SAL_ORDER a WITH(NOLOCK)
--WHERE a.FDOCUMENTSTATUS='C'

SELECT *,
CASE WHEN EXISTS (
    SELECT 1 FROM T_SAL_ORDERENTRY_F f  
    WHERE f.fid = a.fid AND f.FAllAmount > 0
) THEN CONVERT(DECIMAL(23,2),
    (SELECT SUM(f.FAllAmount) FROM T_SAL_ORDERENTRY_F f  
     WHERE f.fid = a.fid AND f.FAllAmount > 0)
) ELSE 0.00 END AS ZhengShuHeJi
FROM dbo.T_SAL_ORDER a  
WHERE a.FDOCUMENTSTATUS = 'C'
GO


