I want to create a variable that holds a list of UPCs that we need to search over. Instead of using:
select * from foo
where upc in (3410015215, 3410015217, 3410015243)
I want to say something like:
Declare @UPCList Varchar(255) = (3410015215, 3410015217, 3410015243)
--If you want to check all stores, swap the commentation status of the next two lines
--Declare @Store int = NULL
Declare @Store int = 203
My second issue is, I want to search fleem for a specific store, but if someone wants to search all stores, then they should be able to make @Store equal to NULL .
select * from foo p
inner join fleem f on p.upc = f.upc_id
if (@Store is NULL)
begin
where f.BOH = 1
end
else (@Store is not NULL)
begin
where f.store = @Store AND f.BOH = 1
end
Are these things possible? If so, what is the best way to go about doing them?