April 12, 2012

SET and SELECT - SQL Server Vs MySQL‏




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

mysql-sqlserver-set-select

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

select @a:=1, @b:=2;

The above command assigns values to the variables and also returns values assigned

OUTPUT

mysql-sqlserver-set-select


Did you like this post?
kick it on DotNetKicks.com
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Madhivanan,an MSc computer Science graduate from Chennai-India, works as a works as a Lead Subject Matter Expert at a company that simplifies BIG data. He started his career as a developer working with Visual Basic 6.0, SQL Server 2000 and Crystal Report 8. As years went by, he started working more on writing queries in SQL Server. He now has good level of knowledge in SQLServer, Oracle, MySQL and PostgreSQL as well. He is also one of the leading posters at www.sqlteam.com and a moderator at www.sql-server-performance.com. His T-sql blog is at http://beyondrelational.com/blogs/madhivanan

 
  Feedback:

comments

0 Responses to "SET and SELECT - SQL Server Vs MySQL‏"
 

Copyright © 2009-2014 All Rights Reserved for SQLServerCurry.com by Suprotim Agarwal | Terms and Conditions