I have the parameter @user_id. I want all records if the parameter has a NULL value. I only want records that match the parameter if the parameter is not null. Because the parameter can be null, I have to cast it to a varchar before I send it into the UPPER function in MSSQL
Here's the test case:
create table test_user (user_id number);
desc test_user;
--Name Null? Type
--USER_ID NUMBER
insert into test_user values (1);
insert into test_user values (2);
select * from test_user where user_id like decode(null,null,'%',null);
--returns all records because @user_id is null
select * from test_user where user_id like decode(1,null,'%',1);
--returns only user_id 1
Bookmarks