Solved

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

Posted on 2008-10-30
7
2,413 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
Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL to copy a database 37 66
Related to SQL Query 5 21
Delete old Sharepoint backups 2 22
sql server major issue  need help 2 46
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

733 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