Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2007
    Posts
    27

    Question Unanswered: Column Named Timestamp (VB.net DataSet)

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

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    The obvious suggestion is just to rename the column to something that isn't a keyword and better describes the data be stored.

  3. #3
    Join Date
    Dec 2007
    Posts
    27
    Sorry it took so long to reply. I forgot I posted this so I hadn't followed up until now.

    Anyway I forgot to mention the fact that I don't have permissions to alter the table. That would have been the first thing I would have done were I able to.

    Thanks for the suggestion, though. You never know when someone overlooked the simple answer because they were concentrating too hard on the overall complexity of a problem.

    I may just go back to hard coding everything, at least for this particular set of data. All my other data sets work, and I guess I can live with a little bit of asymmetry.

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Maybe create a view on the table that uses different column names then select from the view.

    I am unable to test with vb.net but were unable to recreate the problem using isql on ASE 12.5
    Code:
    1> create table #t1 (Timestamp datetime)
    2> go
    1> insert into #t1 values ('20100407')
    2> go
    (1 row affected)
    1> select Timestamp from #t1
    2> go
     Timestamp                  
     -------------------------- 
            Apr  7 2010 12:00AM 
    
    (1 row affected)
    1> select [Timestamp]  from #t1
    2> go
     Timestamp                  
     -------------------------- 
            Apr  7 2010 12:00AM 
    
    (1 row affected)
    1> select ThisTimestamp=Timestamp from #t1
    2> go
     ThisTimestamp              
     -------------------------- 
            Apr  7 2010 12:00AM 
    
    (1 row affected)
    1> select Timestamp as ThisTimestamp from #t1
    2> go
     ThisTimestamp              
     -------------------------- 
            Apr  7 2010 12:00AM 
    
    (1 row affected)
    1> select "Timestamp" from #t1
    2> go
               
     --------- 
     Timestamp 
    
    (1 row affected)
    1> set quoted_identifier on
    2> go
    1> select "Timestamp" from #t1
    2> go
     Timestamp                  
     -------------------------- 
            Apr  7 2010 12:00AM 
    
    (1 row affected)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •