Variables in SQL Server must be affirmed first and then assigned values:
The local variables are identified with one @ and the global variables with two @ (common global variables are usually defined );
Declare the local variable Syntax: declare @ variable name data type; for example, declare @ num int;
Value assignment: There are two methods (@ num is the variable name and value is the value)
Set @ num = value; or select @ num = value;
If you want to obtain a field value in the query statement, you can use select to assign values to the variable, as shown below:
Select @ num = field name from table name where ......
MySQL variables do not need to be stated beforehand. You can simply use "@ variable name" when using them.
First usage: Set @ num = 1; or set @ num: = 1; // use the variable to save the data. Use the @ num variable directly.
Second usage: Select @ num: = 1; or select @ num: = field name from table name where ......
Note that the above two values can be set with "=" or ": =", but ": =" must be used for select"