views:

85

answers:

2

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?

PS FoodMenuID is the primary key of tblFoodMenus which is being auto incremented

+3  A: 

Table name needs to be in quotes

Where FoodMenuID = IDENT_CURRENT('tblFoodMenus')
Mitch Wheat
+1  A: 

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.