Difference between SET and SELECT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukeshchand
    New Member
    • Jan 2007
    • 88

    Difference between SET and SELECT

    Hii,
    Anybody knows the difference between the SET and SELECT statement while assigning variables
  • davash6
    New Member
    • Oct 2007
    • 9

    #2
    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_n ame)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

    Comment

    • sukeshchand
      New Member
      • Jan 2007
      • 88

      #3
      Originally posted by davash6
      Hi

      declare @i int
      set @i=1
      This s used to assign constant values

      select @i=max(column_n ame)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

      Comment

      • sukeshchand
        New Member
        • Jan 2007
        • 88

        #4
        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....

        Comment

        • jamesd0142
          Contributor
          • Sep 2007
          • 471

          #5
          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.

          Comment

          Working...