Insert violates key only in stored proc, not in query window

  • Hi all,

    I'm rather confused and hope you can help. I have a stored procedure that inserts records in several tables. Some of them it then updates, but that appears to be irrelevant to my issue. So I run the stored procedure and it inserts the records and all appears fine. Then, just for kicks, I run it again. I expect to see 0 records affected since I'm using the exact same source data. Instead I get an error saying that it can't run the insert because it violates the primary key constraint.

    In an effort to figure the issue out I cut and paste the insert statement into a query window and run it. 0 rows affected (which is what I expected to happen in the proc). Very weird, I'm thinking. I guess what I really don't understand is why would the same statement act differently if it's in a proc than if it's in a query window?

    Thanks in advance for any help you can give.

  • It would be really helpful to see the proc itself than guessing from what you described.

    Based on your description: it's unlikely to happen...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • We just figured it out... well, the database ninja here in the office did. Turns out in the sproc the @StoreID is a varchar(50). When I was setting up the @storeID in the query window I just defined it as a varchar... no length. So apparently it was only reading the first character of my store number. So instead of pulling together information from store 1102 it was pulling info for store 1.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply