I have to pull a list of data from an Excel sheet which has a point in the column header. If I remove the point everything works perfectly, but if I keep the point then I get an error message.
Working: SELECT DISTINCT Ty FROM dbStock
Not working: SELECT DISTINCT Ty. FROM dbStock
System.Data.OleDb.OleDbException (0x80040E14): Syntax error (missing operator) in query expression 'Ty.'.
I searched on the internet, but couldn't find anything about this.
I tried to place Ty.
between ''
, ""
and []
, but no luck.
Any idea?
The solution was to try a SELECT * FROM ...
. This brought up, that the column's name was translated to Ty#
. The OP could continue with this name...
From this
Working: SELECT DISTINCT Ty FROM dbStock
Not working: SELECT DISTINCT Ty. FROM dbStock
I take, that the column's name is Ty
actually. The point let's the engine think, that this is a multipart qualifier (like tablename.columnname
).
You might use
SELECT DISTINCT Ty AS [Ty.] FROM dbStock
If you need the point in the output column name...
SQL-Server can deal with this...
declare @tbl TABLE([Ty.] INT);
INSERT INTO @tbl VALUES(1),(2),(3);
SELECT * FROM @tbl
SELECT [Ty.] FROM @tbl
You can use
SELECT DISTINCT [Ty.]
OR
SELECT DISTINCT "Ty." // In this case, check if QUOTED_IDENTIFIER is set to ON.
User contributions licensed under CC BY-SA 3.0