Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Updating a record from a table and returning the updated record.

Updating a record from a table and returning the updated record.

Scheduled Pinned Locked Moved Database
databasequestionannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PeteConc
    wrote on last edited by
    #1

    Hello. I am making a stored procedure with the following SQL statement: Update Table1 set Field1='X' Where Field2 = 'N' I want the StoredProcedure to return Field3 from the updated record. Is it possible to do this? Thanks.

    D 1 Reply Last reply
    0
    • P PeteConc

      Hello. I am making a stored procedure with the following SQL statement: Update Table1 set Field1='X' Where Field2 = 'N' I want the StoredProcedure to return Field3 from the updated record. Is it possible to do this? Thanks.

      D Offline
      D Offline
      Daniel Santillanes
      wrote on last edited by
      #2

      sure right after your update, put the select statement select field3 from table1 where field2 = 'N' and execute your stored procedure with either cmd.ExecuteReader() / cmd.ExecuteScalar() daniero

      P 1 Reply Last reply
      0
      • D Daniel Santillanes

        sure right after your update, put the select statement select field3 from table1 where field2 = 'N' and execute your stored procedure with either cmd.ExecuteReader() / cmd.ExecuteScalar() daniero

        P Offline
        P Offline
        PeteConc
        wrote on last edited by
        #3

        Actually that's not exactly what I wanted. The example I gave was not complete. Here's what I want to do: - Select @Res = max(Y) From table1 where X=0 - Update table1 set X=1 where Y = @Res I want to get the max record where X=0 and then update that record. The problem is that there may be two processes executing this stored procedure at the same time. Thus, they may execute the 'select' part at the same time, get the same 'max(Y)' and then update the same record. That's what I wnat to avoid. I need to assure that between the 'select' and the 'update' there is no process accessing the same record in the table. This is a concurrency problem.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups