Home Forums SQL Server 7,2000 T-SQL Convert my syntax - Oracle SQL to MS SQL Server RE: Convert my syntax - Oracle SQL to MS SQL Server

  • thanks!

    Oracle merge inserts or updates the rows into the table2 (i.e. merge table) based on the equijoin condition (i.e. (B.f1 = A.f1))

    ------------------------------------------------------------ 

    I have 2 tables (more than 10 million rows each).

    table1 has 3 columns

    a - datatype - varchar, b - varchar, c - float

    there is no primary key or index

    there is data in column a,b & all the rows of column c have null value

    table2 has same 3 columns

    a - varchar, b - varchar, c - varchar

    there is no primary key or index

    there is data in column a,b,c...

    I have a simple procedure to put the c value of table2 into c value of table1.

    The procedure looks like this

    ------------------------------------------------------------

    create procedure my_procedure as

    begin

     declare @a nvarchar(255),@b nvarchar(255)

     declare @C nvarchar(255)

     declare c1 cursor dynamic

     for select a,b,c from table1

     open c1

     fetch next from c1 into @a,@b,@c

     while(@@fetch_status = 0)

     begin

      update table2

      set c = @C

      where a = @a and

      b = @b-2

      print @C

      print @a

      fetch next from c1 into @a,@b,@c

      if @@error <> 0

       print 'exception 1 ' + @@error 

     end

     close c1

     deallocate c1

    end

    ------------------------------------------------------------

    It takes arround 4 hrs to execute this procedure, is there a way to optimize this procedure code? (I dont have the rights to add keys to table or index..etc. only code changes) Its actually data transfer of column c from table1 to table2


    Regards,

    Srinidhi Rao