ALTER PROCEDURE [dbo].[PRPTINVDOCDETAILNGROUPING]
(
	@DocDateFrom VARCHAR(20)
	,@DocDateTo VARCHAR(20)
	,@DocStatus VARCHAR(20)
	,@DocNoFrom VARCHAR(20)
	,@DocType VARCHAR(20)
)
AS

--DECLARE @DocDateFrom VARCHAR(20) = ''
--DECLARE @DocDateTo VARCHAR(20) = ''
--DECLARE @DocStatus VARCHAR(20) = ''
--DECLARE @DocNoFrom VARCHAR(20) = '00000800'
--DECLARE @DocType VARCHAR(20) = 'GICU'

IF (@DocDateFrom <> '') BEGIN SET @DocDateFrom = @DocDateFrom END ELSE BEGIN SET @DocDateFrom = '19000101' END
IF (@DocDateTo <> '') BEGIN SET @DocDateTo = @DocDateTo END ELSE BEGIN SET @DocDateTo = '99991231' END

SELECT DISTINCT head.DocNo
FROM dbo.PTRMATERIALHEAD AS head
WHERE (head.DocType = @DocType OR @DocType = '')
	AND (head.DocDate >= @DocDateFrom AND head.DocDate <= @DocDateTo)
	AND (head.DocStatus = @DocStatus OR @DocStatus = '')
	AND (head.DocNo = @DocNoFrom OR @DocNoFrom = '')