Anybody knows the difference between the SET and SELECT statement while assigning variables
Quote:
Originally Posted by sukeshchand
Hii,
Anybody knows the difference between the SET and SELECT statement while assigning variables
Hi
declare @.i int
set @.i=1
This s used to assign constant values
select @.i=max(column_name)from table_name
for ex.
select @.i=max(emp_id) from table_emp
This abve stmnt assign the max of the column value to the variable @.i|||
Quote:
Originally Posted by davash6
Hi
declare @.i int
set @.i=1
This s used to assign constant values
select @.i=max(column_name)from table_name
for ex.
select @.i=max(emp_id) from table_emp
This abve stmnt assign the max of the column value to the variable @.i
we can also use select statement to assign constants like
Select @.i=1 from tableEmp|||We can assign more than one value by using Select Statement but in SET we cant
Eg:
Select @.i=Mark1, @.j=Mark2 from Marks where SID=12323
but if we use SET statement We must write two different statement to do that
like
SET @.i=Select Mark1 From Marks where SID=12323
SET @.j=Select Mark2 From Marks where SID=12323
so i think the select statement is fast in this case
anybody have any other comments??? then pls post...|||SELECT:
Just selects data from a table, and does not change the values in the actual table.
so you see a view of the data.
select * from table1
see all data is table1
select * from table1
order by col01
see all data in table1 with the data ordered by col01.
so your view is different to the actual table but the table is unchanged.
SET:
this is used to change values in tables etc.
example 1:
update table1
set col01 = '23' where col01 = '21'
So set all instances of col01 to value '23' where it currently = '21'
example 2:
declare @.variable as int
set @.variable = '123'
create a variable called @.variable and store value '123' in it.
No comments:
Post a Comment