Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Query on a table name that has spaces

Author  Topic 

drewsalem
Constraint Violating Yak Guru

304 Posts

Posted - 2005-12-05 : 07:12:58
Hi,

How do you query on a table that has spaces in its name?

Example:

Select Top 100 *
From dbo.Sales Detail

Cheers,

Drew

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-12-05 : 07:29:09
use.. enter the table name in the box brackets.. []

Select Top 100 *
From [dbo.Sales Detail]

Sucess Comes to those who Believe in Beauty of their Dream..
Go to Top of Page

drewsalem
Constraint Violating Yak Guru

304 Posts

Posted - 2005-12-05 : 07:37:24
I tried that and got

Msg 208, Level 16, State 1, Line 1
Invalid object name 'dbo.Sales Detail'.

The table is there in the right database. Queries are returned if the table has no space in its name.
Go to Top of Page

svicky9
Posting Yak Master

232 Posts

Posted - 2005-12-05 : 07:44:11
try this

select * from dbo.[sales detail]

cheers
Vic


Vicky
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-05 : 07:45:24
Select Top 100 *
From dbo.[Sales Detail]

You should avoid using spaces when naming the objects. Instead use underscore(_) like Sales_Detail to avoid unnecessary problems



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

drewsalem
Constraint Violating Yak Guru

304 Posts

Posted - 2005-12-05 : 07:53:36
Thanks Vicky

Thank you all.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-05 : 07:57:52
Hereafter, Better follow what I suggested
quote:
You should avoid using spaces when naming the objects. Instead use underscore(_) like Sales_Detail to avoid unnecessary problems


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

swatib
Posting Yak Master

173 Posts

Posted - 2005-12-08 : 06:38:08
I fully agreed with Madhivanan!! The naming conventions has to be followed to avoid future conflicts.....


Njoy Life
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-08 : 06:45:48
FYI
http://vyaskn.tripod.com/object_naming.htm

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -