I used SQL Server. I converted value from datetime2 column with different scales to string and compare them to process null values if they are exist. So, I need to convert this data without tailing nulls by one query without any procedures For example,
'2018-06-23 07:30:20.100' should be '2018-06-23 07:30:20.1'
'2018-06-23 07:30:20.000' should be '2018-06-23 07:30:20.'
'2018-06-23 07:30:20.101' should be '2018-06-23 07:30:20.101'
I used following:
select CONVERT(VARCHAR, col1, 126) from [DBO].[DATE_TABLE1]
But it shows unexpected result:
'2018-06-23 07:30:20.100' defined as '2018-06-23 07:30:20.100' - **unexpected(trailing zeros weren't removed)**
'2018-06-23 07:30:20.000' defined as '2018-06-23 07:30:20' - expected
'2018-06-23 07:30:20.101' defined as '2018-06-23 07:30:20.101' - expected
how can I convert datatime2 value without trailing zeros? Thank you