I’ve just set up SQL Server 2008 SP2 on my workstation to run a local version of a database. The production database is SQL Server 2008 R2. A colleague is running SQL Server 2005 on his workstation.
My DB is throwing an error with the following code, while other instances of the same DB on the other servers run this query with no error.
WITH Posts AS (
SELECT TOP 10 *
FROM TBL_MSG_LATEST (NOLOCK)
WHERE TBL_MSG_LATEST.STATUS = 1
)
SELECT * FROM Posts (NOLOCK)
…throws this error:
Msg 215, Level 16, State 1, Line 6
Parameters supplied for object ‘Posts’ which is not a function. If the parameters are intended as a table hint, a WITH keyword is required.
Removing the (NOLOCK) after Posts makes my DB happy.
I’m not familiar with SQL Server, so I don’t totally understand CTEs but I believe that this NOLOCK might not even be necessary here.
However, we aren’t happy about making a change to the codebase just to satisfy my dev environment.
Is there a config difference with my newer DB environment? Is there a valid reason to remove the NOLOCK that I can’t decipher from the error message?
From this page: http://msdn.microsoft.com/en-us/library/ms187373.aspx
So this will work.
Don’t know if it is a good idea or not or if it has any effect.