0

My problem is just set the result of a query into a variable. I can do it in String, but in Integer. Although I tried many different solutions it doesn't work.

Here is my code :

declare pos_t int(2);

set @pos_t = (Select range_position from LIST_PRODUCT where column1 = @variable1 and column2= @variable2 limit 1);

@pos_t returns always NULL

I tried Cast, convert, but it didn't work.

Nhung Phan
  • 41
  • 1
  • 5
  • Please add more functional (trail) code for testing purpose. – ZF007 Jan 01 '18 at 14:18
  • You can do such stuff only when inside a function, procedure, trigger or event – juergen d Jan 01 '18 at 14:31
  • I need to find pos_t value to insert in another table. Yes, my code is in a trigger – Nhung Phan Jan 01 '18 at 14:44
  • Hmm.. you aren't actually using your declared variable in your set statement ie @ pos_t looks incorrect try dropping the @ – P.Salmon Jan 01 '18 at 15:13
  • @ is needed for each variable in PHPMyAdmin – Nhung Phan Jan 01 '18 at 15:22
  • declared variables do not need to be qualified with @ in mysql I would be surprised if phpmyadmin insists upon it. I don't have phpmyadmin to check at the moment though. If it does then you need to be consistent with the names in your code. – P.Salmon Jan 01 '18 at 15:30
  • See https://stackoverflow.com/questions/11754781/how-to-declare-a-variable-in-mysql for discussion of variables in mysql. – P.Salmon Jan 01 '18 at 15:33
  • Hi P.Salmon, Thanks so much for your link, I changed my script and it works. I can now continue to do other tasks. – Nhung Phan Jan 01 '18 at 17:06

0 Answers0