I tried looking this up but it's hard to explain.
I have a table full of items and I run a query on those items. They want the query to spit out not only the rows but also the missing items.
Make sense?
Example:
User does a select of these numbers: '3010','3013','4912'
My query looks like this:
select item_no, barcode, qty
from mytable
where item_no IN ('3010','3013','4912')
ORDER BY CHARINDEX(item_no,'3010,3013,4912')
This spews out to a .net datatable and into a .net DataView that the user downloads as a spreadsheet.
The reason for the CHARINDEX is to keep the numbers in the same sequence that they entered it.
This works.
But wait, it gets better. What if record 4912 is missing?
They want a print out like this:
3010 123456789012 16
3013 123456789012 5
4912 Missing (or blank data)
The 4912 is not in my table and I can't figure out how to get sql server to return it in the query. I've tried everything I can think of.
The query is part of a .NET program and I was going to open the datatable and insert them. Yuck.
The reason for this is so they have a spreadsheet that matches the one they have to sit side by side.
Any help would be great. I know this is a hack.
I have a table full of items and I run a query on those items. They want the query to spit out not only the rows but also the missing items.
Make sense?
Example:
User does a select of these numbers: '3010','3013','4912'
My query looks like this:
select item_no, barcode, qty
from mytable
where item_no IN ('3010','3013','4912')
ORDER BY CHARINDEX(item_no,'3010,3013,4912')
This spews out to a .net datatable and into a .net DataView that the user downloads as a spreadsheet.
The reason for the CHARINDEX is to keep the numbers in the same sequence that they entered it.
This works.
But wait, it gets better. What if record 4912 is missing?
They want a print out like this:
3010 123456789012 16
3013 123456789012 5
4912 Missing (or blank data)
The 4912 is not in my table and I can't figure out how to get sql server to return it in the query. I've tried everything I can think of.
The query is part of a .NET program and I was going to open the datatable and insert them. Yuck.
The reason for this is so they have a spreadsheet that matches the one they have to sit side by side.
Any help would be great. I know this is a hack.