Hi all,
Using SQL Server 2000 and a stored procedure. I need to join some tables together in a way I can't seem to do.
Table SAMASTER is a stock code master, and contains the stock_code and 15 price fields called PRICE1, PRICE2, etc.
Table SABATCH is a detail table to SAMASTER, and contains a field called PRICE_CODE. This field will be contain 1 to 15, and obviously refers to which PRICE field in SAMASTER is relevant to each record in SABATCH.
But how do I show the correct price in my SQL? I only want a single column called PRICE in my output, and for it to show the correct price for each record in SABATCH.
Should I have 15 IF..THENs or somesuch to make up the formula for the PRICE column? Doesn't seem very elegant. I tried doing a ('PRICE'+[PRICE_CODE]) AS PRICE sort of thing, but that just shows PRICE1 or PRICE2, etc as the values in that column.
Thanks for your replies!
Using SQL Server 2000 and a stored procedure. I need to join some tables together in a way I can't seem to do.
Table SAMASTER is a stock code master, and contains the stock_code and 15 price fields called PRICE1, PRICE2, etc.
Table SABATCH is a detail table to SAMASTER, and contains a field called PRICE_CODE. This field will be contain 1 to 15, and obviously refers to which PRICE field in SAMASTER is relevant to each record in SABATCH.
But how do I show the correct price in my SQL? I only want a single column called PRICE in my output, and for it to show the correct price for each record in SABATCH.
Should I have 15 IF..THENs or somesuch to make up the formula for the PRICE column? Doesn't seem very elegant. I tried doing a ('PRICE'+[PRICE_CODE]) AS PRICE sort of thing, but that just shows PRICE1 or PRICE2, etc as the values in that column.
Thanks for your replies!