GertDeWilde GertDeWilde - 7 months ago 26
SQL Question

Point in SQL statement

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?

Answer

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...

EDIT: Just to have mentioned it:

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