0

I have the following script but it returns null all the time.

    SELECT 
    @PRICE_LARGE_PRICE = PRICE_LARGE_PRICE,
    @PRICE_SMALL_PRICE = PRICE_SMALL_PRICE
FROM
    prices
WHERE
    PRICE_LISTING_ID = 60;

SET @ITEM_PRICE = (CASE Size WHEN GivenLargeSizeName THEN @PRICE_LARGE_PRICE 
WHEN GivenSmallSizeName THEN @PRICE_SMALL_PRICE 
ELSE null 
END); 

The issue here is

@PRICE_LARGE_PRICE = PRICE_LARGE_PRICE,
@PRICE_SMALL_PRICE = PRICE_SMALL_PRICE

table returns PRICE_LARGE_PRICE & PRICE_SMALL_PRICE correctly but the assignment does not work. Hence CASE fails.

Any help is appreciated.

2 Answers 2

1

You need to use SELECT ... INTO:

SELECT PRICE_LARGE_PRICE, PRICE_SMALL_PRICE
INTO @PRICE_LARGE_PRICE, @PRICE_SMALL_PRICE
FROM prices
WHERE PRICE_LISTING_ID = 60;

Note that you need to ensure that the query only returns one row of data, using LIMIT 1 if necessary.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Yes, it always returns one record.listing I'd is primary key. I will check your code tommorow.
0
SELECT 
    @PRICE_LARGE_PRICE:=PRICE_LARGE_PRICE,
    @PRICE_SMALL_PRICE:=PRICE_SMALL_PRICE
FROM
    prices
WHERE
    PRICE_LISTING_ID = 60;

just add colon before equal sign in mysql

1 Comment

That's cute, I will try that too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.