Miguel Mas Miguel Mas - 1 year ago 88
SQL Question

TSQL: error while converting timestap to integer

I have:

cast(convert(varchar(255), CURRENT_TIMESTAMP, 121) as int) as MYDATENUMBER

Being 121: yyyy-mm-dd hh:mi:ss.mmm (24h)

This is the error that I get:

Conversion failed when converting the varchar value '2016-11-16 10:28:47.330' to data type int.

MYDATENUMBER is defined as INT

Any idea on why I am getting this error?


Answer Source

You are converting CURRENT_TIMESTAMP to a varchar(255) and then casting a varchar to an int


select convert(int, CURRENT_TIMESTAMP, 121)  MYDATENUMBER
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download