ALTER PROCEDURE [dbo].[PDSCMBSSALESDOCSTATUS] ( @DocType VARCHAR(20) ,@MenuID VARCHAR(250) ) AS --DECLARE @DocType VARCHAR(20) = '' --DECLARE @MenuID VARCHAR(250) = 'SALESINQDRAFT' IF(@MenuID = 'SALESINQDRAFT') BEGIN SELECT * FROM dbo.PCMBSSALESDOCSTATUS WHERE DocStatus IN ( '1','2') AND DocType = 'SINQ' END ELSE IF(@MenuID = 'SALESINQ') BEGIN SELECT * FROM dbo.PCMBSSALESDOCSTATUS WHERE DocType = 'SINQ' END ELSE IF(@MenuID = 'SALESORDERDRAFT') BEGIN SELECT * FROM dbo.PCMBSSALESDOCSTATUS WHERE DocStatus IN ('7','9','10') AND DocType = 'SORD'--WHERE DocStatus IN ('7','9') AND DocType = 'SORD' END ELSE IF(@MenuID = 'SALESORDER') BEGIN SELECT * FROM dbo.PCMBSSALESDOCSTATUS WHERE DocType = 'SORD' END ELSE IF(@MenuID = 'SALESQUOTADRAFT') BEGIN SELECT * FROM dbo.PCMBSSALESDOCSTATUS WHERE DocStatus IN ('4','6') AND DocType = 'SQUO' END ELSE IF(@MenuID = 'SALESQUOTA') BEGIN SELECT * FROM dbo.PCMBSSALESDOCSTATUS WHERE DocType = 'SQUO' END ELSE BEGIN SELECT DISTINCT * FROM dbo.PCMBSSALESDOCSTATUS END