Selecting rows with specific IDs
519348Jan 31 2007 — edited Jan 31 2007Hi all. I need help with the following problem.
I have some ID numbers and I have to select the rows which contain these ID numbers (ID is the primary key column in my table). For example my table might look like this:
ID ...(other columns)
1
2
5
7
..
How can I select the rows which have the specified ID numbers in "ID" column?
Are there any well-known solutions to my problem? I understand that it is simple to write a SELECT like this
select *
from MyTable
where ID in (2,5,7)
But the IDs are selected by the user and I cannot hardcode them into the SELECT statement. I can edit the text of the select statement (from my Delphi program) or try to use Dynamic SQL. But I'd like to know if there exists a better or just more common solution.
Thank you in advance.