Not sure if I phrased that right to display my intention but, I have the following TSQL query:
SELECT *
FROM Table
WHERE Amount_USD >= @init AND Amount_USD < @init2
@init is equal to the base searched value, and @init2 is equal to the base value plus 1. A juxtaposition of this code is made to read negative values if they are available. (Through if else)
This is intended to get all the decimal values of a given value, including that value. This is going to be part of a long chain of where criteria's, searching the date, searching the ID, and searching all decimal values of a given value as above. Problem is, this only works for one input, I intend on making it work for multiple entered values.
Now, what I'm having trouble with is how to word it if I wish to create an IN (list) version of this query so that I can search multiple decimal values of any given value.
Ex: Search amount of 100 120 130. Program picks up the following values from the backend: 100.12, 120.14, 100.99, 130, 130.544 / Etc.
I believe it can be done with the OR function though, like so:
SELECT *
FROM Table
WHERE (Amount_USD >= @init AND Amount_USD < @init2)
OR (Amount_USD >= @init3 AND Amount_USD < @init4)
OR (Amount_USD >= @init5 AND Amount_USD < @init6)
As you can see above, I come across the problem wherein I create these parameters from nothing which I would like to avoid, therefore an IN might be preferable... now that I think about it, the parameters might always be a problem... is there a solution to this?
For example, I define my parameters like so:
da.SelectCommand.Parameters.AddWithValue("@init", init);
da.SelectCommand.Parameters.AddWithValue("@init2", init2);
Say, the input value count increases to 4, or 9. I don't know how to scale this.
Edit: I forgot to mention that this is written in Tsql, interfacing an access database through a windows form. As such, many sql specific functions or methods may not work in my case.
Edit2: Posted the wrong SQL query above, should be correct now...