Solved

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

Posted on 2008-10-30
7
2,279 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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 14

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now