I am passing two parameters i.e @AccountId and @key. I want to show all the values present in the database for @AccountId and @key when there is no values in the parameters i.e @AccountId and @key. I want to do this for the same dataset. Is this possible or i have create different datasets?
The query which I am using is :
CREATE PROCEDURE [dbo].[GetDenyList]
@AccountId nvarchar(100),
@key nvarchar(400)
AS
select New_AccountId AS 'AccountId/Key', New_Description AS 'Reason',CreatedOn AS 'Date'
from abc.dbo.New_keydenylist
where New_AccountId is not null
AND @AccountId = New_AccountId
union all
select new_key AS 'AccountId/Key', New_Description AS 'Reason',CreatedOn AS 'Date'
from abc.dbo.New_keydenylist
where New_key is not null
and @Key=New_key
If I understand your question well, you have to use any predicate that always evaluate to true regardless to the parameters’ values passed to the
WHEREclause. For exampleWHERE 1 = 1:The same with
@keyparameter:If the two parameters
@keyand@AccountIdare bothNULLor one of them, then theWHEREclause still be valid and return all the row as it were not presented.