I have the following query
SELECT * FROM invoice WHERE invoice_id IN (13, 15, 9, 27)
My result is:
invoice_id | invoice_number | ...
------------------------------------
9 | 201006003 |
13 | 201006020 |
15 | 201006022 |
27 | 201006035 |
which is the result set I want except that is ordered by the invoice_id (which is an autoincrement value).
Now I want the result in the order I specified in my query (13, 15, ...). Is there a way to achive that?
The background is that I have a DataTable bound to a DataGridView. The user can filter and sort the result but if he want's to print the result I don't use the DataTable for printing because it only contains the most important columns and instead I pull the whole records from the database and pass it to my printing control.
I also tried to extend the existing DataTable with the missing results but that seems to slower than using the IN (...) query.