How do I compare list of integers with integer columns in sql server. For example I have a column statusid
as int
. I want to get the result where statusid
in 1,4,8,9
. I kept all these integers in string and operate with the column statusid as below but i am facing error there. This string may be hard coded or parameter.
where Cast(statusid as varchar) in ('1,4,8,9');
Please suggest the solution.
CAST Function to convert int to string In this example, we are converting the OrderQty which is an integer into varchar with SELECT CAST syntax.
In our demo, that is performed using three different data types conversions, it can be found that CAST is the fastest function that can be used to convert the data type of the provided value, and the PARSE function is the slowest.
since the number are converted to string, the values on IN
clause should each be wrap with single quotes
where Cast(statusid as varchar(20)) in ('1','4','8','9');
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