I am trying to set variable but I get Incorrect syntax near '='.
.
DECLARE @name NVARCHAR(100) = 'Some name'
DECLARE @id INT
EXECUTE ('SET ' + @id + ' = (SELECT mm.mmID FROM dbo.measurem AS mm
WHERE mm.placeName = ''' + @name + ''')')
PRINT @id
If I try like this:
SET @id= (SELECT mm.mmID FROM dbo.measurem AS mm
WHERE mm.placeName = @name)
I get must declare variable @name
although I have it as my input store procedure param.
For declaring variable, you can go through Declaring Variable in mysql However you need to do something like this to make it run <>db-fiddle
SELECT @my_name := 'Some name';
SELECT @id;
SET @s = CONCAT (
'Select mm.mmID into @id From measurem as mm where
mm.placeName='
,''''
,@my_name
,''''
);
PREPARE stmt
FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT @id;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.