1

I have a comma separated string variable v_combined_prodid . But i wants to convert comma separated string variable to comma separated int value or in loop where we can update one table with where clause prodid as int. we cant use FIND_IN_SET(prodid, v_combined_prodid )

we can use stored procedure.

DECLARE v_combined_prodid varchar(800);

set v_combined_prodid ='1,2,3,4,5';

below statement exactly requirement.

update mytable t set t.status=2
 WHERE prodid in (1,2,3,4,5)
 and t.status=0 ;
1
  • P Nayak, did the answer below help you? If so, you have the option of marking the answer as accepted. It's your choice. Marking your question with an accepted answer will give closure to your question. Commented Aug 11, 2021 at 18:24

1 Answer 1

0

You are better off creating a dynamic query and then execute it.

See Mysql dynamically build query string in a stored procedure based on logic for an example.

DECLARE v_combined_prodid varchar(800);

set v_combined_prodid ='1,2,3,4,5';

set @query = CONCAT(' update mytable t set t.status = 2 where prodid in ('
                    , v_combined_prodid
                    , ') and t.status = 0');

PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Sign up to request clarification or add additional context in comments.

Comments

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.