Insert Scope_Identity() value in to column

  • Hello,

    Small problem im sure but my SQL skills are limited, I have the following stored procedure and what im trying to do is when the user comes to one of my pages I call this SP to create a new record in the DB and return the ItemId, my problem is this table requires the ItemId on insert and as he hasn't been provided throws an error saying "Cannot insert null value in column "ItemId" which I understand because it hasn't been provided, is there a way that when I call this proc I can provide it on insert? I've tried using Scope_Identity() on the insert as displayed here but that doesn't seem to work either.

    INSERT INTO Advert.ItemInformation

    (ItemId, [UniqueId] ,[ParentCatId] ,[SubCatId] ,[ChildCatId] ,[Status] ,BelongsTo, StartDate)

    Values

    (SCOPE_IDENTITY(), NEWID(), @ParentCategoryId, @SubCategoryId, @ChildCategoryId, 3, @createdby, SYSDATETIME())

    set @ItemId = SCOPE_IDENTITY()

  • Please excuse this, I managed to get it resolved by making the ItemId the PK with Identity Increment.

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

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