SQL Server 2005 error: "Incorrect syntax near "-" "

Hello,

I have an application written in visual basic which connects to a SQL Server 2005
In DB of SQL Server I have many tables. Table names can contain chars like: "-",  "\",  ".", etc.
When I execute the instruction in visual basic

sTableName= "Table-3" ' or ""Table-3"" or "Table_1" or sTableName= """" + "Table_1" + """"   -> """" = 4 quates (2 for string identify and two for writing in string a quate chr(34)->"

strQuery = "create view Temp_View_For_Backup_001 as select * from " & sTableName
 db.ExecuteImmediate(strQuery, SQLDMO.SQLDMO_EXEC_TYPE.SQLDMOExec_Default)

  I obtain the error "[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'Table-3'

Please anyone help me to solve this problem!

Thanks you very much!

 

0
magtica17
4/14/2009 1:15:17 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

2 Replies
1066 Views

Similar Articles

[PageSpeed] 31

 when you have chars like: "-",  "\",  ".", etc. in Table name or column names use quadrat parentheses[].

[This is one table name] 


Regards,
Stefan Uzunov
0
Steelymar
4/14/2009 1:38:55 PM

 Thanks you very much!

0
magtica17
4/14/2009 2:20:16 PM
Reply: