Now I have a long query and I’d like to alternate with such a statement
where userid=@userid
But I have other parameters which change flow, so, I want to have two options, selecting one user or any user
Can I send a username so that It can select and user? like we do in LIKE statements, we send
where username LIKE "%%"
and we get all records, how can I do that with INT?
Because my query is parameterized, I can’t add “OR 1=1” like
where userid=1 or 1=1
should I use BETWEEN and get two parameters, so when I select one record, I’ll enter userid-1 and userid+1 as two paramters, and get one user, and when I wand to select all, I’ll enter 1 and 1 million.
Is it a logical way for parameterized queries or is there another way, with one parameter?
SOLUTION

Typically this is done using
Another variation (if the userid column is not nullable):
Yet another (for ints) is to say
But if you have a lot of these conditions and every time the query is run the parameters change, you could be locking yourself into bad plans that aren’t always appropriate. So sometimes the answer is to generate dynamic SQL:
Couple this with
OPTION RECOMPILEand/or the instance setting “optimize for ad hoc workloads” you’ll only stuff up the plan cache with plans for versions of the query that are executed more than once.