I have a table that is structured like this:
|ROWID |COUNTRY|PRICE|
|1 |US |15|
|1 |UK |10|
|1 |EU |12|
I need to select the values from multiple rows into variables for use throughout a stored procedure, doing something like this:
DECLARE @USprice int,@UKprice int
SELECT @USprice = T.Price FROM Table T WHERE T.Country = 'US'
SELECT @UKprice = T.Price FROM Table T WHERE T.Country = 'UK'
The question is what's the fastest way to run this select? In reality I need to get about a dozen rows so am concerned about performance.
Would it be better to do this:
DECLARE @USprice int,@UKprice int
SELECT @USprice = CASE WHEN T.Country = 'US' THEN T.Price ELSE @USprice END
,@UKprice = CASE WHEN T.Country = 'UK' THEN T.Price ELSE @UKprice END
FROM Table T WHERE T.Country IN ('US','UK')