dbTalk Databases Forums  

Basic advice required

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Basic advice required in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
lk
 
Posts: n/a

Default Basic advice required - 06-26-2010 , 06:18 AM






Hi all

I'm using SQL Server 2005 express and the adventureworks sample database to
try and refresh my memory with SQL Server (It's been about 5 years since I
last used it a lot). Can anyone help with a basic question...?

I've written two queries now - one works - one doesn't and I'm not sure why.

The syntax in both is identical (select * from HumanResources.Shift) but one
gives me an "invalid syntax near ." but the other works fine. The only
difference in how I've written them is the one that worked I wrote by right
clkicking on the adventureworks icon on the object explorer. The other one
I just did "File, New, Query with Current Connection".

Must be something fundamental I'm doing wrong. Can anyone help?

Cheers
Rob

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Basic advice required - 06-26-2010 , 06:38 AM






lk (gofyself (AT) wrong (DOT) address.com) writes:
Quote:
I'm using SQL Server 2005 express and the adventureworks sample database
to try and refresh my memory with SQL Server (It's been about 5 years
since I last used it a lot). Can anyone help with a basic
question...?

I've written two queries now - one works - one doesn't and I'm not sure
why.

The syntax in both is identical (select * from HumanResources.Shift) but
one gives me an "invalid syntax near ." but the other works fine. The
only difference in how I've written them is the one that worked I wrote
by right clkicking on the adventureworks icon on the object explorer.
The other one I just did "File, New, Query with Current Connection".

Must be something fundamental I'm doing wrong.
Copy and paste both queries in a reply to this post.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
  #3  
Old   
lk
 
Posts: n/a

Default Re: Basic advice required - 06-26-2010 , 10:05 AM



"Erland Sommarskog" <esquel (AT) sommarskog (DOT) se> wrote


Quote:
Copy and paste both queries in a reply to this post.


select *
from HumanResources.Shift

Reply With Quote
  #4  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Basic advice required - 06-26-2010 , 11:00 AM



lk (gofyself (AT) wrong (DOT) address.com) writes:
Quote:
"Erland Sommarskog" <esquel (AT) sommarskog (DOT) se> wrote in message
news:Xns9DA38092825DEYazorman (AT) 127 (DOT) 0.0.1...

Copy and paste both queries in a reply to this post.



select *
from HumanResources.Shift
So this was the query that compiled. At least in runs on my machine.

I think the query with the syntax error is more interesting. Verify
that it gives any error before you post.



--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
  #5  
Old   
lk
 
Posts: n/a

Default Re: Basic advice required - 06-27-2010 , 05:59 AM



"Erland Sommarskog" <esquel (AT) sommarskog (DOT) se> wrote

Quote:
lk (gofyself (AT) wrong (DOT) address.com) writes:
"Erland Sommarskog" <esquel (AT) sommarskog (DOT) se> wrote in message
news:Xns9DA38092825DEYazorman (AT) 127 (DOT) 0.0.1...

Copy and paste both queries in a reply to this post.



select *
from HumanResources.Shift

So this was the query that compiled. At least in runs on my machine.

I think the query with the syntax error is more interesting. Verify
that it gives any error before you post.

No - you misunderstand.

I have tried the query above twice in two separate windows - one works, one
doesn't.

It's as if one window is connected to the db and one isn't - but I don't
know how to establish the connection.
Therefore I had already verified that it gave me an error (invalid object)
before I posted.

Reply With Quote
  #6  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Basic advice required - 06-27-2010 , 10:56 AM



lk (gofyself (AT) wrong (DOT) address.com) writes:
Quote:
Therefore I had already verified that it gave me an error (invalid object)
before I posted.
In your original post you said that the error was "invalid syntax near .".
There are situations when you can get syntax error in one database, but
not another, when the databases has different compatibility settings. But
I could not see that your query could have this effect.

Now you present a different error message: "invalid object", which casts
the problem in an entirely different light. You are simply running the
query from the wrong database. In the toolbar in Mmgt Studio there is a
dropdown where you can select which to database to work from. You can
also change the current database with the USE command:

USE AdventureWorks
go

In the future, make the habit to always post error messages in verbatim.
Thereby you can avoid this kind of confusion.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.