"How can I combine an INT valued Date with another INT type for hours and minutes so taht I could insert it to another column with datetime data type"
I would like to get this result:
2013-01-02 23:56:00.000 <-- This should be in a datetime format
The data I have is the following:
20130102 <-- this is in INTEGER type in the database -- which comes from column DateA
23 <-- this is also in INTEGER type (for hours) -- which comes from column HourA
56 <-- this is also in INTEGER type (for minutes) -- which comes from column MinutesA
This is what I did, but I got an error:
SUBSTRING(CAST(DateA AS VARCHAR),1,4)+'-'+SUBSTRING(CAST(DateA AS VARCHAR),5,2)+'-'+
SUBSTRING(CAST(DateA AS VARCHAR),7,2)+' '+CAST(HourA AS VARCHAR)+ ':' +CAST(MinutesA AS VARCHAR)+ ':00.000'
This is the error:
Msg 241, Level 16, State 1, Line 1 Conversion failed when converting date and/or time from character string.
By the way, I am using SQL server 2008 R2.