SQL Query Syntax Error - Spaces in Field Names

前端 未结 5 647
囚心锁ツ
囚心锁ツ 2021-02-08 13:49

The database my application uses has field names containing spaces. I believe this to be the cause of my problem. Here is a typical query:

SELECT * FROM \'OV2          


        
5条回答
  •  花落未央
    2021-02-08 14:04

    You don't specify which DBMS you're using, but I'm guessing SQL server, so

    SELECT *
    FROM [OV2 BAS] AS bas
         ^^^^^^^^^
    

    ... enclose the field name in brackets. Using quotes as you are, turns the field name into a plain string, which will NOT be treated as a fieldname by SQL server.

提交回复
热议问题