How to Convert a Time Stamp to Decimal in T-SQL

Written by alexander gokhfeld
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Convert a Time Stamp to Decimal in T-SQL
The T-SQL timestamp data type stores the number of performed database operations. (Ablestock.com/AbleStock.com/Getty Images)

The T-SQL (Transact SQL) language is an extension of the standard SQL query language. It includes tools that allow users to control access to the different type of data in Microsoft SQL databases. Each database has a counter that is incremented for each insert or update operation performed on the database tables. The timestamp data type displays automatically generated unique binary numbers to stamp a version of table rows within your database. You need to define timestamp variable in the database table to convert a timestamp to decimal in T-SQL.

Skill level:
Moderately Easy

Other People Are Reading

Instructions

  1. 1

    Click the "Start" button in Windows and select "Microsoft SQL" from the "All Programs" menu to open the SQL management console.

  2. 2

    Type in the following code in the console window:

    CREATE TABLE MyTest2 (my Key int PRIMARY KEY

    ,my Value int, TS timestamp);
    

    GO

    INSERT INTO MyTest2 (my Key, my Value) VALUES (1, 0);

    GO

    INSERT INTO MyTest2 (my Key, my Value) VALUES (2, 0);

    GO

    DECLARE @t TABLE (my Key int);

    UPDATE MyTest2

    SET my Value = 2

    OUTPUT inserted.myKey INTO @t(myKey)
    

    WHERE my Key = 1

    AND TS = my Value;
    

    IF (SELECT COUNT(*) FROM @t) = 0

    BEGIN
    
        RAISERROR ('error changing row with my Key = %d')
    
    END;
    

    This creates the "myTest2" database and indexes it with the "myKey" primary key using the "TS" variable in your SELECT query.

  3. 3

    Click "File" and "Run" to run the T-SQL query for the conversion of the timestamp counter in the "myTest2" database to the decimal data type.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.