Hello,
I am using SQL language (not Dataquery) to convert Datacom numeric type to string/date/datetime type in a Select clause.
More specifically, I have two NUMERIC columns: DATE_CHANGE of format yyyymmdd and TIME_CHANGE of format hhmmss and I want to combine those two numbers into a string and a datetime type.
For example: I have 20200822 and 070323,
1) how to add '-' and space ' 'and combine those two columns to get '2020-08-22 07:03:23'?
something like:
select insert(DATE_CHANGE, 5, '-') + insert(TIME_CHANGE, 3, ':') as DATETIME_CHANGE
from myTable
2) how to combine those two columns to a datetime type?
something like:
select cast((cast(DATE_CHANGE as date), cast(TIME_CHANGE as time), datetime) as DATETIME_CHANGE
from myTable
3) The requirement in my real problem also include:
- if DATE_CHANGE is 0, convert it to 1900-01-01
- if TIME_CHANGE number has less than 6 digits, padding 0s to the left and convert it to string/time as above
Can you please give me a SQL command to cover both (1), (3) and (2), (3)?
Thank you very much.