Updating sql proceedure

"I need to figure out how to run a query and get a recordset row.

With the data from that recordset I need to create create a new row changing the primary key.

If you want table names or column names or an entire WHERE clause in your variable it gets more complicated. The second step is to update the existing record with the new status value.

Now we have the primary key of the record we wish to update and the new status value. We'll use an INSERT/SELECT statement that looks like this:: Notice that we didn't need to insert a value for PKValue since it's an identity column.

I used my parameter in the WHERE clause to indicate which record I wanted.

Let's assume your table looks like this: I'll need to pass two parameters to our stored procedure.

The first is the old primary key value and the second is the new status.

You can generally use a variable either side of the equal sign in a WHERE clause.

I'm assuming that the PKValue field is an identity column so I don't need to supply it a new value.

Our create prodedure statement will look something like this: Notice that each parameter's data type is defined along with the parameters.

terrem43.ru

21 Comments

  1. Pingback:

  2. eric   •  

    We are continuing to build out our new website where we will have a complete library​ of our MSDS sheets.

  3. eric   •  

    To begin using this site for free, you will be asked to create a profile with information such as gender, birthdate, first name, email and a password.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>