If (@ StartTime> @ EndTime)
Set @ EndTime = cast (convert (char, @ ScheduleDate + 1,101) + ''+ convert (char, @ EndTime, 108) as datetime)
Else
Set @ EndTime = cast (convert (char, @ ScheduleDate, 101) + ''+ convert (char, @ EndTime, 108) as datetime)
Set @ StartTime = cast (convert (char, @ ScheduleDate, 101) + ''+ convert (char, @ StartTime, 108) as datetime)
Convert and Cast in this statement.
Convert (data_type [, length], expression [, style])
This conversion function is generally used only when the time and string types are converted.
The format of the style is as follows:
Style (2 bits represent the year) | Style (4 bits represent the year) | input/output format
Bytes ------------------------------------------------------------------------------------------------------------
0 | 100 | mon dd yyyy hh: miAM (or PM)
Bytes ------------------------------------------------------------------------------------------------------------
1 | 101 us | mm/dd/yy
Bytes ------------------------------------------------------------------------------------------------------------
2 | 102 ANSI | yy-mm-dd
Bytes ------------------------------------------------------------------------------------------------------------
3 | 103 English | dd/mm/yy
Bytes ------------------------------------------------------------------------------------------------------------
4 | 104 Germany | dd. mm. yy
Bytes ------------------------------------------------------------------------------------------------------------
5 | 105 Italy | dd-mm-yy
Bytes ------------------------------------------------------------------------------------------------------------
6 | 106 | dd mon yy
Bytes ------------------------------------------------------------------------------------------------------------
7 | 107 | mon dd, yy
Bytes ------------------------------------------------------------------------------------------------------------
Eight | 108 | hh: mm: ss
Bytes ------------------------------------------------------------------------------------------------------------
9 | 109 | mon dd yyyy hh: mi: ss: mmmmAM (or PM)
Bytes ------------------------------------------------------------------------------------------------------------
10 | 110 US | mm-dd-yy
Bytes ------------------------------------------------------------------------------------------------------------
11 | 111 Japan | yy/mm/dd
Bytes ------------------------------------------------------------------------------------------------------------
12 | 112 ISO | yymmdd
Bytes ------------------------------------------------------------------------------------------------------------
13 | 113 European default value | dd mon yyyy hh: mi: ss: mmm (in 24-hour format)
Bytes ------------------------------------------------------------------------------------------------------------
14 | 114 | hh: mi: ss: mmm (in 24-hour format)
Bytes ------------------------------------------------------------------------------------------------------------
20 | 120 ODBC specifications | yyyy-mm-dd hh: mi: ss (24-hour)
Bytes ------------------------------------------------------------------------------------------------------------
21 | 121 | yyyy-mm-dd hh: mi: ss: mmm (in 24-hour format)
Cast (Expression as data_type): converts a data type to another type.
Select top 1 starttime from itemtransaction
Select top 1 convert (char, starttime + 1,102) from itemtransaction
Select top 1 Convert (char, starttime, 108) from itemtransaction
Select top 1 cast (convert (char, starttime + 1,102) + Convert (char, starttime, 108) as datetime) from itemtransaction
Display result: