IF (EXISTS (SELECT * FROM sys.objects WHERE name = 'usp_DH2_Query'))
    DROP PROCEDURE usp_DH2_Query
GO
CREATE PROCEDURE usp_DH2_Query
(
    @DHA001 NVarChar(100) = NULL
)
AS
BEGIN
/************************************************************************
程序说明：资料查询

    SELECT * FROM PURDHA

    usp_DH2_Query

************************************************************************/

    SET NOCOUNT ON
    DECLARE @SQL NVARCHAR(MAX)

    SET @SQL='SELECT A.* FROM PURDHA AS A WHERE 1=1 '
    IF ISNULL(@DHA001,'')<>'' SET @SQL=@SQL+'  AND A.DHA001='''+@DHA001+''''

    --PRINT(@SQL)
    EXEC(@SQL)
    SET NOCOUNT OFF
END
GO


IF (EXISTS (SELECT * FROM sys.objects WHERE name = 'usp_DH2_Delete'))
    DROP PROCEDURE usp_DH2_Delete
GO
CREATE PROCEDURE usp_DH2_Delete
(
    @DocNo NVarChar(MAX) --支持批量删除，多个单号用逗号分开
)
AS
BEGIN
/************************************************************************
程序说明：资料查询

    SELECT * FROM PURDHA
    SELECT * FROM PURDHB

    usp_DH2_Delete '00001' 

************************************************************************/
    SET NOCOUNT ON
    DELETE PURDHA WHERE [DHA001] IN (SELECT COL FROM dbo.ufn_Split(@DocNo,',',1))
    DELETE PURDHB WHERE [DHA001] IN (SELECT COL FROM dbo.ufn_Split(@DocNo,',',1))
    SET NOCOUNT OFF
END
GO

IF (EXISTS (SELECT * FROM sys.objects WHERE name = 'usp_DH2_GetDataByKey'))
    DROP PROCEDURE usp_DH2_GetDataByKey
GO
CREATE PROCEDURE usp_DH2_GetDataByKey
(
    @DocNo NVarChar(100)
)
AS

BEGIN
/************************************************************************
程序说明：资料查询

    SELECT * FROM PURDHA
    SELECT * FROM PURDHB

    usp_DH2_GetDataByKey '00001' 

************************************************************************/
    SET NOCOUNT ON
    SELECT A.* FROM [PURDHA] A WHERE [DHA001]=@DocNo
    SELECT A.* FROM [PURDHB] A WHERE [DHA001]=@DocNo
    SET NOCOUNT OFF
END
GO

