Solved

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

Posted on 2008-10-30
7
2,481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 60

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

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…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

707 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