Table of ContentsPreviousNext

Ispirer             Ispirer


Ispirer SQLWays Database Migration Software

Conversion of Variable Declarations from Microsoft SQL Server to MySQL

The DECLARE statement is used to declare variables in Microsoft SQL Server and allows declaring variables with different data types. The MySQL DECLARE statement allows declaring a list of variables with one data type only, which is specified at the end of the variable list.

Microsoft SQL Server local variable name (@var) is changed to MySQL local variable name with the only difference that symbol "@" (which in Microsoft SQL Server designates local variable) is changed to MySQL "v_". In MySQL symbol "@" is used to designate user variable. User variable means that variable is working during the whole connection to the database. In our case we must used local variable, which works only within procedure body.

SQLWays used "v_" before local variable name for discern between local variable and column name. For example:

TABLE 18. Example, where column has the same name as variable (with "v_"):
Microsoft SQL Server
MySQL
select col1 from test where c=@c 
select col1 from test where c=v_c 

TABLE 19. Example, where column has the same name as variable (without "v_"):
Microsoft SQL Server
MySQL
select col1 from test where c=@c 
select col1 from test where c=c 

SQLWays converts the Microsoft SQL Server DECLARE statement with a list of variables to a standalone DECLARE statement for each variable in MySQL

TABLE 20. Example of variable declaration conversion
Microsoft SQL Server
MySQL
Create procedure mssql_declare_mysql
As
Begin
DECLARE @x INTEGER, @y CHAR
end 
Create procedure mssql_declare_mysql( ) 
Begin
DECLARE v_x INT;
DECLARE v_y CHAR;
end ; 


Table of ContentsPreviousNext
Ispirer             Ispirer
Copyright © 1999-2015 Ispirer Systems Ltd. Ispirer and SQLWays are trademarks of Ispirer Systems Ltd. All other product names may be trademarks of the respective companies. All rights reserved.