Solved

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

Posted on 2008-10-30
7
2,308 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Suggested Solutions

Title # Comments Views Activity
System Center 2016 SQL Srv 1 24
Query Peformance + mulitple query plans 9 47
Add '#' to end of file 2 29
SQL Query Syntax Join 4 32
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

911 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

16 Experts available now in Live!

Get 1:1 Help Now