Results 1 to 4 of 4

Thread: Insert and Update in one storedprocedure

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Insert and Update in one storedprocedure

    I have a storedprocedure that I put the INsert and Update together in one store procedure. On my varaibles, I declared an @ID as integer

    But my ID in my db is Autoincremented, now my problem is that whenever I tried to insert something, it complains that the ID doesn't supply. But during the insert, I don't need to insert the ID because it's auto increment, but I need the ID for the Update... how do I do this?

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Insert and Update in one storedprocedure

    Always supply it in the SP check if > 0 then update if = 0 then Insert using an If condition on the @Id var pass the Id for the update or 0 for insert.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: Insert and Update in one storedprocedure

    Thank you, but now I am having a problem with other variables that I declared in that SP as well when I have a SELECT * FROM tbl

    It's asking me to provide those parameters like username, firstname, lastname, age, etc... how do I approach that?

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Insert and Update in one storedprocedure

    Please post your code and the stored procedure before we go futher. With out seeing what you are doing there is no way to actually help you out here.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width