I am trying to update a row with SQL, but I want to be able to pass in a variable for the name of the column to update. Is this possible?
DECLARE @Place varchar(max)
SET @Place = '[MDinner]'
UPDATE [UserMealPlans] SET @Place = NULL WHERE [UserId] = 'ffc3a7ed-264f-4d75-ae4c-aabe900023b6'
this is my statement which says 1 row affected, but then the column is not set to null.
If I do this, it works fine:
UPDATE [UserMealPlans] SET [MDinner] = NULL WHERE [UserId] = 'ffc3a7ed-264f-4d75-ae4c-aabe900023b6'
Any thoughts on how to do about doing this correctly?
Thanks!
You need to use Dynamic SQL for this: