0% found this document useful (0 votes)
36 views1 page

Convert Timestamp To Varchar

The document discusses converting a SQL Server timestamp value to a varchar in order to use it in a dynamic SQL string to filter records by timestamp. While it seems timestamps should be convertible to strings based on viewing their values in Query Analyzer, using CONVERT() directly on a timestamp fails. The suggested workaround is to first convert the timestamp to a datetime before converting to varchar, but the reason for the discrepancy with the documentation is unclear.

Uploaded by

Buggy Buggys
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views1 page

Convert Timestamp To Varchar

The document discusses converting a SQL Server timestamp value to a varchar in order to use it in a dynamic SQL string to filter records by timestamp. While it seems timestamps should be convertible to strings based on viewing their values in Query Analyzer, using CONVERT() directly on a timestamp fails. The suggested workaround is to first convert the timestamp to a datetime before converting to varchar, but the reason for the discrepancy with the documentation is unclear.

Uploaded by

Buggy Buggys
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

http://www.sql-server-performance.com/forum/threads/convert-timestamp-to-varchar.

10681/

Convert timestamp to varchar

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 ? Thanks

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.

You might also like