I’m not sure if I’m wording what I’m looking for correctly as none of my searches have given me an answer remotely close to what I’m asking.
I’m creating a stored procedure in SQL Server Management Studio where I’m searching the table for a specific row depending upon a user’s MS ID. The request is being sent from a form within a web app where a user has updated their information and the stored procedure searches for the record to perform the update. Here’s what I’ve got:
BEGIN
SELECT * FROM [MY_USER_TABLE] WHERE MSID = @MSID
IF (@FName != FName)
UPDATE [MY_USER_TABLE]
SET FName = @FName
END
IF (@LName != LName)
UPDATE [MY_USER_TABLE]
SET LName = @LName
END
IF (@MSID != MSID)
UPDATE [MY_USER_TABLE]
SET MSID = @MSID
END
...
[several other similar IF statement rows]
...
END
The issue I’m having is I’m getting an error saying “Invalid column name” in the IF statements:
IF (@FName != FName)
But, the column name seems fine when I set it to the parameter:
SET FName = @FName
Is there a reason why my query doesn’t recognize the column name when comparing it to the parameter? Is there a better way to compare parameter values to column field values to see if they differ and need to be updated?