SQL Server Performance

Convert timestamp to varchar

Discussion in 'General Developer Questions' started by vpoirier, Jan 14, 2005.

  1. vpoirier New Member

    SQL Server 2000 sp3a
    I need to convert a timestamp value to a varchar.

    I need to build a string will look like this :

    DECLARE @String varchar(8000)

    SELECT @String = 'INSERT INTO Table2 SELECT * FROM Table1 WHERE timestamp >= ' + @TimeStampVal

    EXEC (@String)

    Since it is possible in Query Analyser to see the actual value
    of a timestamp I figure it is possible to use it in a string one way or another.

    It is impossible to do that though : CONVERT(varchar(50), @@DBTS)

    Anyone have a clue on this one ?
  2. chopeen Member

    @@DBTS returns a varbinary value.

    But, anyway, I cannot convert it to varchar. I'm puzzled.


    Marek 'chopeen' Grzenkowicz

    Rediscover the web
  3. thomas New Member

    No, me neither, I can't convert a timestamp column to varchar. But I can convert it to datetime and I can select it directly. Even though BOL says an explicit convert to varchar for timestamp is meant to work...

    So .. sorry.. I don't know.

    Tom Pullen
    DBA, Oxfam GB
  4. Luis Martin Moderator

    The best I can find is something like:

    select convert(varchar(255),convert(datetime,timestamp)) from exampletable

    But I can't understand why BOL said one thing and does not work.

    Luis Martin

    All postings are provided “AS IS” with no warranties for accuracy.

  5. vpoirier New Member

    I tried this solution :

    select convert(varchar(255),convert(datetime,timestamp)) from exampletable

    It doesn't work for me, I have this error :
    Arithmetic overflow error converting expression to data type datetime.

    Anything else ?

Share This Page