Reputation: 179
I am trying to update a column in my table which was last inserted. I tried creating this stored procedure:
CREATE PROCEDURE [dbo].[msp_AssociateEvent]
(
@EventId int
)
AS
UPDATE tblFoodMenus set
EventID = @EventId
Where FoodMenuID = IDENT_CURRENT(tblFoodMenus)
but it gives me this error:
Invalid column name tblFoodMenus
Am I using IDENT_CURRENT correctly?
P.S. FoodMenuID is the primary key of tblFoodMenus which is being auto incremented
Upvotes: 1
Views: 692
Reputation: 1912
Mark Brackett's comment is right on the money - ident_current is not safe to get you the particular identity generated that you are interested in. Almost always you would want to use scope_identity() in the code that does the insert and then pass that around wherever it is needed.
Upvotes: 1
Reputation: 300728
Table name needs to be in quotes
Where FoodMenuID = IDENT_CURRENT('tblFoodMenus')
Upvotes: 4