Hi,
I am using Microsoft SQL Server 2005. I need help with a select statement. I think I may need to include the Case When or Coalesce functions, but I'm not sure. I need to query a table for only 3 fields: Product ID, Bin and VendID. However, each product can be in multiple bins and have a different vendors or no vendor for a particular bin. I want to look in two bins 35 & 49. If there is a vendor associated with bin 49 then I want the product, bin (49) and the vendor for bin 49. However, if there is no vendor on bin 49, I want to pull the vendor for bin 35. If no Vendor is in bin 49 nor 35, bin 49 should be in the result set with NULL for the vendID.
Here is an example
Product Bin VendID
1479 35 Acme
1479 49 Ross
2035 49 Null
2035 35 Carter
1738 35 Null
1738 49 Null
1738 57 Ross
Here are the results I would like when selecting Product, Bin & Vendor
Product Bin VendID
1479 49 Ross
2035 35 Carter
1738 49 Null
The select statement may go something like this, but it is bringing back a row for both bins.
SELECT ProductID, Bin, Vendor
FROM Invt
WHERE Bin in (49, 35)
Thank you in advance.
I am using Microsoft SQL Server 2005. I need help with a select statement. I think I may need to include the Case When or Coalesce functions, but I'm not sure. I need to query a table for only 3 fields: Product ID, Bin and VendID. However, each product can be in multiple bins and have a different vendors or no vendor for a particular bin. I want to look in two bins 35 & 49. If there is a vendor associated with bin 49 then I want the product, bin (49) and the vendor for bin 49. However, if there is no vendor on bin 49, I want to pull the vendor for bin 35. If no Vendor is in bin 49 nor 35, bin 49 should be in the result set with NULL for the vendID.
Here is an example
Product Bin VendID
1479 35 Acme
1479 49 Ross
2035 49 Null
2035 35 Carter
1738 35 Null
1738 49 Null
1738 57 Ross
Here are the results I would like when selecting Product, Bin & Vendor
Product Bin VendID
1479 49 Ross
2035 35 Carter
1738 49 Null
The select statement may go something like this, but it is bringing back a row for both bins.
SELECT ProductID, Bin, Vendor
FROM Invt
WHERE Bin in (49, 35)
Thank you in advance.