How to use IN Operator in SQL Server
Here Is the table Structure
Create Table Sample(Id INT,Name Varchar(50))
While I am the Query like this I can get the Value
Select * FROM Sample WHERE Id IN ('74','77','79','80')
While I am executing the above Query I can't able to get the Records Related to that table getting error executing this error.
DECLARE @s VARCHAR(MAX)
SET @s='74','77','79','80'
Select * FROM Sample WHERE Id IN (@s)
You are using wrong way
use the following way
DECLARE @s VARCHAR(MAX)
DECLARE @d VARCHAR(MAX)
SET @s='74 , 77 , 79 , 80'
set @d = 'select * from arinvoice where arinvoiceid in('+@s+')'
exec (@d)
here IN operator use integers collection not string collection..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With