I’m writing a stored proc in SQL Server 2008. The following code:
SELECT @LastAccessed = cs.LastAccessed
FROM [int].ClientSessions AS cs INNER JOIN
dbo.Profiles AS p ON cs.ProfileID = p.ProfileID
WITH (XLOCK, ROWLOCK)
WHERE (p.ClientID = @ClientID)
…won’t compile, stating a syntax error at XLOCK.
If I remove the INNER JOIN statement (which is impossible because I need the join), then it’s fine with the XLOCK. I don’t see what the issue is.
Note: I only want to lock the [int].ClientSessions table, so I realize this may not be the best approach.
You have to put the
WITH (XLOCK, ROWLOCK)after theas cs/as pstatement.Something like
Have a look at Table Hints (Transact-SQL)