Wednesday, March 7, 2012

ODBC Sql Server Query Error

Hi,

I'm attempting to use the SQLExecute function to make a query to a SQL Server DB through ODBC.

However, the column I am trying to retrieve is called "date". When I try and query, I get back the message, "S0022: Invalid column name 'date'".

I believe I'm getting the error because date is a sql keyword (however if I run the query directly through SQL Interactive, I do not get a problem).

If anyone knows how I can get around this problem, that would be very helpful, as it is not possible to change the column name.

Thanks in advance.
Khalid.I'd use brackets around the offending columns. Something like:SELECT [date] FROM naughtyTable-PatP|||Gave that a try -- gives the same error. Any other ideas?

Thanks,
Khalid.|||try it with doublequotes

select "date" from naughtyTable|||you could also try functionizing it
select dateadd(d,0,[date]) as mydate from naughtyTable|||That will just return "date" for every row.

Post your query.

I have a sneaky suspicion something else is going on here like maybe the column does not exist or there is some imprperly formatted inline SQL.

Otherwise what Pat said should have worked.|||That will just return "date" for every row.wrong

you may try it for yourself --create table datetest
( id tinyint not null primary key
, date datetime
)

insert into datetest (id, date) values ( 1, getdate() )
insert into datetest (id, [date]) values ( 2, '11/11/2005' )
insert into datetest (id, "date") values ( 3, '2005-01-19' )

select id, "date" from datetestwant to know what this produces?

1 2005-01-18 15:32:29.163
2 2005-11-11 00:00:00.000
3 2005-01-19 00:00:00.000|||Alright you win this round Batman.

I was thinking about single qoutes which would spit out Date for every row. I have to stop posting at this during the day. I start getting a little flitty.

No comments:

Post a Comment