SELECT query in a table with a space in the name using SQSH

I am using SQSH (version 2.1) for Ubuntu 10.04 to connect to the MSSQL database using the following command:

sqsh -S server -U user -P password -D database 

I have a table called My Table, but I cannot find a way to run a SELECT query on it. This is what I have tried so far:

 SELECT * FROM 'My Table' go 

Exit: incorrect syntax next to "My table". (I get the same for double quotes)

 \set t="My Table" SELECT * FROM $t go 

Output: Invalid object name 'My'. (Which is strange, because if I do \ echo $ t, I get the full name of the table)

 SELECT * FROM My\\ Table go 

Output: The name of the invalid object 'My'.

 SELECT * FROM [My Table] go 

Output: Unicode data in Unicode or ntext mapping data cannot be sent to clients using a DB library (e.g. ISQL) or ODBC version 3.7 or earlier.

This last command works great for table names without spaces.

UPDATE: other commands work fine, for example. I can get a description of the table with:

 SELECT column_name,data_type FROM information_schema.columns WHERE table_name = 'My Table' go 
+7
source share
4 answers

Finally found a solution . I had to add the following 2 lines to /etc/freetds/freetds.conf

 tds version = 8.0 client charset = UTF-8 
+2
source

Putting the table name in quotation marks does not work in MS SQL Server.
The correct way: [ ] :

 SELECT * FROM [My Table] 
+8
source

Im using SQL 2008R2 and the following works for me

 ['table name'] 
+2
source

Try setting QUOTED_IDENTIFIER to ON when using SQL Server. For more information about QUOTED_IDENTIFIER, see: http://msdn.microsoft.com/en-us/library/ms174393.aspx

0
source

All Articles