I want to store the one table data row 'Id' into variable and I used the SELECT statement for that in stored procedure.
EX:
SET @IRid := 1;
SET @iCID := 0;
SELECT @iCID := Id FROM tbl_custidData WHERE RID = @IRid;
The Id value is storing successfully into the @iCID
Here My question is, can I use SET command instead of SELECT statement to store the one table id value into variable ?
I tried this way but not working ( directly assigning the value into variable )
SET @IRid := 1;
SET @iCID := 0;
SET @iCID := Id FROM tbl_custidData WHERE RID = @IRid;
And also I tried like this (declaring the variable and assigning the value) :
DECLARE IRid,iCID INT;
SET IRid =1;
SET iCID = 0;
SET iCID := Id FROM tbl_custidData WHERE RID = IRid;
The above two ways are not working
Is there any possibility in MySQL for the use of SET command to assign the table id value, like how I used the SELECT statement.
I'm new to MYSQL .
Give me your best solution for my further good steps.
CodePudding user response:
If you want SET and only it then
SET @iCID := (SELECT Id FROM tbl_custidData WHERE RID = @IRid LIMIT 1);
But SELECT Id INTO @iCID FROM tbl_custidData WHERE RID = @IRid LIMIT 1
may be more useful...