I have the following query:
select *
from cars
where make in ('BMW', 'Toyota', 'Nissan')
What I want to do is store the where parameters in a SQL variable.
Something like:
declare @caroptions varchar(max);
select @caroptions = select distinct(make) from carsforsale;
print @caroptions;
select * from cars where make in (@caroptions)
Problem is the print of @caroptions
only has the last result returned from:
select distinct(make) from carsforsale;
I want it to store multiple values.
Any ideas?