This is my SQL Server stored procedure
CREATE PROC test_sp
@id int,
@ipVal varchar(20) = null,
@browserName varchar(20) = null
as
begin
select * from users where id=@id order by id desc;
end
I want to change my where
condition in this dynamically.
When @ipVal is not null
, I should pass all the three parameters in Where condition. When my @ipVal is null
, then I should pass only id=@id
in where condition.
How to do this in SQL Server stored procedure?