Solved

what is wrong with this sql statement using WITH (NOLOCK)

Posted on 2008-10-30
7
2,345 Views
Last Modified: 2010-04-21
What am I doing wrong to throw the error?
It works if i remove the alias "gbi" but I will want to use aliases on more complex/joined statements.  How can I get this to work without throwing an error in SQL Server?

SELECT     *
FROM         GBI_Stats WITH (NOLOCK) gbi

thanks!
0
Comment
Question by:RichardRiga
7 Comments
 
LVL 26

Accepted Solution

by:
tigin44 earned 500 total points
ID: 22845535
Hi RichardRiga,

you can chance the position of alias and the hint keyword.

SELECT *
FROM GBI_Stats gbi WITH (NOLOCK)

0
 
LVL 1

Author Comment

by:RichardRiga
ID: 22845579
i tried that, still get an error :(  "incorrect syntax from gbi"
0
 
LVL 1

Author Comment

by:RichardRiga
ID: 22845583
"near" gbi.  not from hehe
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22845787
That should work, guess you can try explicity typing the AS for alias, but syntax looks right to me but I do use SQL 2005 and not SQL 2000.  Didn't remember that mattering though as most of queries I have WITH (NOLOCK) on were used in SQL 2000 db before.

SELECT *
FROM GBI_Stats AS gbi WITH (NOLOCK)
0
 
LVL 15

Expert Comment

by:rob_farley
ID: 22847830
It should be fine. Do you have a space in your GBI_Stats name or something? I can't see one, but perhaps when you're writing it out you have one?

The alias should definitely come before the "WITH (NOLOCK)".

Rob

-- http://www.lobsterpot.com.au, http://msmvps.com/blogs/robfarley
0
 
LVL 1

Author Comment

by:RichardRiga
ID: 22850873
ok, points to Tig but thanks everyone, for responding.  Thing is I was testing the query in SQL Server Enterprise.  Apparently results are different if testing in the query analyzer.
0
 
LVL 1

Author Closing Comment

by:RichardRiga
ID: 31511863
thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question