Question Column Named Timestamp

VentureFree

Well-known member
Joined
Jan 9, 2008
Messages
54
Programming Experience
5-10
I'm trying to create a DataSet in VB.net which accesses a table in a Sybase database. One of the columns is named Timestamp, and trying to select this column is causing problems due to it's being a reserved word...plus the fact that the datatype is a datetime and not a timestamp. Here's the base select statement:
VB.NET:
SELECT AgentLogin, FirstEventTimestamp, Timestamp, EventType
FROM dbo.eAgentLoginStat
This causes the following error:
Error in SELECT clause: expression near ','.
Missing FROM clause.
Unable to parse query text.
I verified that it's the Timestamp itself causing the problem by excluding it which resulted in the proper values being selected (i.e. AgentLogin, FirstEventTimestamp, and EventType). Coming from a Sql Server background, I tried [Timestamp] next, but that caused this error:
Error in SELECT clause: expression near '['.
Missing FROM clause.
Unable to parse query text.

I was told by someone to use quotes around it like "Timestamp", but this selects the literal string "Timestamp". Same thing using single quotes like 'Timestamp'. This doesn't cause any errors in the query itself, but of course it causes problems with anything expecting a datetime from this query.

Someone else told me to change the name of the column in the select by using Timestamp=ThisTimestamp or possibly ThisTimestamp=Timestamp (he wasn't sure which), but both of them cause similar errors.
-- When using Timestamp=ThisTimestamp
Error in SELECT clause: expression near '='.
Missing FROM clause.
Unable to parse query text.

-- When using ThisTimestamp=Timestamp
Error in SELECT clause: expression near '='.
Missing FROM clause.
Error in SELECT clause: expression near ','.
Unable to parse query text.
And again, coming from Sql Server I tried using Timestamp AS ThisTimestamp.
Error in SELECT clause: expression near 'AS'.
Missing FROM clause.
Unable to parse query text.

So how do I select that column given that it's a reserved word? Again, in case it's relevant I'll point out that this in the context of a DataSet in VB.net.
 

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,052
Programming Experience
10+
Try writing the query as SELECT * FROM table

-

Try surrounding the field with ` (to the left of number 1, above tab) marks
Note that ` is not '

-

Create a VIEW in the database that SELECTs the column AS a different name

CREATE VIEW diffname AS SELECT timestamp AS ts FROM table

Then link Visual Studio to the view instead

-

Create a stored procedure to return the data

-

Rename the column

-

Add another column and use a trigger to keep the data equal

-

Try a different database driver

-

The error text says "unable to parse query text" - this error is from Visual Studio, not Sybase. You can ignore it, create the parameters yourself and use the query regardless
 
Top Bottom