I have a variable v_brand in a sql procedure. If that variable is not null then
select * from table where column1 = someValue and brandColumn = v_brand;
If the variable is null
select * from table where column1 = someValue;
Best I could come up with is
IF v_brand IS NOT NULL THEN
select * from table where column1 = someValue and brandColumn = v_brand;
ELSE
select * from table where column1 = someValue;
END IF:
The queries I will be using are hundreds of lines. Is there a way to combine both queries, as it seems more maintainable.