Sql-server – MS SQL server set variable to where clause

oraclesql server

I am new in MS SQL server and oracle database
I have the following query:

 SELECT * from TBL1 where adc in ('21','24');

but I need something like this:

DECLARE @sqlq nvarchar(500)
    Set @sqlq = '21','23';--(how can I write this)
    SELECT* from OPENQUERY([CBSCSDB], 'SELECT * from TBL1 where adc in (@sqlq)');

problem is how can I set value @sqlq and put it in the select statement in where clause.

Best Answer

You can use table variables

DECLARE @sqlq TABLE
(
    adc VARCHAR(100)
)

INSERT INTO @sqlq VALUES (21);
INSERT INTO @sqlq VALUES (23);

SELECT * FROM TBL1 WHERE adc IN (SELECT adc FROM @sqlsq)