Home > DeveloperSection > Interviews > What is the difference between SET and SELECT?

Posted on    March-15-2014 7:14 AM

 MSSQL Server MSSQL Server 
Ratings:
 1 Answer(s)
  1085  View(s)
Rate this:

Sumit Kesarwani

Total Post:782

Points:3910
Posted on    March-15-2014 12:00 AM

 Both SET and SELECT can be used to assign values to variables. It is recommended that SET @local_variable be used for variable assignment rather than SELECT @local_variable.

Examples

declare @i int

set @i=1

This is used to assign constant values.

select @i=max(column_name)from table_name

for ex.

select @i=max(emp_id) from table_emp.


Don't want to miss updates? Please click the below button!

Follow MindStick