I am trying to select a column named "YEAR" from a table.
I can achieve this using the following:
SELECT * FROM OPENQUERY (mybook, 'SELECT mytable.year FROM mytable')
but not when I use this:
SELECT * FROM OPENQUERY (mybook, 'SELECT year FROM mytable')
Is this because "year" is some sort of reserved word or is there another reason?
In SQL Server, Year is a reserved word. So it will complain when you try to use it.
If you are using MySql, you can use back ticks (`) around year.
In SQL Server, you can use []'s around year, [year].
EDIT
After seeing your updated question, the following SQL should work:
SELECT * FROM OPENQUERY (mybook, 'SELECT [year] FROM mytable')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With