Continuing my series on how same things can be done differently in SQL Server and MySQL, in this post, we will see the usage of SET and SELECT commands in SQL Server vs MySQL.
SET and SELECT commands can be used to assign values to the variables. But the usage is different in SQL Server and MySQL.
In SQL Server, SET can be used to assign a value to single variable only. SELECT command can be used to assign values to multiple variables.
Consider the following examples
Declare @a int, @b int
set @a=1
set @b=2
select @a,@b
The following will also work
Declare @a int, @b int
select @a=1,@b=2
select @a,@b
OUTPUT
In MySQL, declaration is not needed. Any number of variables can be assigned using a single SET command
set @a:=1, @b:=2;
select @a,@b
The SELECT command can be used to assign values and select the values too. The following is equal to the previous code
The above command assigns values to the variables and also returns values assigned
OUTPUT
No comments:
Post a Comment