Miguel Mas Miguel Mas - 7 months ago 33
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?



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


select convert(int, CURRENT_TIMESTAMP, 121)  MYDATENUMBER