From a9535db346db93b8522f565179c3fa8828f413c3 Mon Sep 17 00:00:00 2001 From: Rohit Bhagat Date: Wed, 1 Jan 2025 04:29:50 +0000 Subject: [PATCH 01/10] Fix issue with convert function when converting string to date, datetimeoffset, datetime2, datetime, smalldatetime or time Signed-off-by: Rohit Bhagat --- .../sql/sys_function_helpers.sql | 2281 ++++--- .../babelfishpg_tsql/sql/sys_functions.sql | 4 +- .../babelfishpg_tsql--5.0.0--5.1.0.sql | 5288 +++++++++++++++++ .../src/backend_parser/gram-tsql-epilogue.y.c | 57 +- test/JDBC/expected/9809_1.out | 368 ++ test/JDBC/expected/ATTIMEZONE.out | 2 - .../BABEL-3486-before-17_3-vu-prepare.out | 1230 ++++ .../BABEL-3486-before-17_3-vu-verify.out | 3232 ++++++++++ test/JDBC/expected/BABEL-3486-vu-verify.out | 14 +- .../BABEL-3614-before-17_3-vu-prepare.out | 184 + .../BABEL-3614-before-17_3-vu-verify.out | 503 ++ test/JDBC/expected/BABEL-3614-vu-verify.out | 38 +- test/JDBC/expected/BABEL-5031-vu-verify.out | 106 + ...dateaddfunction-before-17_3-vu-prepare.out | 632 ++ ...-dateaddfunction-before-17_3-vu-verify.out | 309 + ...ime-numeric-dateaddfunction-vu-prepare.out | 126 +- test/JDBC/expected/TestDatetime-vu-verify.out | 14 +- test/JDBC/expected/TestDatetime.out | 14 +- test/JDBC/expected/babel_function.out | 14 +- .../chinese_prc_ci_as/babel_function.out | 14 +- ..._string_to_date-before-13_6-vu-cleanup.out | 71 + ..._string_to_date-before-13_6-vu-prepare.out | 107 + ...v_string_to_date-before-13_6-vu-verify.out | 3741 ++++++++++++ ..._string_to_date-before-17_3-vu-cleanup.out | 68 + ..._string_to_date-before-17_3-vu-prepare.out | 104 + ...v_string_to_date-before-17_3-vu-verify.out | 3734 ++++++++++++ .../test_conv_string_to_date-vu-cleanup.out | 71 + .../test_conv_string_to_date-vu-prepare.out | 107 + .../test_conv_string_to_date-vu-verify.out | 3743 ++++++++++++ ...ing_to_datetime-before-14_6-vu-cleanup.out | 68 + ...ing_to_datetime-before-14_6-vu-prepare.out | 104 + ...ring_to_datetime-before-14_6-vu-verify.out | 3543 +++++++++++ ...ing_to_datetime-before-17_3-vu-cleanup.out | 68 + ...ing_to_datetime-before-17_3-vu-prepare.out | 104 + ...ring_to_datetime-before-17_3-vu-verify.out | 3541 +++++++++++ ...est_conv_string_to_datetime-vu-cleanup.out | 68 + ...est_conv_string_to_datetime-vu-prepare.out | 104 + ...test_conv_string_to_datetime-vu-verify.out | 3540 +++++++++++ ...ng_to_datetime2-before-14_5-vu-cleanup.out | 64 + ...ng_to_datetime2-before-14_5-vu-prepare.out | 101 + ...ing_to_datetime2-before-14_5-vu-verify.out | 1768 ++++++ ...ng_to_datetime2-before-17_3-vu-cleanup.out | 64 + ...ng_to_datetime2-before-17_3-vu-prepare.out | 101 + ...ing_to_datetime2-before-17_3-vu-verify.out | 1768 ++++++ ...st_conv_string_to_datetime2-vu-cleanup.out | 60 + ...st_conv_string_to_datetime2-vu-prepare.out | 97 + ...est_conv_string_to_datetime2-vu-verify.out | 1768 ++++++ ..._datetimeoffset-before-17_3-vu-cleanup.out | 52 + ..._datetimeoffset-before-17_3-vu-prepare.out | 80 + ...o_datetimeoffset-before-17_3-vu-verify.out | 1893 ++++++ ...nv_string_to_datetimeoffset-vu-cleanup.out | 48 + ...nv_string_to_datetimeoffset-vu-prepare.out | 76 + ...onv_string_to_datetimeoffset-vu-verify.out | 1893 ++++++ ...o_smalldatetime-before-14_6-vu-cleanup.out | 52 + ...o_smalldatetime-before-14_6-vu-prepare.out | 80 + ...to_smalldatetime-before-14_6-vu-verify.out | 1943 ++++++ ...onv_string_to_smalldatetime-vu-cleanup.out | 48 + ...onv_string_to_smalldatetime-vu-prepare.out | 76 + ...conv_string_to_smalldatetime-vu-verify.out | 1944 ++++++ ..._string_to_time-before-13_6-vu-cleanup.out | 71 + ..._string_to_time-before-13_6-vu-prepare.out | 107 + ...v_string_to_time-before-13_6-vu-verify.out | 2365 ++++++++ ..._string_to_time-before-17_3-vu-cleanup.out | 71 + ..._string_to_time-before-17_3-vu-prepare.out | 107 + ...v_string_to_time-before-17_3-vu-verify.out | 2372 ++++++++ .../test_conv_string_to_time-vu-cleanup.out | 71 + .../test_conv_string_to_time-vu-prepare.out | 107 + .../test_conv_string_to_time-vu-verify.out | 2367 ++++++++ .../BABEL-3486-before-17_3-vu-prepare.sql | 1228 ++++ .../BABEL-3486-before-17_3-vu-verify.sql | 1607 +++++ .../BABEL-3614-before-17_3-vu-prepare.sql | 184 + .../BABEL-3614-before-17_3-vu-verify.sql | 249 + test/JDBC/input/BABEL-5031-vu-verify.sql | 72 + ...dateaddfunction-before-17_3-vu-prepare.sql | 406 ++ ...-dateaddfunction-before-17_3-vu-verify.sql | 159 + ..._string_to_date-before-13_6-vu-cleanup.sql | 71 + ..._string_to_date-before-13_6-vu-prepare.sql | 107 + ...v_string_to_date-before-13_6-vu-verify.sql | 1481 +++++ ..._string_to_date-before-17_3-vu-cleanup.sql | 68 + ..._string_to_date-before-17_3-vu-prepare.sql | 104 + ...v_string_to_date-before-17_3-vu-verify.sql | 1478 +++++ .../test_conv_string_to_date-vu-cleanup.sql | 71 + .../test_conv_string_to_date-vu-prepare.sql | 107 + .../test_conv_string_to_date-vu-verify.sql | 1482 +++++ ...ing_to_datetime-before-14_6-vu-cleanup.sql | 68 + ...ing_to_datetime-before-14_6-vu-prepare.sql | 104 + ...ring_to_datetime-before-14_6-vu-verify.sql | 1407 +++++ ...ing_to_datetime-before-17_3-vu-cleanup.sql | 68 + ...ing_to_datetime-before-17_3-vu-prepare.sql | 104 + ...ring_to_datetime-before-17_3-vu-verify.sql | 1407 +++++ ...est_conv_string_to_datetime-vu-cleanup.sql | 68 + ...est_conv_string_to_datetime-vu-prepare.sql | 104 + ...test_conv_string_to_datetime-vu-verify.sql | 1408 +++++ ...ng_to_datetime2-before-14_5-vu-cleanup.sql | 60 + ...ng_to_datetime2-before-14_5-vu-prepare.sql | 97 + ...ing_to_datetime2-before-14_5-vu-verify.sql | 684 +++ ...ng_to_datetime2-before-17_3-vu-cleanup.sql | 60 + ...ng_to_datetime2-before-17_3-vu-prepare.sql | 97 + ...ing_to_datetime2-before-17_3-vu-verify.sql | 684 +++ ...st_conv_string_to_datetime2-vu-cleanup.sql | 60 + ...st_conv_string_to_datetime2-vu-prepare.sql | 97 + ...est_conv_string_to_datetime2-vu-verify.sql | 685 +++ ..._datetimeoffset-before-17_3-vu-cleanup.sql | 48 + ..._datetimeoffset-before-17_3-vu-prepare.sql | 76 + ...o_datetimeoffset-before-17_3-vu-verify.sql | 743 +++ ...nv_string_to_datetimeoffset-vu-cleanup.sql | 48 + ...nv_string_to_datetimeoffset-vu-prepare.sql | 76 + ...onv_string_to_datetimeoffset-vu-verify.sql | 744 +++ ...o_smalldatetime-before-14_6-vu-cleanup.sql | 48 + ...o_smalldatetime-before-14_6-vu-prepare.sql | 76 + ...to_smalldatetime-before-14_6-vu-verify.sql | 776 +++ ...onv_string_to_smalldatetime-vu-cleanup.sql | 48 + ...onv_string_to_smalldatetime-vu-prepare.sql | 76 + ...conv_string_to_smalldatetime-vu-verify.sql | 777 +++ ..._string_to_time-before-13_6-vu-cleanup.sql | 71 + ..._string_to_time-before-13_6-vu-prepare.sql | 107 + ...v_string_to_time-before-13_6-vu-verify.sql | 920 +++ ..._string_to_time-before-17_3-vu-cleanup.sql | 71 + ..._string_to_time-before-17_3-vu-prepare.sql | 107 + ...v_string_to_time-before-17_3-vu-verify.sql | 920 +++ .../test_conv_string_to_time-vu-cleanup.sql | 71 + .../test_conv_string_to_time-vu-prepare.sql | 107 + .../test_conv_string_to_time-vu-verify.sql | 921 +++ test/JDBC/jdbc_schedule | 38 + test/JDBC/upgrade/13_4/schedule | 7 + test/JDBC/upgrade/13_5/schedule | 7 + test/JDBC/upgrade/13_6/schedule | 7 + test/JDBC/upgrade/13_7/schedule | 7 + test/JDBC/upgrade/13_8/schedule | 7 + test/JDBC/upgrade/13_9/schedule | 7 + test/JDBC/upgrade/14_10/schedule | 11 +- test/JDBC/upgrade/14_11/schedule | 11 +- test/JDBC/upgrade/14_12/schedule | 11 +- test/JDBC/upgrade/14_3/schedule | 7 + test/JDBC/upgrade/14_5/schedule | 7 + test/JDBC/upgrade/14_6/schedule | 11 +- test/JDBC/upgrade/14_7/schedule | 11 +- test/JDBC/upgrade/14_8/schedule | 11 +- test/JDBC/upgrade/14_9/schedule | 11 +- test/JDBC/upgrade/15_1/schedule | 11 +- test/JDBC/upgrade/15_2/schedule | 11 +- test/JDBC/upgrade/15_3/schedule | 13 +- test/JDBC/upgrade/15_4/schedule | 13 +- test/JDBC/upgrade/15_5/schedule | 13 +- test/JDBC/upgrade/15_6/schedule | 13 +- test/JDBC/upgrade/15_7/schedule | 9 + test/JDBC/upgrade/16_1/schedule | 13 +- test/JDBC/upgrade/16_2/schedule | 13 +- test/JDBC/upgrade/latest/schedule | 8 + .../expected_dependency.out | 21 +- 150 files changed, 81360 insertions(+), 846 deletions(-) create mode 100644 test/JDBC/expected/9809_1.out create mode 100644 test/JDBC/expected/BABEL-3486-before-17_3-vu-prepare.out create mode 100644 test/JDBC/expected/BABEL-3486-before-17_3-vu-verify.out create mode 100644 test/JDBC/expected/BABEL-3614-before-17_3-vu-prepare.out create mode 100644 test/JDBC/expected/BABEL-3614-before-17_3-vu-verify.out create mode 100644 test/JDBC/expected/BABEL-5031-vu-verify.out create mode 100644 test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-prepare.out create mode 100644 test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_date-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_date-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_date-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime2-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime2-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetime2-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_smalldatetime-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_smalldatetime-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_smalldatetime-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-verify.out create mode 100644 test/JDBC/expected/test_conv_string_to_time-vu-cleanup.out create mode 100644 test/JDBC/expected/test_conv_string_to_time-vu-prepare.out create mode 100644 test/JDBC/expected/test_conv_string_to_time-vu-verify.out create mode 100644 test/JDBC/input/BABEL-3486-before-17_3-vu-prepare.sql create mode 100644 test/JDBC/input/BABEL-3486-before-17_3-vu-verify.sql create mode 100644 test/JDBC/input/BABEL-3614-before-17_3-vu-prepare.sql create mode 100644 test/JDBC/input/BABEL-3614-before-17_3-vu-verify.sql create mode 100644 test/JDBC/input/BABEL-5031-vu-verify.sql create mode 100644 test/JDBC/input/datatypes/TestDatetime-numeric-dateaddfunction-before-17_3-vu-prepare.sql create mode 100644 test/JDBC/input/datatypes/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_date-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_date-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_date-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime2-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime2-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetime2-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-verify.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_time-vu-cleanup.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_time-vu-prepare.sql create mode 100644 test/JDBC/input/functions/test_conv_string_to_time-vu-verify.sql diff --git a/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql b/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql index 99d5c59f2e..8686f463a6 100644 --- a/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql +++ b/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql @@ -387,7 +387,13 @@ BEGIN v_fseconds := lpad(v_fseconds, 3, '0'); END IF; ELSE - v_fseconds := sys.babelfish_get_microsecs_from_fractsecs(to_char(v_datetimeval, 'US'), v_scale); + v_fseconds := sys.babelfish_get_microsecs_from_fractsecs_v2(to_char(v_datetimeval, 'US'), v_scale); + + -- Following condition will handle overflow of fractsecs + IF (v_fseconds::INTEGER < 0) THEN + v_fseconds := PG_CATALOG.repeat('0', LEAST(v_scale, 6)); + v_datetimeval := v_datetimeval + INTERVAL '1 second'; + END IF; IF (v_scale = 7) THEN v_fseconds := pg_catalog.concat(v_fseconds, '0'); @@ -680,7 +686,7 @@ BEGIN END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; CREATE OR REPLACE FUNCTION sys.babelfish_conv_hijri_to_greg(IN p_day NUMERIC, @@ -762,7 +768,7 @@ EXCEPTION END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; CREATE OR REPLACE FUNCTION sys.babelfish_conv_hijri_to_greg(IN p_day TEXT, @@ -778,7 +784,7 @@ BEGIN END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; CREATE OR REPLACE FUNCTION sys.babelfish_conv_hijri_to_greg(IN p_datetimeval TIMESTAMP WITHOUT TIME ZONE) @@ -798,30 +804,46 @@ BEGIN END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; -CREATE OR REPLACE FUNCTION sys.babelfish_conv_string_to_date(IN p_datestring TEXT, - IN p_style NUMERIC DEFAULT 0) -RETURNS DATE +-- Following function can be used to convert string literal to DATE, TIME and DATETIME2. +CREATE OR REPLACE FUNCTION sys.babelfish_conv_string_to_datetime2(IN p_datatype TEXT, + IN p_datetimestring TEXT, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIMESTAMP WITHOUT TIME ZONE AS $BODY$ DECLARE v_day VARCHAR COLLATE "C"; v_year VARCHAR COLLATE "C"; v_month VARCHAR COLLATE "C"; - v_hijridate DATE; v_style SMALLINT; + v_scale SMALLINT; + v_hours VARCHAR COLLATE "C"; + v_hijridate DATE; + v_minutes VARCHAR COLLATE "C"; + v_seconds VARCHAR COLLATE "C"; + v_fseconds VARCHAR COLLATE "C"; + v_sign VARCHAR COLLATE "C" = NULL::VARCHAR; + v_offhours VARCHAR COLLATE "C" = NULL::VARCHAR; + v_offminutes VARCHAR COLLATE "C" = NULL::VARCHAR; + v_datatype VARCHAR COLLATE "C"; + v_timepart VARCHAR COLLATE "C"; v_leftpart VARCHAR COLLATE "C"; v_middlepart VARCHAR COLLATE "C"; v_rightpart VARCHAR COLLATE "C"; - v_fractsecs VARCHAR COLLATE "C"; v_datestring VARCHAR COLLATE "C"; v_err_message VARCHAR COLLATE "C"; v_date_format VARCHAR COLLATE "C"; + v_res_datatype VARCHAR COLLATE "C"; + v_datetimestring VARCHAR COLLATE "C"; + v_datatype_groups TEXT[]; v_regmatch_groups TEXT[]; v_lang_metadata_json JSONB; v_compmonth_regexp VARCHAR COLLATE "C"; + v_resdatetime TIMESTAMP(6) WITHOUT TIME ZONE; + v_language VARCHAR COLLATE "C"; CONVERSION_LANG CONSTANT VARCHAR COLLATE "C" := ''; DATE_FORMAT CONSTANT VARCHAR COLLATE "C" := ''; DAYMM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; @@ -829,67 +851,124 @@ DECLARE SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; COMPYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2}|\d{4})'; AMPM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:[AP]M)'; + MASKSEP_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:\.|-|/)'; TIMEUNIT_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,2}\s*'; - FRACTSECS_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,9}'; - HHMMSSFS_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('(', TIMEUNIT_REGEXP, AMPM_REGEXP, '|', - TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '|', - TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '|', - TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '(?:\.|\:)', FRACTSECS_REGEXP, - ')\s*', AMPM_REGEXP, '?'); - HHMMSSFS_DOTPART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('(', TIMEUNIT_REGEXP, AMPM_REGEXP, '|', - TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '|', - TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '|', - TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\.', FRACTSECS_REGEXP, - ')\s*', AMPM_REGEXP, '?'); - HHMMSSFS_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', HHMMSSFS_PART_REGEXP, '$'); - HHMMSSFS_DOT_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', HHMMSSFS_DOTPART_REGEXP, '$'); - v_defmask1_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^($comp_month$)\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '$'); - v_defmask2_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*($comp_month$)\s*', COMPYEAR_REGEXP, '$'); - v_defmask3_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*($comp_month$)\s*', DAYMM_REGEXP, '$'); - v_defmask4_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*($comp_month$)$'); - v_defmask5_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '\s*($comp_month$)$'); - v_defmask6_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^($comp_month$)\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '$'); - v_defmask7_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^($comp_month$)\s*', DAYMM_REGEXP, '\s*\,\s*', COMPYEAR_REGEXP, '$'); - v_defmask8_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*($comp_month$)$'); - v_defmask9_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^($comp_month$)\s*', FULLYEAR_REGEXP, '$'); - v_defmask10_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*(?:\.|/|-)\s*($comp_month$)\s*(?:\.|/|-)\s*', COMPYEAR_REGEXP, '$'); - DOT_SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '\s*\.\s*', SHORTYEAR_REGEXP, '$'); - DOT_FULLYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '\s*\.\s*', FULLYEAR_REGEXP, '$'); - SLASH_SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*/\s*', DAYMM_REGEXP, '\s*/\s*', SHORTYEAR_REGEXP, '$'); - SLASH_FULLYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*/\s*', DAYMM_REGEXP, '\s*/\s*', FULLYEAR_REGEXP, '$'); - DASH_SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*-\s*', DAYMM_REGEXP, '\s*-\s*', SHORTYEAR_REGEXP, '$'); - DASH_FULLYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*-\s*', DAYMM_REGEXP, '\s*-\s*', FULLYEAR_REGEXP, '$'); - DOT_SLASH_DASH_YEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*(?:\.|/|-)\s*', DAYMM_REGEXP, '\s*(?:\.|/|-)\s*', COMPYEAR_REGEXP, '$'); - YEAR_DOTMASK_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '$'); - YEAR_SLASHMASK_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*/\s*', DAYMM_REGEXP, '\s*/\s*', DAYMM_REGEXP, '$'); - YEAR_DASHMASK_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*-\s*', DAYMM_REGEXP, '\s*-\s*', DAYMM_REGEXP, '$'); - YEAR_DOT_SLASH_DASH_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*(?:\.|/|-)\s*', DAYMM_REGEXP, '\s*(?:\.|/|-)\s*', DAYMM_REGEXP, '$'); - DIGITMASK1_REGEXP CONSTANT VARCHAR COLLATE "C" := '^\d{6}$'; - DIGITMASK2_REGEXP CONSTANT VARCHAR COLLATE "C" := '^\d{8}$'; + FRACTSECS_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,9}\s*'; + DATATYPE_REGEXP CONSTANT VARCHAR COLLATE "C" := '^(DATE|TIME|DATETIME2|DATETIMEOFFSET)\s*(?:\()?\s*((?:-)?\d+)?\s*(?:\))?$'; + TIME_OFFSET_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('\s*((\-|\+)\s*(', TIMEUNIT_REGEXP, ')\s*\:\s*(', TIMEUNIT_REGEXP, ')|Z)\s*'); + HHMMSSFSOFF_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('(', TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '(?:\.|\:)', FRACTSECS_REGEXP, AMPM_REGEXP, '?)(', TIME_OFFSET_REGEXP, ')?'); + HHMMSSFSOFF_DOT_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('(', TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '(?:\.)', FRACTSECS_REGEXP, AMPM_REGEXP, '?)(', TIME_OFFSET_REGEXP, ')?'); + HHMMSSFSOFF_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFSOFF_PART_REGEXP, ')$'); + DEFMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '$'); + DEFMASK2_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK2_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, '$'); + DEFMASK3_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*($comp_month$)\s*', DAYMM_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK3_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*($comp_month$)\s*', DAYMM_REGEXP, '$'); + DEFMASK4_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*($comp_month$)', '\s*(', HHMMSSFSOFF_PART_REGEXP, ')?$'); + DEFMASK4_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*($comp_month$)$'); + DEFMASK5_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '\s*($comp_month$)', '\s*(', HHMMSSFSOFF_PART_REGEXP, ')?$'); + DEFMASK5_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '\s*($comp_month$)$'); + DEFMASK6_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK6_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '$'); + DEFMASK7_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK7_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '$'); + DEFMASK8_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', COMPYEAR_REGEXP, '\s*($comp_month$)', '\s*(', HHMMSSFSOFF_PART_REGEXP, ')?$'); + DEFMASK8_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', COMPYEAR_REGEXP, '\s*($comp_month$)$'); + DEFMASK8_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', SHORTYEAR_REGEXP, '\s*($comp_month$)$'); + DEFMASK9_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK9_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*\,?\s*', COMPYEAR_REGEXP, '$'); + DEFMASK9_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', SHORTYEAR_REGEXP, '$'); + DEFMASK9_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*\,?\s*', FULLYEAR_REGEXP, '$'); + DEFMASK10_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK10_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '$'); + DEFMASK10_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*-\s*($comp_month$)\s*-\s*', COMPYEAR_REGEXP, '$'); + DEFMASK10_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\/\s*($comp_month$)\s*\/\s*', COMPYEAR_REGEXP, '$'); + DEFMASK10_4_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\.\s*($comp_month$)\s*\.\s*', COMPYEAR_REGEXP, '$'); + DOT_SLASH_DASH_COMPYEAR1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DOT_SLASH_DASH_COMPYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '$'); + DASH_COMPYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*-\s*', DAYMM_REGEXP, '\s*-\s*', COMPYEAR_REGEXP, '$'); + SLASH_COMPYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\/\s*', DAYMM_REGEXP, '\s*\/\s*', COMPYEAR_REGEXP, '$'); + DOT_COMPYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '\s*\.\s*', COMPYEAR_REGEXP, '$'); + DOT_SLASH_DASH_SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', SHORTYEAR_REGEXP, '$'); + DOT_SLASH_DASH_FULLYEAR1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DOT_SLASH_DASH_FULLYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '$'); + FULLYEAR_DOT_SLASH_DASH1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + FULLYEAR_DOT_SLASH_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '$'); + FULLYEAR_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*-\s*', DAYMM_REGEXP, '\s*-\s*', DAYMM_REGEXP, '$'); + FULLYEAR_SLASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*\/\s*', DAYMM_REGEXP, '\s*\/\s*', DAYMM_REGEXP, '$'); + FULLYEAR_DOT1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '$'); + DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '$'); + DASH_FULLYEAR_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*-\s*', FULLYEAR_REGEXP, '\s*-\s*', DAYMM_REGEXP, '$'); + SLASH_FULLYEAR_SLASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\/\s*', FULLYEAR_REGEXP, '\s*\/\s*', DAYMM_REGEXP, '$'); + DOT_FULLYEAR_DOT1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\.\s*', FULLYEAR_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '$'); + FULLYEAR_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '\s*\d{4}', '(\s+(', HHMMSSFSOFF_PART_REGEXP, '))?$'); + SHORT_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '\s*\d{6}', '(\s+(', HHMMSSFSOFF_PART_REGEXP, '))?$'); + FULL_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '\s*\d{8}', '(\s+(', HHMMSSFSOFF_PART_REGEXP, '))?$'); + W3C_XML_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, '(', '(\-|\+)', '(\d{2})', '\:', '(\d{2})', '|', 'Z', ')','$'); + W3C_XML_Z_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, 'Z','$'); + ISO_8601_DATETIMEOFFSET_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, 'T', '\d{2}', '\:', '\d{1,2}', '\:', '\d{1,2}', '(?:\.', '\d{1,9}', ')?', '((\-|\+)', '\d{2}', '\:', '\d{2}','|Z)?$'); BEGIN + v_datatype := pg_catalog.btrim(p_datatype); + v_datetimestring := pg_catalog.upper(pg_catalog.btrim(p_datetimestring)); v_style := floor(p_style)::SMALLINT; - v_datestring := pg_catalog.btrim(p_datestring); + + v_datatype_groups := regexp_matches(v_datatype, DATATYPE_REGEXP, 'gi'); + + v_res_datatype := pg_catalog.upper(v_datatype_groups[1]); + v_scale := v_datatype_groups[2]::SMALLINT; + + IF (v_res_datatype IS NULL) THEN + RAISE datatype_mismatch; + ELSIF (v_res_datatype = 'DATE' AND v_scale IS NOT NULL) + THEN + RAISE invalid_indicator_parameter_value; + ELSIF (coalesce(v_scale, 0) NOT BETWEEN 0 AND 7) + THEN + RAISE interval_field_overflow; + ELSIF (v_scale IS NULL) THEN + -- currently datetime2, datetimeoffset and time only support factional seconds + -- upto 6 digits hence set v_scale to 6 to get consistent behaviour in datetime2(7) and datetime2 + v_scale := 6; + END IF; IF (scale(p_style) > 0) THEN RAISE most_specific_type_mismatch; ELSIF (NOT ((v_style BETWEEN 0 AND 14) OR - (v_style BETWEEN 20 AND 25) OR - (v_style BETWEEN 100 AND 114) OR - v_style IN (120, 121, 126, 127, 130, 131))) + (v_style BETWEEN 20 AND 25) OR + (v_style BETWEEN 100 AND 114) OR + (v_style IN (120, 121, 126, 127, 130, 131)))) THEN RAISE invalid_parameter_value; END IF; - IF (v_datestring ~* HHMMSSFS_PART_REGEXP AND v_datestring !~* HHMMSSFS_REGEXP) + -- For W3C_XML_REGEXP, there is no need of maintaining v_timepart and v_datestring + IF (v_datetimestring ~* W3C_XML_REGEXP) THEN - v_datestring := pg_catalog.btrim(regexp_pg_catalog.replace(v_datestring, HHMMSSFS_PART_REGEXP, '', 'gi')); + v_timepart := NULL; + v_datestring := NULL; + ELSE + v_timepart := pg_catalog.btrim(substring(v_datetimestring, PG_CATALOG.concat('(', HHMMSSFSOFF_PART_REGEXP, ')'))); + v_datestring := pg_catalog.btrim(regexp_replace(v_datetimestring, PG_CATALOG.concat('T?', '(', HHMMSSFSOFF_PART_REGEXP, ')'), '', 'gi')); END IF; + v_language := CASE + WHEN (v_style IN (130, 131)) THEN 'HIJRI' + ELSE CONVERSION_LANG + END; + BEGIN - v_lang_metadata_json := sys.babelfish_get_lang_metadata_json(CONVERSION_LANG); + v_lang_metadata_json := sys.babelfish_get_lang_metadata_json(v_language); EXCEPTION WHEN OTHERS THEN - RAISE invalid_character_value_for_cast; + RAISE invalid_escape_sequence; END; v_date_format := coalesce(nullif(DATE_FORMAT, ''), v_lang_metadata_json ->> 'date_format'); @@ -897,138 +976,147 @@ BEGIN v_compmonth_regexp := array_to_string(array_cat(ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_shortnames')), ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_names'))), '|'); - v_defmask1_regexp := pg_catalog.replace(v_defmask1_regexp, '$comp_month$', v_compmonth_regexp); - v_defmask2_regexp := pg_catalog.replace(v_defmask2_regexp, '$comp_month$', v_compmonth_regexp); - v_defmask3_regexp := pg_catalog.replace(v_defmask3_regexp, '$comp_month$', v_compmonth_regexp); - v_defmask4_regexp := pg_catalog.replace(v_defmask4_regexp, '$comp_month$', v_compmonth_regexp); - v_defmask5_regexp := pg_catalog.replace(v_defmask5_regexp, '$comp_month$', v_compmonth_regexp); - v_defmask6_regexp := pg_catalog.replace(v_defmask6_regexp, '$comp_month$', v_compmonth_regexp); - v_defmask7_regexp := pg_catalog.replace(v_defmask7_regexp, '$comp_month$', v_compmonth_regexp); - v_defmask8_regexp := pg_catalog.replace(v_defmask8_regexp, '$comp_month$', v_compmonth_regexp); - v_defmask9_regexp := pg_catalog.replace(v_defmask9_regexp, '$comp_month$', v_compmonth_regexp); - v_defmask10_regexp := pg_catalog.replace(v_defmask10_regexp, '$comp_month$', v_compmonth_regexp); - - IF (v_datestring ~* v_defmask1_regexp OR - v_datestring ~* v_defmask2_regexp OR - v_datestring ~* v_defmask3_regexp OR - v_datestring ~* v_defmask4_regexp OR - v_datestring ~* v_defmask5_regexp OR - v_datestring ~* v_defmask6_regexp OR - v_datestring ~* v_defmask7_regexp OR - v_datestring ~* v_defmask8_regexp OR - v_datestring ~* v_defmask9_regexp OR - v_datestring ~* v_defmask10_regexp) + -- If datetime string has some part as 'AMZ' or 'PMZ' then its invalid datetime format + IF (v_datetimestring ~* pg_catalog.concat(AMPM_REGEXP, 'Z')) THEN - IF (v_style IN (130, 131)) THEN - RAISE invalid_datetime_format; - END IF; + RAISE invalid_datetime_format; + END IF; - IF (v_datestring ~* v_defmask1_regexp) + IF (v_datetimestring ~* pg_catalog.replace(DEFMASK1_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK2_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK3_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK4_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK5_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK6_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK7_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK8_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK9_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK10_0_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + IF (v_datestring ~* pg_catalog.replace(DEFMASK1_1_REGEXP, '$comp_month$', v_compmonth_regexp)) THEN - v_regmatch_groups := regexp_matches(v_datestring, v_defmask1_regexp, 'gi'); + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK1_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[2]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); - ELSIF (v_datestring ~* v_defmask2_regexp) + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK2_1_REGEXP, '$comp_month$', v_compmonth_regexp)) THEN - v_regmatch_groups := regexp_matches(v_datestring, v_defmask2_regexp, 'gi'); + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK2_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[1]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); - ELSIF (v_datestring ~* v_defmask3_regexp) + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK3_1_REGEXP, '$comp_month$', v_compmonth_regexp)) THEN - v_regmatch_groups := regexp_matches(v_datestring, v_defmask3_regexp, 'gi'); + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK3_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[3]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); v_year := v_regmatch_groups[1]; - ELSIF (v_datestring ~* v_defmask4_regexp) + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK4_1_REGEXP, '$comp_month$', v_compmonth_regexp)) THEN - v_regmatch_groups := regexp_matches(v_datestring, v_defmask4_regexp, 'gi'); + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK4_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[2]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); v_year := v_regmatch_groups[1]; - ELSIF (v_datestring ~* v_defmask5_regexp) + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK5_1_REGEXP, '$comp_month$', v_compmonth_regexp)) THEN - v_regmatch_groups := regexp_matches(v_datestring, v_defmask5_regexp, 'gi'); + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK5_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[1]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); v_year := sys.babelfish_get_full_year(v_regmatch_groups[2]); - ELSIF (v_datestring ~* v_defmask6_regexp) + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK6_1_REGEXP, '$comp_month$', v_compmonth_regexp)) THEN - v_regmatch_groups := regexp_matches(v_datestring, v_defmask6_regexp, 'gi'); + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK6_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[3]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); v_year := v_regmatch_groups[2]; - ELSIF (v_datestring ~* v_defmask7_regexp) + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK7_1_REGEXP, '$comp_month$', v_compmonth_regexp)) THEN - v_regmatch_groups := regexp_matches(v_datestring, v_defmask7_regexp, 'gi'); + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK7_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[2]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); - ELSIF (v_datestring ~* v_defmask8_regexp) + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK8_1_REGEXP, '$comp_month$', v_compmonth_regexp)) THEN - v_regmatch_groups := regexp_matches(v_datestring, v_defmask8_regexp, 'gi'); + IF (v_datetimestring ~* pg_catalog.replace(DEFMASK8_2_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK8_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := '01'; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); - v_year := v_regmatch_groups[1]; + v_year := sys.babelfish_get_full_year(v_regmatch_groups[1]); - ELSIF (v_datestring ~* v_defmask9_regexp) + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK9_1_REGEXP, '$comp_month$', v_compmonth_regexp)) THEN - v_regmatch_groups := regexp_matches(v_datestring, v_defmask9_regexp, 'gi'); + IF (v_datetimestring ~* pg_catalog.replace(DEFMASK9_2_REGEXP, '$comp_month$', v_compmonth_regexp) OR + (v_datestring !~* pg_catalog.replace(DEFMASK9_2_REGEXP, '$comp_month$', v_compmonth_regexp) AND + v_datestring !~* pg_catalog.replace(DEFMASK9_3_REGEXP, '$comp_month$', v_compmonth_regexp))) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK9_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := '01'; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); - v_year := v_regmatch_groups[2]; + v_year := sys.babelfish_get_full_year(v_regmatch_groups[2]); ELSE - v_regmatch_groups := regexp_matches(v_datestring, v_defmask10_regexp, 'gi'); + IF ((v_datestring !~* pg_catalog.replace(DEFMASK10_2_REGEXP, '$comp_month$', v_compmonth_regexp)) AND + (v_datestring !~* pg_catalog.replace(DEFMASK10_3_REGEXP, '$comp_month$', v_compmonth_regexp)) AND + (v_datestring !~* pg_catalog.replace(DEFMASK10_4_REGEXP, '$comp_month$', v_compmonth_regexp))) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK10_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[1]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); END IF; - ELSEIF (v_datestring ~* DOT_SHORTYEAR_REGEXP OR - v_datestring ~* DOT_FULLYEAR_REGEXP OR - v_datestring ~* SLASH_SHORTYEAR_REGEXP OR - v_datestring ~* SLASH_FULLYEAR_REGEXP OR - v_datestring ~* DASH_SHORTYEAR_REGEXP OR - v_datestring ~* DASH_FULLYEAR_REGEXP) + ELSIF (v_datetimestring ~* DOT_SLASH_DASH_COMPYEAR1_0_REGEXP) THEN - IF (v_style IN (6, 7, 8, 9, 12, 13, 14, 24, 100, 106, 107, 108, 109, 112, 113, 114, 130)) THEN - RAISE invalid_regular_expression; - ELSIF (v_style IN (20, 21, 23, 25, 102, 111, 120, 121, 126, 127)) THEN + IF ((v_datestring !~* DASH_COMPYEAR1_1_REGEXP) AND + (v_datestring !~* SLASH_COMPYEAR1_1_REGEXP) AND + (v_datestring !~* DOT_COMPYEAR1_1_REGEXP)) + THEN RAISE invalid_datetime_format; END IF; - v_regmatch_groups := regexp_matches(v_datestring, DOT_SLASH_DASH_YEAR_REGEXP, 'gi'); + IF (v_style IN (6, 7, 8, 9, 12, 13, 14, 24, 100, 106, 107, 108, 109, 112, 113, 114, 130)) + THEN + RAISE invalid_regular_expression; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, DOT_SLASH_DASH_COMPYEAR1_1_REGEXP, 'gi'); v_leftpart := v_regmatch_groups[1]; v_middlepart := v_regmatch_groups[2]; v_rightpart := v_regmatch_groups[3]; - IF (v_datestring ~* DOT_SHORTYEAR_REGEXP OR - v_datestring ~* SLASH_SHORTYEAR_REGEXP OR - v_datestring ~* DASH_SHORTYEAR_REGEXP) + IF (v_datestring ~* DOT_SLASH_DASH_SHORTYEAR_REGEXP) THEN - IF ((v_style IN (1, 10, 22) AND v_date_format <> 'MDY') OR - ((v_style IS NULL OR v_style IN (0, 1, 10, 22)) AND v_date_format NOT IN ('YDM', 'YMD', 'DMY', 'DYM', 'MYD'))) + IF ((v_style IN (1, 10, 22)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MDY')) THEN v_day := v_middlepart; v_month := v_leftpart; v_year := sys.babelfish_get_full_year(v_rightpart); - ELSIF ((v_style IN (2, 11) AND v_date_format <> 'YMD') OR - ((v_style IS NULL OR v_style IN (0, 2, 11)) AND v_date_format = 'YMD')) + ELSIF ((v_style IN (2, 11)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'YMD')) THEN v_day := v_rightpart; v_month := v_middlepart; v_year := sys.babelfish_get_full_year(v_leftpart); - ELSIF ((v_style IN (3, 4, 5) AND v_date_format <> 'DMY') OR - ((v_style IS NULL OR v_style IN (0, 3, 4, 5)) AND v_date_format = 'DMY')) + ELSIF ((v_style IN (3, 4, 5)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DMY')) THEN v_day := v_leftpart; v_month := v_middlepart; @@ -1036,161 +1124,340 @@ BEGIN ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DYM') THEN - v_day := v_leftpart; - v_month := v_rightpart; - v_year := sys.babelfish_get_full_year(v_middlepart); + v_day = v_leftpart; + v_month = v_rightpart; + v_year = sys.babelfish_get_full_year(v_middlepart); ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MYD') THEN v_day := v_rightpart; v_month := v_leftpart; - v_year := sys.babelfish_get_full_year(v_middlepart); + v_year = sys.babelfish_get_full_year(v_middlepart); - ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'YDM') THEN - RAISE character_not_in_repertoire; - ELSIF (v_style IN (101, 103, 104, 105, 110, 131)) THEN + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'YDM') + THEN + RAISE character_not_in_repertoire; + ELSE RAISE invalid_datetime_format; END IF; - ELSE + ELSIF (v_datestring ~* DOT_SLASH_DASH_FULLYEAR1_1_REGEXP) + THEN v_year := v_rightpart; + IF ((v_style IN (103, 104, 105, 131)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DMY')) + THEN + v_day := v_leftpart; + v_month := v_middlepart; - IF (v_leftpart::SMALLINT <= 12) + ELSIF ((v_style IN (101, 110)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MDY')) THEN - IF ((v_style IN (103, 104, 105, 131) AND v_date_format <> 'DMY') OR - ((v_style IS NULL OR v_style IN (0, 103, 104, 105, 131)) AND v_date_format = 'DMY')) - THEN - v_day := v_leftpart; - v_month := v_middlepart; - ELSIF ((v_style IN (101, 110) AND v_date_format IN ('YDM', 'DMY', 'DYM')) OR - ((v_style IS NULL OR v_style IN (0, 101, 110)) AND v_date_format NOT IN ('YDM', 'DMY', 'DYM'))) - THEN - v_day := v_middlepart; - v_month := v_leftpart; - ELSIF ((v_style IN (1, 2, 3, 4, 5, 10, 11, 22) AND v_date_format <> 'YDM') OR - ((v_style IS NULL OR v_style IN (0, 1, 2, 3, 4, 5, 10, 11, 22)) AND v_date_format = 'YDM')) - THEN - RAISE invalid_datetime_format; - END IF; + v_day := v_middlepart; + v_month := v_leftpart; ELSE - IF ((v_style IN (103, 104, 105, 131) AND v_date_format <> 'DMY') OR - ((v_style IS NULL OR v_style IN (0, 103, 104, 105, 131)) AND v_date_format = 'DMY')) - THEN - v_day := v_leftpart; - v_month := v_middlepart; - ELSIF ((v_style IN (1, 2, 3, 4, 5, 10, 11, 22, 101, 110) AND v_date_format = 'DMY') OR - ((v_style IS NULL OR v_style IN (0, 1, 2, 3, 4, 5, 10, 11, 22, 101, 110)) AND v_date_format <> 'DMY')) - THEN - RAISE invalid_datetime_format; - END IF; + RAISE invalid_datetime_format; END IF; END IF; - ELSIF (v_datestring ~* YEAR_DOTMASK_REGEXP OR - v_datestring ~* YEAR_SLASHMASK_REGEXP OR - v_datestring ~* YEAR_DASHMASK_REGEXP) + ELSIF (v_datetimestring ~* FULLYEAR_DOT_SLASH_DASH1_0_REGEXP) THEN - IF (v_style IN (6, 7, 8, 9, 12, 13, 14, 24, 100, 106, 107, 108, 109, 112, 113, 114, 130)) THEN + IF ((v_datestring !~* FULLYEAR_DASH1_1_REGEXP) AND + (v_datestring !~* FULLYEAR_SLASH1_1_REGEXP) AND + (v_datestring !~* FULLYEAR_DOT1_1_REGEXP)) + THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_style IN (6, 7, 8, 9, 12, 13, 14, 24, 100, 106, 107, 108, 109, 112, 113, 114, 130)) + THEN RAISE invalid_regular_expression; ELSIF (v_style IN (1, 2, 3, 4, 5, 10, 11, 22, 101, 103, 104, 105, 110, 131)) THEN RAISE invalid_datetime_format; END IF; - v_regmatch_groups := regexp_matches(v_datestring, YEAR_DOT_SLASH_DASH_REGEXP, 'gi'); + v_regmatch_groups := regexp_matches(v_datestring, FULLYEAR_DOT_SLASH_DASH1_1_REGEXP, 'gi'); + -- DATEFORMAT 'YDM' is not supported hence only applicable dateformat can be used here is YMD + v_year := v_regmatch_groups[1]; v_day := v_regmatch_groups[3]; v_month := v_regmatch_groups[2]; - v_year := v_regmatch_groups[1]; - - ELSIF (v_datestring ~* DIGITMASK1_REGEXP OR - v_datestring ~* DIGITMASK2_REGEXP) + ELSIF (v_datetimestring ~* DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_0_REGEXP) THEN - IF (v_datestring ~* DIGITMASK1_REGEXP) + IF ((v_datestring !~* DASH_FULLYEAR_DASH1_1_REGEXP) AND + (v_datestring !~* SLASH_FULLYEAR_SLASH1_1_REGEXP) AND + (v_datestring !~* DOT_FULLYEAR_DOT1_1_REGEXP)) THEN - v_day := substring(v_datestring, 5, 2); - v_month := substring(v_datestring, 3, 2); - v_year := sys.babelfish_get_full_year(substring(v_datestring, 1, 2)); - ELSE - v_day := substring(v_datestring, 7, 2); - v_month := substring(v_datestring, 5, 2); - v_year := substring(v_datestring, 1, 4); + RAISE invalid_datetime_format; END IF; - ELSIF (v_datestring ~* HHMMSSFS_REGEXP) - THEN - v_fractsecs := coalesce(sys.babelfish_get_timeunit_from_string(v_datestring, 'FRACTSECONDS'), ''); - IF (v_datestring !~* HHMMSSFS_DOT_REGEXP AND char_length(v_fractsecs) > 3) THEN + + IF (v_style IN (6, 7, 8, 9, 12, 13, 14, 24, 100, 106, 107, 108, 109, 112, 113, 114, 130)) + THEN + RAISE invalid_regular_expression; + ELSIF (v_style IN (1, 2, 3, 4, 5, 10, 11, 20, 21, 22, 23, 25, 101, 102, 103, 104, 105, 110, 111, 120, 121, 126, 127, 131)) THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_1_REGEXP, 'gi'); + v_leftpart := v_regmatch_groups[1]; + v_year := v_regmatch_groups[2]; + v_rightpart := v_regmatch_groups[3]; + + IF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MYD') + THEN + v_day := v_rightpart; + v_month := v_leftpart; + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DYM') + THEN + v_day := v_leftpart; + v_month := v_rightpart; + ELSE RAISE invalid_datetime_format; END IF; + ELSIF ((v_datetimestring ~* FULLYEAR_DIGITMASK1_0_REGEXP OR + v_datetimestring ~* SHORT_DIGITMASK1_0_REGEXP OR + v_datetimestring ~* FULL_DIGITMASK1_0_REGEXP)) + THEN + IF (v_datestring ~* '^\d{4}$') + THEN + v_day := '01'; + v_month := '01'; + v_year := substr(v_datestring, 1, 4); + + ELSIF (v_datestring ~* '^\d{6}$') + THEN + v_day := substr(v_datestring, 5, 2); + v_month := substr(v_datestring, 3, 2); + v_year := sys.babelfish_get_full_year(substr(v_datestring, 1, 2)); + ELSIF (v_datestring ~* '^\d{8}$') + THEN + v_day := substr(v_datestring, 7, 2); + v_month := substr(v_datestring, 5, 2); + v_year := substr(v_datestring, 1, 4); + END IF; + ELSIF (v_datetimestring ~* HHMMSSFSOFF_REGEXP OR length(v_datetimestring) = 0) + THEN v_day := '01'; v_month := '01'; v_year := '1900'; + ELSIF (v_datetimestring ~* W3C_XML_REGEXP) + THEN + v_regmatch_groups := regexp_matches(v_datetimestring, W3C_XML_REGEXP, 'gi'); + v_day := v_regmatch_groups[3]; + v_month := v_regmatch_groups[2]; + v_year := v_regmatch_groups[1]; + + IF (v_datetimestring !~* W3C_XML_Z_REGEXP) + THEN + v_sign := v_regmatch_groups[5]; + v_offhours := v_regmatch_groups[6]; + v_offminutes := v_regmatch_groups[7]; + IF ((v_offhours::SMALLINT NOT BETWEEN 0 AND 14) OR + (v_offminutes::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_offhours::SMALLINT = 14 AND v_offminutes::SMALLINT != 0)) + THEN + RAISE invalid_datetime_format; + END IF; + ELSE + v_sign := '+'; + v_offhours := '0'; + v_offminutes := '0'; + END IF; + ELSIF (v_datetimestring ~* ISO_8601_DATETIMEOFFSET_REGEXP) + THEN + v_regmatch_groups := regexp_matches(v_datetimestring, ISO_8601_DATETIMEOFFSET_REGEXP, 'gi'); + + v_day := v_regmatch_groups[3]; + v_month := v_regmatch_groups[2]; + v_year := v_regmatch_groups[1]; ELSE RAISE invalid_datetime_format; END IF; - IF (((v_datestring ~* HHMMSSFS_REGEXP OR v_datestring ~* DIGITMASK1_REGEXP OR v_datestring ~* DIGITMASK2_REGEXP) AND v_style IN (130, 131)) OR - ((v_datestring ~* DOT_FULLYEAR_REGEXP OR v_datestring ~* SLASH_FULLYEAR_REGEXP OR v_datestring ~* DASH_FULLYEAR_REGEXP) AND v_style = 131)) + IF (v_style IN (130, 131)) THEN - IF ((v_day::SMALLINT NOT BETWEEN 1 AND 29) OR - (v_month::SMALLINT NOT BETWEEN 1 AND 12)) + -- validate date according to hijri date format + IF ((v_month::SMALLINT NOT BETWEEN 1 AND 12) OR + (v_day::SMALLINT NOT BETWEEN 1 AND 30) OR + ((MOD(v_month::SMALLINT, 2) = 0 AND v_month::SMALLINT != 12) AND v_day::SMALLINT = 30)) THEN - RAISE invalid_datetime_format; + RAISE invalid_character_value_for_cast; END IF; - v_hijridate := sys.babelfish_conv_hijri_to_greg(v_day, v_month, v_year) - 1; - v_datestring := to_char(v_hijridate, 'DD.MM.YYYY'); + -- for hijri leap year + IF (v_month::SMALLINT = 12) + THEN + -- check for a leap year + IF (MOD(v_year::SMALLINT, 30) IN (2, 5, 7, 10, 13, 16, 18, 21, 24, 26, 29)) + THEN + IF (v_day::SMALLINT NOT BETWEEN 1 AND 30) + THEN + RAISE invalid_character_value_for_cast; + END IF; + ELSE + IF (v_day::SMALLINT NOT BETWEEN 1 AND 29) + THEN + RAISE invalid_character_value_for_cast; + END IF; + END IF; + END IF; - v_day := split_part(v_datestring, '.', 1); - v_month := split_part(v_datestring, '.', 2); - v_year := split_part(v_datestring, '.', 3); + v_hijridate := sys.babelfish_conv_hijri_to_greg(v_day, v_month, v_year) - 1; + v_day = to_char(v_hijridate, 'DD'); + v_month = to_char(v_hijridate, 'MM'); + v_year = to_char(v_hijridate, 'YYYY'); END IF; - RETURN to_date(pg_catalog.concat_ws('.', v_day, v_month, v_year), 'DD.MM.YYYY'); -EXCEPTION - WHEN most_specific_type_mismatch THEN - RAISE USING MESSAGE := 'Argument data type NUMERIC is invalid for argument 2 of conv_string_to_date function.', - DETAIL := 'Use of incorrect "style" parameter value during conversion process.', - HINT := 'Change "style" parameter to the proper value and try again.'; - - WHEN invalid_parameter_value THEN - RAISE USING MESSAGE := pg_catalog.format('The style %s is not supported for conversions from VARCHAR to DATE.', v_style), - DETAIL := 'Use of incorrect "style" parameter value during conversion process.', - HINT := 'Change "style" parameter to the proper value and try again.'; - - WHEN invalid_regular_expression THEN - RAISE USING MESSAGE := pg_catalog.format('The input character string doesn''t follow style %s.', v_style), - DETAIL := 'Selected "style" param value isn''t valid for conversion of passed character string.', - HINT := 'Either change the input character string or use a different style.'; - - WHEN invalid_datetime_format THEN - RAISE USING MESSAGE := 'Conversion failed when converting date from character string.', - DETAIL := 'Incorrect using of pair of input parameters values during conversion process.', - HINT := 'Check the input parameters values, correct them if needed, and try again.'; + BEGIN + v_hours := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'HOURS'), '0'); + v_minutes := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'MINUTES'), '0'); + v_seconds := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'SECONDS'), '0'); + v_fseconds := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'FRACTSECONDS'), '0'); + + -- v_offhours and v_offminutes will be already set for W3C_XML datetime string format + v_sign := coalesce(v_sign, sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFSIGN'), '+'); + v_offhours := coalesce(v_offhours, sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFHOURS'), '0'); + v_offminutes := coalesce(v_offminutes, sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFMINUTES'), '0'); + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_character_value_for_cast; + END; - WHEN character_not_in_repertoire THEN - RAISE USING MESSAGE := 'The YDM date format isn''t supported when converting from this string format to date.', - DETAIL := 'Use of incorrect DATE_FORMAT constant value regarding string format parameter during conversion process.', - HINT := 'Change DATE_FORMAT constant to one of these values: MDY|DMY|DYM, recompile function and try again.'; + -- validate time and offset + IF ((v_hours::SMALLINT NOT BETWEEN 0 AND 23) OR + (v_minutes::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_seconds::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_offhours::SMALLINT NOT BETWEEN 0 AND 14) OR + (v_offminutes::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_offhours::SMALLINT = 14 AND v_offminutes::SMALLINT != 0)) + THEN + RAISE invalid_character_value_for_cast; + END IF; - WHEN invalid_character_value_for_cast THEN + -- validate date according to gregorian date format + IF ((v_year::SMALLINT NOT BETWEEN 1 AND 9999) OR + (v_month::SMALLINT NOT BETWEEN 1 AND 12) OR + ((v_month::SMALLINT IN (1,3,5,7,8,10,12)) AND (v_day::SMALLINT NOT BETWEEN 1 AND 31)) OR + ((v_month::SMALLINT IN (4,6,9,11)) AND (v_day::SMALLINT NOT BETWEEN 1 AND 30))) + THEN + RAISE invalid_character_value_for_cast; + ELSIF (v_month::SMALLINT = 2) + THEN + -- check for a leap year + IF ((v_year::SMALLINT % 4 = 0) AND ((v_year::SMALLINT % 100 <> 0) or (v_year::SMALLINT % 400 = 0))) + THEN + IF (v_day::SMALLINT NOT BETWEEN 1 AND 29) + THEN + RAISE invalid_character_value_for_cast; + END IF; + ELSE + IF (v_day::SMALLINT NOT BETWEEN 1 AND 28) + THEN + RAISE invalid_character_value_for_cast; + END IF; + END IF; + END IF; + + IF (v_timepart !~* PG_CATALOG.concat('^(', HHMMSSFSOFF_DOT_PART_REGEXP, ')$') AND char_length(v_fseconds) > 3) + THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_timepart !~* PG_CATALOG.concat('^(', HHMMSSFSOFF_DOT_PART_REGEXP, ')$')) THEN + -- if before fractional seconds there is a ':' + v_fseconds := lpad(v_fseconds, 3, '0'); + END IF; + + IF (v_scale = 0) THEN + v_seconds := pg_catalog.concat_ws('.', v_seconds, v_fseconds); + v_seconds := round(v_seconds::NUMERIC, 0)::TEXT; + ELSE + v_fseconds := sys.babelfish_get_microsecs_from_fractsecs_v2(v_fseconds, v_scale); + + -- Following condition will handle overflow of fractsecs + IF (v_fseconds::INTEGER < 0) THEN + v_fseconds := PG_CATALOG.repeat('0', LEAST(v_scale, 6)); + v_seconds := (v_seconds::INTEGER + 1)::TEXT; + END IF; + + v_seconds := pg_catalog.concat_ws('.', v_seconds, v_fseconds); + END IF; + + IF (v_res_datatype = 'DATE') + THEN + v_resdatetime := make_timestamp(v_year::SMALLINT, v_month::SMALLINT, v_day::SMALLINT,0,0,0); + ELSIF (v_res_datatype = 'TIME') + THEN + v_resdatetime := make_timestamp(9999, 12, 31, v_hours::SMALLINT, v_minutes::SMALLINT, v_seconds::NUMERIC); + ELSE + v_resdatetime := make_timestamp(v_year::SMALLINT, v_month::SMALLINT, v_day::SMALLINT, + v_hours::SMALLINT, v_minutes::SMALLINT, v_seconds::NUMERIC); + END IF; + + IF (v_resdatetime > make_timestamp(9999, 12, 31, 23, 59, 59.999999)) THEN + -- if rounding of fractional seconds caused the date and time to go out of range + -- then max date and time that can be stored for p_datatype will be used + v_resdatetime := make_timestamp(9999, 12, 31, 23, 59, pg_catalog.concat_ws('.', '59', PG_CATALOG.repeat('9', LEAST(v_scale, 6)))::NUMERIC); + END IF; + + RETURN v_resdatetime; +EXCEPTION + WHEN most_specific_type_mismatch THEN + RAISE USING MESSAGE := 'Argument data type numeric is invalid for argument 3 of conv_string_to_datetime2 function.', + DETAIL := 'Use of incorrect "style" parameter value during conversion process.', + HINT := 'Change "style" parameter to the proper value and try again.'; + + WHEN invalid_parameter_value THEN + RAISE USING MESSAGE := pg_catalog.format('The style %s is not supported for conversions from varchar to %s.', v_style, PG_CATALOG.lower(v_res_datatype)), + DETAIL := 'Use of incorrect "style" parameter value during conversion process.', + HINT := 'Change "style" parameter to the proper value and try again.'; + + WHEN invalid_regular_expression THEN + RAISE USING MESSAGE := pg_catalog.format('The input character string does not follow style %s, either change the input character string or use a different style.', v_style), + DETAIL := 'Selected "style" param value isn''t valid for conversion of passed character string.', + HINT := 'Either change the input character string or use a different style.'; + + WHEN datatype_mismatch THEN + RAISE USING MESSAGE := 'Data type should be one of these values: ''DATE'', ''TIME''/''TIME(n)'', ''DATETIME2''/''DATETIME2(n)'', ''DATETIMEOFFSET''/''DATETIMEOFFSET(n)''.', + DETAIL := 'Use of incorrect "datatype" parameter value during conversion process.', + HINT := 'Change "datatype" parameter to the proper value and try again.'; + + WHEN invalid_indicator_parameter_value THEN + RAISE USING MESSAGE := pg_catalog.format('CAST or CONVERT: invalid attributes specified for type ''%s''', v_res_datatype), + DETAIL := 'Use of incorrect scale value, which is not corresponding to specified data type.', + HINT := 'Change data type scale component or select different data type and try again.'; + + WHEN interval_field_overflow THEN + RAISE USING MESSAGE := pg_catalog.format('Specified scale %s is invalid.', v_scale), + DETAIL := 'Use of incorrect data type scale value during conversion process.', + HINT := 'Change scale component of data type parameter to be in range [0..7] and try again.'; + + WHEN invalid_datetime_format THEN + RAISE USING MESSAGE := 'Conversion failed when converting date and/or time from character string.', + DETAIL := 'Incorrect using of pair of input parameters values during conversion process.', + HINT := 'Check the input parameters values, correct them if needed, and try again.'; + + WHEN invalid_character_value_for_cast THEN + RAISE USING MESSAGE := pg_catalog.format('The conversion of a varchar data type to a %s data type resulted in an out-of-range value.', PG_CATALOG.lower(v_res_datatype)), + DETAIL := 'Use of incorrect pair of input parameter values during conversion process.', + HINT := 'Check input parameter values, correct them if needed, and try again.'; + + WHEN character_not_in_repertoire THEN + RAISE USING MESSAGE := 'This session''s YDM date format is not supported when converting from this character string format to date, time, datetime2 or datetimeoffset. Change the session''s date format or provide a style to the explicit conversion.', + DETAIL := 'Use of incorrect DATE_FORMAT constant value regarding string format parameter during conversion process.', + HINT := 'Change DATE_FORMAT constant to one of these values: MDY|DMY|DYM, recompile function and try again.'; + + WHEN invalid_escape_sequence THEN RAISE USING MESSAGE := pg_catalog.format('Invalid CONVERSION_LANG constant value - ''%s''. Allowed values are: ''English'', ''Deutsch'', etc.', CONVERSION_LANG), DETAIL := 'Compiled incorrect CONVERSION_LANG constant value in function''s body.', HINT := 'Correct CONVERSION_LANG constant value in function''s body, recompile it and try again.'; - - WHEN invalid_text_representation THEN - GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT; - v_err_message := substring(pg_catalog.lower(v_err_message), 'integer\:\s\"(.*)\"'); - - RAISE USING MESSAGE := pg_catalog.format('Error while trying to convert "%s" value to SMALLINT data type.', - v_err_message), - DETAIL := 'Passed argument value contains illegal characters.', - HINT := 'Correct passed argument value, remove all illegal characters.'; END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; -CREATE OR REPLACE FUNCTION sys.babelfish_conv_string_to_datetime(IN p_datatype TEXT, +-- Following function can be used to convert string literal to DATETIME and SMALLDATETIME +CREATE OR REPLACE FUNCTION sys.babelfish_conv_string_to_datetime_v2(IN p_datatype TEXT, IN p_datetimestring TEXT, IN p_style NUMERIC DEFAULT 0) RETURNS TIMESTAMP WITHOUT TIME ZONE @@ -1222,6 +1489,7 @@ DECLARE v_lang_metadata_json JSONB; v_compmonth_regexp VARCHAR COLLATE "C"; v_resdatetime TIMESTAMP(6) WITHOUT TIME ZONE; + v_language VARCHAR COLLATE "C"; CONVERSION_LANG CONSTANT VARCHAR COLLATE "C" := ''; DATE_FORMAT CONSTANT VARCHAR COLLATE "C" := ''; DAYMM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; @@ -1231,84 +1499,100 @@ DECLARE AMPM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:[AP]M)'; MASKSEP_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:\.|-|/)'; TIMEUNIT_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,2}\s*'; - FRACTSECS_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,9}\s*'; - DATATYPE_REGEXP CONSTANT VARCHAR COLLATE "C" := '^(DATETIME|SMALLDATETIME|DATETIME2)\s*(?:\()?\s*((?:-)?\d+)?\s*(?:\))?$'; - DIGITREPRESENT_REGEXP CONSTANT VARCHAR COLLATE "C" := '^\-?\d+\.?(?:\d+)?$'; - HHMMSSFS_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat(TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + FRACTSECS_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,3}\s*'; + DATATYPE_REGEXP CONSTANT VARCHAR COLLATE "C" := '^(DATETIME|SMALLDATETIME)\s*(?:\()?\s*((?:-)?\d+)?\s*(?:\))?$'; + HHMMSSFS_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat( TIMEUNIT_REGEXP, AMPM_REGEXP, '|', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\.', FRACTSECS_REGEXP, AMPM_REGEXP, '?|', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '(?:\.|\:)', FRACTSECS_REGEXP, AMPM_REGEXP, '?'); - HHMMSSFS_DOT_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat(TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + HHMMSSFS_DOT_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat( TIMEUNIT_REGEXP, AMPM_REGEXP, '|', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\.', FRACTSECS_REGEXP, AMPM_REGEXP, '?|', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '(?:\.)', FRACTSECS_REGEXP, AMPM_REGEXP, '?'); HHMMSSFS_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')$'); - DEFMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', - MASKSEP_REGEXP, '*\s*($comp_month$)\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, + DEFMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '$'); + DEFMASK1_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '$'); + DEFMASK1_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '$'); + DEFMASK2_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + DAYMM_REGEXP, '\s*(?:,|', MASKSEP_REGEXP, ')', '?\s*($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK2_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*(?:,|', MASKSEP_REGEXP, ')', '?\s*($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, '$'); + DEFMASK2_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*(?:,|', MASKSEP_REGEXP, ')', '\s*($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, '$'); + DEFMASK3_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK3_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '$'); + DEFMASK3_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '$'); + DEFMASK3_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,\s*', DAYMM_REGEXP, '$'); + DEFMASK4_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*', '\s*(?:,|', MASKSEP_REGEXP, ')', '?\s*($comp_month$)', '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); - DEFMASK1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '$'); - DEFMASK1_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '$'); - DEFMASK2_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', - DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '*\s*($comp_month$)\s*', COMPYEAR_REGEXP, + DEFMASK4_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*(?:,|', MASKSEP_REGEXP, ')', '?\s*($comp_month$)$'); + DEFMASK4_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*(?:,|', MASKSEP_REGEXP, ')', '\s*($comp_month$)$'); + DEFMASK5_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + DAYMM_REGEXP, '(?:\s+|\s*,\s*)', COMPYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)', '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); - DEFMASK2_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)\s*', COMPYEAR_REGEXP, '$'); - DEFMASK2_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*', COMPYEAR_REGEXP, '$'); - DEFMASK3_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', - FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '*\s*($comp_month$)\s*', DAYMM_REGEXP, - '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); - DEFMASK3_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)\s*', DAYMM_REGEXP, '$'); - DEFMASK3_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*', DAYMM_REGEXP, '$'); - DEFMASK4_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', - FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '*\s*($comp_month$)', - '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); - DEFMASK4_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)$'); - DEFMASK4_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)$'); - DEFMASK5_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', - DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '*\s*($comp_month$)', - '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); - DEFMASK5_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)$'); - DEFMASK5_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)$'); + DEFMASK5_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '(?:\s+|\s*,\s*)', COMPYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)$'); + DEFMASK5_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '(?:\s+|\s*,\s*)', COMPYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)$'); + DEFMASK5_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '(?:\s*,\s*)', COMPYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)$'); DEFMASK6_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', - MASKSEP_REGEXP, '*\s*($comp_month$)\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, - '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); - DEFMASK6_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '$'); - DEFMASK6_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '$'); + MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK6_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '$'); + DEFMASK6_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '$'); + DEFMASK6_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '$'); DEFMASK7_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', - MASKSEP_REGEXP, '*\s*($comp_month$)\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, - '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); - DEFMASK7_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '$'); - DEFMASK7_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '$'); - DEFMASK8_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', - FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '*\s*($comp_month$)', + MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK7_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '$'); + DEFMASK7_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '$'); + DEFMASK7_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '$'); + DEFMASK8_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)', '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); DEFMASK8_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)$'); DEFMASK8_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)$'); DEFMASK9_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', - MASKSEP_REGEXP, '*\s*($comp_month$)\s*', FULLYEAR_REGEXP, - '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); - DEFMASK9_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*', FULLYEAR_REGEXP, '$'); - DEFMASK9_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*', FULLYEAR_REGEXP, '$'); - DEFMASK10_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', + MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK9_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, '$'); + DEFMASK9_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, '$'); + DEFMASK10_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, - '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); DEFMASK10_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '$'); - DOT_SLASH_DASH_COMPYEAR1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', + DEFMASK10_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*-\s*($comp_month$)\s*-\s*', COMPYEAR_REGEXP, '$'); + DEFMASK10_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\/\s*($comp_month$)\s*\/\s*', COMPYEAR_REGEXP, '$'); + DEFMASK10_4_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\.\s*($comp_month$)\s*\.\s*', COMPYEAR_REGEXP, '$'); + DOT_SLASH_DASH_COMPYEAR1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', DAYMM_REGEXP, '\s*(?:\.|/|-)\s*', DAYMM_REGEXP, '\s*(?:\.|/|-)\s*', COMPYEAR_REGEXP, - '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); DOT_SLASH_DASH_COMPYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '$'); DOT_SLASH_DASH_SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', SHORTYEAR_REGEXP, '$'); - DOT_SLASH_DASH_FULLYEAR1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', + DOT_SLASH_DASH_FULLYEAR1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', DAYMM_REGEXP, '\s*(?:\.|/|-)\s*', DAYMM_REGEXP, '\s*(?:\.|/|-)\s*', FULLYEAR_REGEXP, - '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); DOT_SLASH_DASH_FULLYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '$'); - FULLYEAR_DOT_SLASH_DASH1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', + + FULLYEAR_DOT_SLASH_DASH1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, - '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); FULLYEAR_DOT_SLASH_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '$'); - SHORT_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*\d{6}\s*(', HHMMSSFS_PART_REGEXP, ')?$'); - FULL_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*\d{8}\s*(', HHMMSSFS_PART_REGEXP, ')?$'); + + DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '$'); + + FULLYEAR_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*\d{4}\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + SHORT_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*\d{6}\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + FULL_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*\d{8}\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + ISO_8601_DATETIME_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', '(\d{2})', '-', '(\d{2})', 'T', '\d{2}', '\:', '\d{2}', '\:', '\d{2}', '(?:\.', FRACTSECS_REGEXP, ')?','$'); BEGIN v_datatype := pg_catalog.btrim(p_datatype); v_datetimestring := pg_catalog.upper(pg_catalog.btrim(p_datetimestring)); @@ -1321,32 +1605,27 @@ BEGIN IF (v_res_datatype IS NULL) THEN RAISE datatype_mismatch; - ELSIF (v_res_datatype <> 'DATETIME2' AND v_scale IS NOT NULL) + ELSIF (v_scale IS NOT NULL) THEN RAISE invalid_indicator_parameter_value; - ELSIF (coalesce(v_scale, 0) NOT BETWEEN 0 AND 7) - THEN - RAISE interval_field_overflow; ELSIF (v_scale IS NULL) THEN v_scale := 7; END IF; IF (scale(p_style) > 0) THEN RAISE most_specific_type_mismatch; - ELSIF (NOT ((v_style BETWEEN 0 AND 14) OR - (v_style BETWEEN 20 AND 25) OR - (v_style BETWEEN 100 AND 114) OR - (v_style IN (120, 121, 126, 127, 130, 131))) AND - v_res_datatype = 'DATETIME2') - THEN - RAISE invalid_parameter_value; END IF; - v_timepart := pg_catalog.btrim(substring(v_datetimestring, HHMMSSFS_PART_REGEXP)); - v_datestring := pg_catalog.btrim(regexp_replace(v_datetimestring, HHMMSSFS_PART_REGEXP, '', 'gi')); + v_timepart := pg_catalog.btrim(substring(v_datetimestring, PG_CATALOG.concat('(', HHMMSSFS_PART_REGEXP, ')'))); + v_datestring := pg_catalog.btrim(regexp_replace(v_datetimestring, PG_CATALOG.concat('T?', '(', HHMMSSFS_PART_REGEXP, ')'), '', 'gi')); + + v_language := CASE + WHEN (v_style IN (130, 131)) THEN 'HIJRI' + ELSE CONVERSION_LANG + END; BEGIN - v_lang_metadata_json := sys.babelfish_get_lang_metadata_json(CONVERSION_LANG); + v_lang_metadata_json := sys.babelfish_get_lang_metadata_json(v_language); EXCEPTION WHEN OTHERS THEN RAISE invalid_escape_sequence; @@ -1368,23 +1647,7 @@ BEGIN v_datetimestring ~* pg_catalog.replace(DEFMASK9_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR v_datetimestring ~* pg_catalog.replace(DEFMASK10_0_REGEXP, '$comp_month$', v_compmonth_regexp)) THEN - IF ((v_style IN (127, 130, 131) AND v_res_datatype IN ('DATETIME', 'SMALLDATETIME')) OR - (v_style IN (130, 131) AND v_res_datatype = 'DATETIME2')) - THEN - RAISE invalid_datetime_format; - END IF; - - IF ((v_datestring ~* pg_catalog.replace(DEFMASK1_2_REGEXP, '$comp_month$', v_compmonth_regexp) OR - v_datestring ~* pg_catalog.replace(DEFMASK2_2_REGEXP, '$comp_month$', v_compmonth_regexp) OR - v_datestring ~* pg_catalog.replace(DEFMASK3_2_REGEXP, '$comp_month$', v_compmonth_regexp) OR - v_datestring ~* pg_catalog.replace(DEFMASK4_2_REGEXP, '$comp_month$', v_compmonth_regexp) OR - v_datestring ~* pg_catalog.replace(DEFMASK5_2_REGEXP, '$comp_month$', v_compmonth_regexp) OR - v_datestring ~* pg_catalog.replace(DEFMASK6_2_REGEXP, '$comp_month$', v_compmonth_regexp) OR - v_datestring ~* pg_catalog.replace(DEFMASK7_2_REGEXP, '$comp_month$', v_compmonth_regexp) OR - v_datestring ~* pg_catalog.replace(DEFMASK8_2_REGEXP, '$comp_month$', v_compmonth_regexp) OR - v_datestring ~* pg_catalog.replace(DEFMASK9_2_REGEXP, '$comp_month$', v_compmonth_regexp)) AND - v_res_datatype = 'DATETIME2') - THEN + IF (v_style = 127) THEN RAISE invalid_datetime_format; END IF; @@ -1393,6 +1656,12 @@ BEGIN v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK1_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[2]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); + + -- For v_style 130 and 131, 1 or 2 digit year is out of range + IF (v_style IN (130, 131) AND v_regmatch_groups[3]::SMALLINT <= 99) + THEN + RAISE invalid_character_value_for_cast; + END IF; v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK2_1_REGEXP, '$comp_month$', v_compmonth_regexp)) @@ -1400,6 +1669,12 @@ BEGIN v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK2_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[1]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + + -- For v_style 130 and 131, 1 or 2 digit year is out of range + IF (v_style IN (130, 131) AND v_regmatch_groups[3]::SMALLINT <= 99) + THEN + RAISE invalid_character_value_for_cast; + END IF; v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK3_1_REGEXP, '$comp_month$', v_compmonth_regexp)) @@ -1421,6 +1696,12 @@ BEGIN v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK5_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[1]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + + -- For v_style 130 and 131, 1 or 2 digit year is out of range + IF (v_style IN (130, 131) AND v_regmatch_groups[2]::SMALLINT <= 99) + THEN + RAISE invalid_character_value_for_cast; + END IF; v_year := sys.babelfish_get_full_year(v_regmatch_groups[2]); ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK6_1_REGEXP, '$comp_month$', v_compmonth_regexp)) @@ -1435,6 +1716,12 @@ BEGIN v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK7_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[2]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); + + -- For v_style 130 and 131, 1 or 2 digit year is out of range + IF (v_style IN (130, 131) AND v_regmatch_groups[3]::SMALLINT <= 99) + THEN + RAISE invalid_character_value_for_cast; + END IF; v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK8_1_REGEXP, '$comp_month$', v_compmonth_regexp)) @@ -1456,18 +1743,18 @@ BEGIN v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK10_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); v_day := v_regmatch_groups[1]; v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + + -- For v_style 130 and 131, 1 or 2 digit year is out of range + IF (v_style IN (130, 131) AND v_regmatch_groups[3]::SMALLINT <= 99) + THEN + RAISE invalid_character_value_for_cast; + END IF; v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); ELSE RAISE invalid_character_value_for_cast; END IF; ELSIF (v_datetimestring ~* DOT_SLASH_DASH_COMPYEAR1_0_REGEXP) THEN - IF (v_style IN (6, 7, 8, 9, 12, 13, 14, 24, 100, 106, 107, 108, 109, 112, 113, 114, 130) AND - v_res_datatype = 'DATETIME2') - THEN - RAISE invalid_regular_expression; - END IF; - v_regmatch_groups := regexp_matches(v_datestring, DOT_SLASH_DASH_COMPYEAR1_1_REGEXP, 'gi'); v_leftpart := v_regmatch_groups[1]; v_middlepart := v_regmatch_groups[2]; @@ -1475,115 +1762,76 @@ BEGIN IF (v_datestring ~* DOT_SLASH_DASH_SHORTYEAR_REGEXP) THEN - IF ((v_style NOT IN (0, 1, 2, 3, 4, 5, 10, 11) AND v_res_datatype IN ('DATETIME', 'SMALLDATETIME')) OR - (v_style NOT IN (0, 1, 2, 3, 4, 5, 10, 11, 12) AND v_res_datatype = 'DATETIME2')) + IF (v_style NOT IN (0, 1, 2, 3, 4, 5, 10, 11)) THEN RAISE invalid_datetime_format; END IF; - IF ((v_style IN (1, 10) AND v_date_format <> 'MDY' AND v_res_datatype IN ('DATETIME', 'SMALLDATETIME')) OR - (v_style IN (0, 1, 10) AND v_date_format NOT IN ('DMY', 'DYM', 'MYD', 'YMD', 'YDM') AND v_res_datatype IN ('DATETIME', 'SMALLDATETIME')) OR - (v_style IN (0, 1, 10, 22) AND v_date_format NOT IN ('DMY', 'DYM', 'MYD', 'YMD', 'YDM') AND v_res_datatype = 'DATETIME2') OR - (v_style IN (1, 10, 22) AND v_date_format IN ('DMY', 'DYM', 'MYD', 'YMD', 'YDM') AND v_res_datatype = 'DATETIME2')) + IF ((v_style IN (1, 10)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MDY')) THEN v_day := v_middlepart; v_month := v_leftpart; v_year := sys.babelfish_get_full_year(v_rightpart); - ELSIF ((v_style IN (2, 11) AND v_date_format <> 'YMD') OR - (v_style IN (0, 2, 11) AND v_date_format = 'YMD')) + ELSIF ((v_style IN (2, 11)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'YMD')) THEN v_day := v_rightpart; v_month := v_middlepart; v_year := sys.babelfish_get_full_year(v_leftpart); - ELSIF ((v_style IN (3, 4, 5) AND v_date_format <> 'DMY') OR - (v_style IN (0, 3, 4, 5) AND v_date_format = 'DMY')) + ELSIF ((v_style IN (3, 4, 5)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DMY')) THEN v_day := v_leftpart; v_month := v_middlepart; v_year := sys.babelfish_get_full_year(v_rightpart); - ELSIF (v_style = 0 AND v_date_format = 'DYM') + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DYM') THEN v_day = v_leftpart; v_month = v_rightpart; v_year = sys.babelfish_get_full_year(v_middlepart); - ELSIF (v_style = 0 AND v_date_format = 'MYD') + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MYD') THEN v_day := v_rightpart; v_month := v_leftpart; v_year = sys.babelfish_get_full_year(v_middlepart); - ELSIF (v_style = 0 AND v_date_format = 'YDM') + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'YDM') THEN - IF (v_res_datatype = 'DATETIME2') THEN - RAISE character_not_in_repertoire; - END IF; - v_day := v_middlepart; v_month := v_rightpart; v_year := sys.babelfish_get_full_year(v_leftpart); - ELSE - RAISE invalid_character_value_for_cast; END IF; ELSIF (v_datestring ~* DOT_SLASH_DASH_FULLYEAR1_1_REGEXP) THEN - IF (v_style NOT IN (0, 20, 21, 101, 102, 103, 104, 105, 110, 111, 120, 121, 130, 131) AND - v_res_datatype IN ('DATETIME', 'SMALLDATETIME')) + IF (v_style NOT IN (0, 20, 21, 101, 102, 103, 104, 105, 110, 111, 120, 121, 130, 131)) THEN RAISE invalid_datetime_format; - ELSIF (v_style IN (130, 131) AND v_res_datatype = 'SMALLDATETIME') THEN - RAISE invalid_character_value_for_cast; END IF; v_year := v_rightpart; - IF (v_leftpart::SMALLINT <= 12) + IF ((v_style IN (103, 104, 105, 130, 131)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format IN ('DMY', 'DYM', 'YDM'))) THEN - IF ((v_style IN (103, 104, 105, 130, 131) AND v_date_format NOT IN ('DMY', 'DYM', 'YDM')) OR - (v_style IN (0, 103, 104, 105, 130, 131) AND ((v_date_format = 'DMY' AND v_res_datatype = 'DATETIME2') OR - (v_date_format IN ('DMY', 'DYM', 'YDM') AND v_res_datatype <> 'DATETIME2'))) OR - (v_style IN (103, 104, 105, 130, 131) AND v_date_format IN ('DMY', 'DYM', 'YDM') AND v_res_datatype = 'DATETIME2')) - THEN - v_day := v_leftpart; - v_month := v_middlepart; - - ELSIF ((v_style IN (20, 21, 101, 102, 110, 111, 120, 121) AND v_date_format IN ('DMY', 'DYM', 'YDM') AND v_res_datatype IN ('DATETIME', 'SMALLDATETIME')) OR - (v_style IN (0, 20, 21, 101, 102, 110, 111, 120, 121) AND v_date_format NOT IN ('DMY', 'DYM', 'YDM') AND v_res_datatype IN ('DATETIME', 'SMALLDATETIME')) OR - (v_style IN (101, 110) AND v_date_format IN ('DMY', 'DYM', 'MYD', 'YDM') AND v_res_datatype = 'DATETIME2') OR - (v_style IN (0, 101, 110) AND v_date_format NOT IN ('DMY', 'DYM', 'MYD', 'YDM') AND v_res_datatype = 'DATETIME2')) - THEN - v_day := v_middlepart; - v_month := v_leftpart; - END IF; - ELSE - IF ((v_style IN (103, 104, 105, 130, 131) AND v_date_format NOT IN ('DMY', 'DYM', 'YDM')) OR - (v_style IN (0, 103, 104, 105, 130, 131) AND ((v_date_format = 'DMY' AND v_res_datatype = 'DATETIME2') OR - (v_date_format IN ('DMY', 'DYM', 'YDM') AND v_res_datatype <> 'DATETIME2'))) OR - (v_style IN (103, 104, 105, 130, 131) AND v_date_format IN ('DMY', 'DYM', 'YDM') AND v_res_datatype = 'DATETIME2')) - THEN - v_day := v_leftpart; - v_month := v_middlepart; - ELSE - IF (v_res_datatype = 'DATETIME2') THEN - RAISE invalid_datetime_format; - END IF; + v_day := v_leftpart; + v_month := v_middlepart; - RAISE invalid_character_value_for_cast; - END IF; + ELSIF ((v_style IN (20, 21, 101, 102, 110, 111, 120, 121)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format IN ('MDY', 'MYD', 'YMD'))) + THEN + v_day := v_middlepart; + v_month := v_leftpart; END IF; END IF; ELSIF (v_datetimestring ~* FULLYEAR_DOT_SLASH_DASH1_0_REGEXP) THEN - IF (v_style NOT IN (0, 20, 21, 101, 102, 103, 104, 105, 110, 111, 120, 121, 130, 131) AND - v_res_datatype IN ('DATETIME', 'SMALLDATETIME')) + IF (v_style NOT IN (0, 20, 21, 101, 102, 103, 104, 105, 110, 111, 120, 121, 130, 131)) THEN RAISE invalid_datetime_format; - ELSIF (v_style IN (6, 7, 8, 9, 12, 13, 14, 24, 100, 106, 107, 108, 109, 112, 113, 114, 130) AND - v_res_datatype = 'DATETIME2') - THEN - RAISE invalid_regular_expression; ELSIF (v_style IN (130, 131) AND v_res_datatype = 'SMALLDATETIME') THEN RAISE invalid_character_value_for_cast; @@ -1594,39 +1842,49 @@ BEGIN v_middlepart := v_regmatch_groups[2]; v_rightpart := v_regmatch_groups[3]; - IF ((v_res_datatype IN ('DATETIME', 'SMALLDATETIME') AND v_rightpart::SMALLINT <= 12) OR v_res_datatype = 'DATETIME2') + IF ((v_style IN (20, 21, 101, 102, 110, 111, 120, 121)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format IN ('MDY', 'MYD', 'YMD'))) THEN - IF ((v_style IN (20, 21, 101, 102, 110, 111, 120, 121) AND v_date_format IN ('DMY', 'DYM', 'YDM') AND v_res_datatype <> 'DATETIME2') OR - (v_style IN (0, 20, 21, 101, 102, 110, 111, 120, 121) AND v_date_format NOT IN ('DMY', 'DYM', 'YDM') AND v_res_datatype <> 'DATETIME2') OR - (v_style IN (0, 20, 21, 23, 25, 101, 102, 110, 111, 120, 121, 126, 127) AND v_res_datatype = 'DATETIME2')) - THEN - v_day := v_rightpart; - v_month := v_middlepart; + v_day := v_rightpart; + v_month := v_middlepart; - ELSIF ((v_style IN (103, 104, 105, 130, 131) AND v_date_format NOT IN ('DMY', 'DYM', 'YDM')) OR - v_style IN (0, 103, 104, 105, 130, 131) AND v_date_format IN ('DMY', 'DYM', 'YDM')) - THEN - v_day := v_middlepart; - v_month := v_rightpart; - END IF; - ELSIF (v_res_datatype IN ('DATETIME', 'SMALLDATETIME') AND v_rightpart::SMALLINT > 12) + ELSIF ((v_style IN (103, 104, 105, 130, 131)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format IN ('DMY', 'DYM', 'YDM'))) THEN - IF ((v_style IN (20, 21, 101, 102, 110, 111, 120, 121) AND v_date_format IN ('DMY', 'DYM', 'YDM')) OR - (v_style IN (0, 20, 21, 101, 102, 110, 111, 120, 121) AND v_date_format NOT IN ('DMY', 'DYM', 'YDM'))) - THEN - v_day := v_rightpart; - v_month := v_middlepart; + v_day := v_middlepart; + v_month := v_rightpart; + END IF; + ELSIF (v_datetimestring ~* DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_0_REGEXP) + THEN + IF (v_style IS NOT NULL AND v_style != 0) + THEN + RAISE invalid_datetime_format; + ELSIF (v_style IN (130, 131) AND v_res_datatype = 'SMALLDATETIME') + THEN + RAISE invalid_character_value_for_cast; + END IF; - ELSIF ((v_style IN (103, 104, 105, 130, 131) AND v_date_format NOT IN ('DMY', 'DYM', 'YDM')) OR - (v_style IN (0, 103, 104, 105, 130, 131) AND v_date_format IN ('DMY', 'DYM', 'YDM'))) - THEN - RAISE invalid_character_value_for_cast; - END IF; + v_regmatch_groups := regexp_matches(v_datestring, DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_1_REGEXP, 'gi'); + v_leftpart := v_regmatch_groups[1]; + v_year := v_regmatch_groups[2]; + v_rightpart := v_regmatch_groups[3]; + + IF (v_date_format IN ('MYD', 'MDY', 'YMD')) + THEN + v_day := v_rightpart; + v_month := v_leftpart; + ELSIF (v_date_format IN ('DYM', 'DMY', 'YDM')) + THEN + v_day := v_leftpart; + v_month := v_rightpart; + ELSE + RAISE invalid_datetime_format; END IF; - ELSIF (v_datetimestring ~* SHORT_DIGITMASK1_0_REGEXP OR + ELSIF (v_datetimestring ~* FULLYEAR_DIGITMASK1_0_REGEXP OR + v_datetimestring ~* SHORT_DIGITMASK1_0_REGEXP OR v_datetimestring ~* FULL_DIGITMASK1_0_REGEXP) THEN - IF (v_style = 127 AND v_res_datatype <> 'DATETIME2') + IF (v_style = 127 AND v_datestring !~* '^\d{4}$') THEN RAISE invalid_datetime_format; ELSIF (v_style IN (130, 131) AND v_res_datatype = 'SMALLDATETIME') @@ -1634,7 +1892,13 @@ BEGIN RAISE invalid_character_value_for_cast; END IF; - IF (v_datestring ~* '^\d{6}$') + IF (v_datestring ~* '^\d{4}$') + THEN + v_day := '01'; + v_month := '01'; + v_year := substr(v_datestring, 1, 4); + + ELSIF (v_datestring ~* '^\d{6}$') THEN v_day := substr(v_datestring, 5, 2); v_month := substr(v_datestring, 3, 2); @@ -1646,99 +1910,175 @@ BEGIN v_month := substr(v_datestring, 5, 2); v_year := substr(v_datestring, 1, 4); END IF; - ELSIF (v_datetimestring ~* HHMMSSFS_REGEXP) + ELSIF (v_datetimestring ~* HHMMSSFS_REGEXP OR length(v_datetimestring) = 0) THEN v_day := '01'; v_month := '01'; v_year := '1900'; - ELSIF (v_datetimestring ~* DIGITREPRESENT_REGEXP) + ELSIF (v_datetimestring ~* ISO_8601_DATETIME_REGEXP) THEN - v_resdatetime = CAST('1900-01-01 00:00:00.0' AS sys.DATETIME) + v_datetimestring::NUMERIC; - RETURN v_resdatetime; + IF (v_style IN (130, 131)) + THEN + RAISE invalid_character_value_for_cast; + END IF; + v_regmatch_groups := regexp_matches(v_datetimestring, ISO_8601_DATETIME_REGEXP, 'gi'); + + v_day := v_regmatch_groups[3]; + v_month := v_regmatch_groups[2]; + v_year := v_regmatch_groups[1]; ELSE RAISE invalid_datetime_format; END IF; - IF (((v_datetimestring ~* HHMMSSFS_PART_REGEXP AND v_res_datatype = 'DATETIME2') OR - (v_datetimestring ~* SHORT_DIGITMASK1_0_REGEXP OR v_datetimestring ~* FULL_DIGITMASK1_0_REGEXP OR - v_datetimestring ~* FULLYEAR_DOT_SLASH_DASH1_0_REGEXP OR v_datetimestring ~* DOT_SLASH_DASH_FULLYEAR1_0_REGEXP)) AND + -- DATETIME/SMALLDATETIME supports time part in either left or right side of date part, + -- but having time on both side of date part should throw error + IF ((SELECT COUNT(*) FROM regexp_matches(v_datetimestring, HHMMSSFS_PART_REGEXP)) > 1) + THEN + RAISE invalid_character_value_for_cast; + END IF; + + IF ((v_datetimestring !~* HHMMSSFS_REGEXP AND + length(v_datetimestring) != 0) AND v_style IN (130, 131)) THEN + -- validate date according to hijri date format + IF ((v_month::SMALLINT NOT BETWEEN 1 AND 12) OR + (v_day::SMALLINT NOT BETWEEN 1 AND 30) OR + ((MOD(v_month::SMALLINT, 2) = 0 AND v_month::SMALLINT != 12) AND v_day::SMALLINT = 30)) + THEN + RAISE invalid_character_value_for_cast; + END IF; + + -- for hijri leap year + IF (v_month::SMALLINT = 12) + THEN + -- check for a leap year + IF (MOD(v_year::SMALLINT, 30) IN (2, 5, 7, 10, 13, 16, 18, 21, 24, 26, 29)) + THEN + IF (v_day::SMALLINT NOT BETWEEN 1 AND 30) + THEN + RAISE invalid_character_value_for_cast; + END IF; + ELSE + IF (v_day::SMALLINT NOT BETWEEN 1 AND 29) + THEN + RAISE invalid_character_value_for_cast; + END IF; + END IF; + END IF; + v_hijridate := sys.babelfish_conv_hijri_to_greg(v_day, v_month, v_year) - 1; v_day = to_char(v_hijridate, 'DD'); v_month = to_char(v_hijridate, 'MM'); v_year = to_char(v_hijridate, 'YYYY'); END IF; - v_hours := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'HOURS'), '0'); - v_minutes := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'MINUTES'), '0'); - v_seconds := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'SECONDS'), '0'); - v_fseconds := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'FRACTSECONDS'), '0'); - - IF ((v_res_datatype IN ('DATETIME', 'SMALLDATETIME') OR - (v_res_datatype = 'DATETIME2' AND v_timepart !~* HHMMSSFS_DOT_PART_REGEXP)) AND - char_length(v_fseconds) > 3) + BEGIN + v_hours := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'HOURS'), '0'); + v_minutes := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'MINUTES'), '0'); + v_seconds := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'SECONDS'), '0'); + v_fseconds := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'FRACTSECONDS'), '0'); + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_character_value_for_cast; + END; + + -- validate time + IF ((v_hours::SMALLINT NOT BETWEEN 0 AND 23) OR + (v_minutes::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_seconds::SMALLINT NOT BETWEEN 0 AND 59)) THEN - RAISE invalid_datetime_format; + RAISE invalid_character_value_for_cast; END IF; - BEGIN - IF (v_res_datatype IN ('DATETIME', 'SMALLDATETIME')) + -- validate date according to gregorian date format + IF ((v_year::SMALLINT NOT BETWEEN 1 AND 9999) OR + (v_month::SMALLINT NOT BETWEEN 1 AND 12) OR + ((v_month::SMALLINT IN (1,3,5,7,8,10,12)) AND (v_day::SMALLINT NOT BETWEEN 1 AND 31)) OR + ((v_month::SMALLINT IN (4,6,9,11)) AND (v_day::SMALLINT NOT BETWEEN 1 AND 30)) OR + ((v_res_datatype = 'DATETIME') AND (v_year::SMALLINT NOT BETWEEN 1753 AND 9999)) OR + ((v_res_datatype = 'SMALLDATETIME') AND + ((v_year::SMALLINT NOT BETWEEN 1900 AND 2079) OR + (v_year::SMALLINT = 2079 AND + ((v_month::SMALLINT NOT BETWEEN 1 AND 6) OR (v_day::SMALLINT NOT BETWEEN 1 AND 6)))))) + THEN + RAISE invalid_character_value_for_cast; + ELSIF (v_month::SMALLINT = 2) + THEN + -- check for a leap year + IF ((v_year::SMALLINT % 4 = 0) AND ((v_year::SMALLINT % 100 <> 0) or (v_year::SMALLINT % 400 = 0))) THEN - v_resdatetime := sys.datetimefromparts(v_year, v_month, v_day, - v_hours, v_minutes, v_seconds, - rpad(v_fseconds, 3, '0')); - IF (v_res_datatype = 'SMALLDATETIME' AND - to_char(v_resdatetime, 'SS') <> '00') + IF (v_day::SMALLINT NOT BETWEEN 1 AND 29) THEN - IF (to_char(v_resdatetime, 'SS')::SMALLINT >= 30) THEN - v_resdatetime := v_resdatetime + INTERVAL '1 minute'; - END IF; - - v_resdatetime := to_timestamp(to_char(v_resdatetime, 'DD.MM.YYYY.HH24.MI'), 'DD.MM.YYYY.HH24.MI'); + RAISE invalid_character_value_for_cast; + END IF; + ELSE + IF (v_day::SMALLINT NOT BETWEEN 1 AND 28) + THEN + RAISE invalid_character_value_for_cast; END IF; - ELSIF (v_res_datatype = 'DATETIME2') - THEN - v_fseconds := sys.babelfish_get_microsecs_from_fractsecs(v_fseconds, v_scale); - v_seconds := pg_catalog.concat_ws('.', v_seconds, v_fseconds); - v_resdatetime := make_timestamp(v_year::SMALLINT, v_month::SMALLINT, v_day::SMALLINT, - v_hours::SMALLINT, v_minutes::SMALLINT, v_seconds::NUMERIC); - END IF; - EXCEPTION - WHEN datetime_field_overflow THEN - RAISE invalid_datetime_format; - WHEN OTHERS THEN - GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT; - - IF (v_err_message ~* 'Cannot construct data type') THEN - RAISE invalid_character_value_for_cast; END IF; - END; + END IF; - RETURN v_resdatetime; + -- validate boundary condition for date and time + IF ((v_res_datatype = 'SMALLDATETIME' AND + (v_year::SMALLINT = 2079 AND v_month::SMALLINT = 6 AND v_day::SMALLINT = 6 AND + v_hours::SMALLINT = 23 AND v_minutes::SMALLINT = 59 AND + (v_seconds::SMALLINT > 29 OR (v_seconds::SMALLINT = 29 AND v_fseconds::SMALLINT > 998)))) OR + (v_res_datatype = 'DATETIME' AND + (v_year::SMALLINT = 9999 AND v_month::SMALLINT = 12 AND v_day::SMALLINT = 31 AND + v_hours::SMALLINT = 23 AND v_minutes::SMALLINT = 59 AND v_seconds::SMALLINT = 59 AND v_fseconds::SMALLINT > 998)) + ) + THEN + RAISE invalid_character_value_for_cast; + END IF; + + IF (v_timepart ~* PG_CATALOG.concat('^(', HHMMSSFS_DOT_PART_REGEXP, ')$')) THEN + -- if before fractional seconds there is a '.' + v_resdatetime := sys.datetimefromparts(v_year, v_month, v_day, + v_hours, v_minutes, v_seconds, + rpad(v_fseconds, 3, '0')); + ELSE + -- if before fractional seconds there is a ':' + v_resdatetime := sys.datetimefromparts(v_year, v_month, v_day, + v_hours, v_minutes, v_seconds, + lpad(v_fseconds, 3, '0')); + END IF; + + IF (v_res_datatype = 'SMALLDATETIME' AND + to_char(v_resdatetime, 'SS') <> '00') + THEN + IF (to_char(v_resdatetime, 'SS')::SMALLINT >= 30) THEN + v_resdatetime := v_resdatetime + INTERVAL '1 minute'; + END IF; + + v_resdatetime := to_timestamp(to_char(v_resdatetime, 'DD.MM.YYYY.HH24.MI'), 'DD.MM.YYYY.HH24.MI'); + END IF; + + RETURN v_resdatetime; EXCEPTION WHEN most_specific_type_mismatch THEN - RAISE USING MESSAGE := 'Argument data type NUMERIC is invalid for argument 3 of conv_string_to_datetime function.', + RAISE USING MESSAGE := 'Argument data type numeric is invalid for argument 3 of convert function.', DETAIL := 'Use of incorrect "style" parameter value during conversion process.', HINT := 'Change "style" parameter to the proper value and try again.'; WHEN invalid_parameter_value THEN - RAISE USING MESSAGE := pg_catalog.format('The style %s is not supported for conversions from VARCHAR to %s.', v_style, v_res_datatype), + RAISE USING MESSAGE := pg_catalog.format('The style %s is not supported for conversions from varchar to %s.', v_style, PG_CATALOG.lower(v_res_datatype)), DETAIL := 'Use of incorrect "style" parameter value during conversion process.', HINT := 'Change "style" parameter to the proper value and try again.'; WHEN invalid_regular_expression THEN - RAISE USING MESSAGE := pg_catalog.format('The input character string doesn''t follow style %s.', v_style), + RAISE USING MESSAGE := pg_catalog.format('The input character string does not follow style %s, either change the input character string or use a different style.', v_style), DETAIL := 'Selected "style" param value isn''t valid for conversion of passed character string.', HINT := 'Either change the input character string or use a different style.'; WHEN datatype_mismatch THEN - RAISE USING MESSAGE := 'Data type should be one of these values: ''DATETIME'', ''SMALLDATETIME'', ''DATETIME2''/''DATETIME2(n)''.', + RAISE USING MESSAGE := 'Data type should be one of these values: ''DATETIME'', ''SMALLDATETIME''.', DETAIL := 'Use of incorrect "datatype" parameter value during conversion process.', HINT := 'Change "datatype" parameter to the proper value and try again.'; WHEN invalid_indicator_parameter_value THEN - RAISE USING MESSAGE := pg_catalog.format('Invalid attributes specified for data type %s.', v_res_datatype), + RAISE USING MESSAGE := pg_catalog.format('CAST or CONVERT: invalid attributes specified for type ''%s''', PG_CATALOG.lower(v_res_datatype)), DETAIL := 'Use of incorrect scale value, which is not corresponding to specified data type.', HINT := 'Change data type scale component or select different data type and try again.'; @@ -1749,22 +2089,17 @@ EXCEPTION WHEN invalid_datetime_format THEN RAISE USING MESSAGE := CASE v_res_datatype - WHEN 'SMALLDATETIME' THEN 'Conversion failed when converting character string to SMALLDATETIME data type.' - ELSE 'Conversion failed when converting date and time from character string.' + WHEN 'SMALLDATETIME' THEN 'Conversion failed when converting character string to smalldatetime data type.' + ELSE 'Conversion failed when converting date and/or time from character string.' END, DETAIL := 'Incorrect using of pair of input parameters values during conversion process.', HINT := 'Check the input parameters values, correct them if needed, and try again.'; WHEN invalid_character_value_for_cast THEN - RAISE USING MESSAGE := 'The conversion of a VARCHAR data type to a DATETIME data type resulted in an out-of-range value.', + RAISE USING MESSAGE := pg_catalog.format('The conversion of a varchar data type to a %s data type resulted in an out-of-range value.', PG_CATALOG.lower(v_res_datatype)), DETAIL := 'Use of incorrect pair of input parameter values during conversion process.', HINT := 'Check input parameter values, correct them if needed, and try again.'; - WHEN character_not_in_repertoire THEN - RAISE USING MESSAGE := 'The YDM date format isn''t supported when converting from this string format to date and time.', - DETAIL := 'Use of incorrect DATE_FORMAT constant value regarding string format parameter during conversion process.', - HINT := 'Change DATE_FORMAT constant to one of these values: MDY|DMY|DYM, recompile function and try again.'; - WHEN invalid_escape_sequence THEN RAISE USING MESSAGE := pg_catalog.format('Invalid CONVERSION_LANG constant value - ''%s''. Allowed values are: ''English'', ''Deutsch'', etc.', CONVERSION_LANG), @@ -1782,158 +2117,92 @@ EXCEPTION END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; -CREATE OR REPLACE FUNCTION sys.babelfish_conv_string_to_time(IN p_datatype TEXT, - IN p_timestring TEXT, - IN p_style NUMERIC DEFAULT 0) -RETURNS TIME WITHOUT TIME ZONE +-- Following function can be used to convert string literal to DATETIMEOFFSET +CREATE OR REPLACE FUNCTION sys.babelfish_conv_string_to_datetimeoffset(IN p_datatype TEXT, + IN p_datetimestring TEXT, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET AS $BODY$ DECLARE - v_hours SMALLINT; - v_style SMALLINT; - v_scale SMALLINT; - v_daypart VARCHAR COLLATE "C"; - v_seconds VARCHAR COLLATE "C"; - v_minutes SMALLINT; - v_fseconds VARCHAR COLLATE "C"; - v_datatype VARCHAR COLLATE "C"; - v_timestring VARCHAR COLLATE "C"; - v_err_message VARCHAR COLLATE "C"; - v_src_datatype VARCHAR COLLATE "C"; - v_timeunit_mask VARCHAR COLLATE "C"; - v_datatype_groups TEXT[]; + v_sign VARCHAR COLLATE "C"; + v_offhours VARCHAR COLLATE "C"; + v_offminutes VARCHAR COLLATE "C"; + v_timepart VARCHAR COLLATE "C"; + v_datestring VARCHAR COLLATE "C"; + v_datetimestring VARCHAR COLLATE "C"; v_regmatch_groups TEXT[]; - AMPM_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*([AP]M)'; - TIMEUNIT_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(\d{1,2})\s*'; - FRACTSECS_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(\d{1,9})'; - HHMMSSFS_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', TIMEUNIT_REGEXP, - '\:', TIMEUNIT_REGEXP, - '\:', TIMEUNIT_REGEXP, - '(?:\.|\:)', FRACTSECS_REGEXP, '$'); - HHMMSS_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '$'); - HHMMFS_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\.', FRACTSECS_REGEXP, '$'); - HHMM_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '$'); - HH_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', TIMEUNIT_REGEXP, '$'); - DATATYPE_REGEXP CONSTANT VARCHAR COLLATE "C" := '^(TIME)\s*(?:\()?\s*((?:-)?\d+)?\s*(?:\))?$'; + v_resdatetime TIMESTAMP(6) WITHOUT TIME ZONE; + v_resdatetime_string VARCHAR COLLATE "C"; + DAYMM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; + FULLYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{4})'; + AMPM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:[AP]M)'; + TIMEUNIT_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,2}\s*'; + FRACTSECS_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,9}\s*'; + TIME_OFFSET_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('\s*((\-|\+)\s*(', TIMEUNIT_REGEXP, ')\s*\:\s*(', TIMEUNIT_REGEXP, ')|Z)\s*'); + HHMMSSFSOFF_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('(', TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '(?:\.|\:)', FRACTSECS_REGEXP, AMPM_REGEXP, '?)(', TIME_OFFSET_REGEXP, ')?'); + W3C_XML_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, '(', '(\-|\+)', '\s*(\d{2})\s*', '\:', '\s*(\d{2})\s*', '|', 'Z', ')','$'); + W3C_XML_Z_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, 'Z','$'); BEGIN - v_datatype := pg_catalog.btrim(regexp_replace(p_datatype COLLATE "C", 'DATETIME', 'TIME', 'gi')); - v_timestring := pg_catalog.upper(pg_catalog.btrim(p_timestring)); - v_style := floor(p_style)::SMALLINT; - - v_datatype_groups := regexp_matches(v_datatype, DATATYPE_REGEXP, 'gi'); - - v_src_datatype := pg_catalog.upper(v_datatype_groups[1]); - v_scale := v_datatype_groups[2]::SMALLINT; + v_datetimestring := pg_catalog.upper(pg_catalog.trim(p_datetimestring)); + -- datetimestring validation and conversion will be done in babelfish_conv_string_to_datetime2 function and a timestamp will be returned + v_resdatetime := sys.babelfish_conv_string_to_datetime2(p_datatype, p_datetimestring, p_style); - IF (v_src_datatype IS NULL) THEN - RAISE datatype_mismatch; - ELSIF (coalesce(v_scale, 0) NOT BETWEEN 0 AND 7) - THEN - RAISE interval_field_overflow; - ELSIF (v_scale IS NULL) THEN - v_scale := 7; - END IF; + v_timepart := pg_catalog.btrim(substring(v_datetimestring, PG_CATALOG.concat('(', HHMMSSFSOFF_PART_REGEXP, ')'))); + v_datestring := pg_catalog.btrim(regexp_replace(v_datetimestring, PG_CATALOG.concat('T?', '(', HHMMSSFSOFF_PART_REGEXP, ')'), '', 'gi')); - IF (scale(p_style) > 0) THEN - RAISE most_specific_type_mismatch; - ELSIF (NOT ((v_style BETWEEN 0 AND 14) OR - (v_style BETWEEN 20 AND 25) OR - (v_style BETWEEN 100 AND 114) OR - v_style IN (120, 121, 126, 127, 130, 131))) + -- Get the time offset value + IF (v_datetimestring ~* W3C_XML_REGEXP) THEN - RAISE invalid_parameter_value; - END IF; - - v_daypart := substring(v_timestring, 'AM|PM'); - v_timestring := pg_catalog.btrim(regexp_replace(v_timestring, coalesce(v_daypart, ''), '')); + v_regmatch_groups := regexp_matches(v_datetimestring, W3C_XML_REGEXP, 'gi'); - v_timeunit_mask := - CASE - WHEN (v_timestring ~* HHMMSSFS_REGEXP) THEN HHMMSSFS_REGEXP - WHEN (v_timestring ~* HHMMSS_REGEXP) THEN HHMMSS_REGEXP - WHEN (v_timestring ~* HHMMFS_REGEXP) THEN HHMMFS_REGEXP - WHEN (v_timestring ~* HHMM_REGEXP) THEN HHMM_REGEXP - WHEN (v_timestring ~* HH_REGEXP) THEN HH_REGEXP + IF (v_datetimestring !~* W3C_XML_Z_REGEXP) + THEN + v_sign := v_regmatch_groups[5]; + v_offhours := v_regmatch_groups[6]; + v_offminutes := v_regmatch_groups[7]; + ELSE + v_sign := '+'; + v_offhours := '0'; + v_offminutes := '0'; + END IF; + ELSE + BEGIN + v_sign := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFSIGN'), '+'); + v_offhours := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFHOURS'), '0'); + v_offminutes := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFMINUTES'), '0'); + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_character_value_for_cast; END; - - IF (v_timeunit_mask IS NULL) THEN - RAISE invalid_datetime_format; END IF; - v_regmatch_groups := regexp_matches(v_timestring, v_timeunit_mask, 'gi'); - - v_hours := v_regmatch_groups[1]::SMALLINT; - v_minutes := v_regmatch_groups[2]::SMALLINT; - - IF (v_timestring ~* HHMMFS_REGEXP) THEN - v_fseconds := v_regmatch_groups[3]; - ELSE - v_seconds := v_regmatch_groups[3]; - v_fseconds := v_regmatch_groups[4]; + -- validate offset + IF ((v_offhours::SMALLINT NOT BETWEEN 0 AND 14) OR + (v_offminutes::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_offhours::SMALLINT = 14 AND v_offminutes::SMALLINT != 0)) + THEN + RAISE invalid_character_value_for_cast; END IF; - IF (v_daypart IS NOT NULL) THEN - IF ((v_daypart = 'AM' AND v_hours NOT BETWEEN 0 AND 12) OR - (v_daypart = 'PM' AND v_hours NOT BETWEEN 1 AND 23)) - THEN - RAISE numeric_value_out_of_range; - ELSIF (v_daypart = 'PM' AND v_hours < 12) THEN - v_hours := v_hours + 12; - ELSIF (v_daypart = 'AM' AND v_hours = 12) THEN - v_hours := v_hours - 12; - END IF; - END IF; - - v_fseconds := sys.babelfish_get_microsecs_from_fractsecs(v_fseconds, v_scale); - v_seconds := pg_catalog.concat_ws('.', v_seconds, v_fseconds); + v_resdatetime_string := PG_CATALOG.concat(v_resdatetime::PG_CATALOG.TEXT,v_sign,v_offhours,':',v_offminutes); - RETURN make_time(v_hours, v_minutes, v_seconds::NUMERIC); + RETURN CAST(v_resdatetime_string AS sys.datetimeoffset); EXCEPTION - WHEN most_specific_type_mismatch THEN - RAISE USING MESSAGE := 'Argument data type NUMERIC is invalid for argument 3 of conv_string_to_time function.', - DETAIL := 'Use of incorrect "style" parameter value during conversion process.', - HINT := 'Change "style" parameter to the proper value and try again.'; - - WHEN invalid_parameter_value THEN - RAISE USING MESSAGE := pg_catalog.format('The style %s is not supported for conversions from VARCHAR to TIME.', v_style), - DETAIL := 'Use of incorrect "style" parameter value during conversion process.', - HINT := 'Change "style" parameter to the proper value and try again.'; - - WHEN datatype_mismatch THEN - RAISE USING MESSAGE := 'Source data type should be ''TIME'' or ''TIME(n)''.', - DETAIL := 'Use of incorrect "datatype" parameter value during conversion process.', - HINT := 'Change "datatype" parameter to the proper value and try again.'; - - WHEN interval_field_overflow THEN - RAISE USING MESSAGE := pg_catalog.format('Specified scale %s is invalid.', v_scale), - DETAIL := 'Use of incorrect data type scale value during conversion process.', - HINT := 'Change scale component of data type parameter to be in range [0..7] and try again.'; - - WHEN numeric_value_out_of_range THEN - RAISE USING MESSAGE := 'Could not extract correct hour value due to it''s inconsistency with AM|PM day part mark.', - DETAIL := 'Extracted hour value doesn''t fall in correct day part mark range: 0..12 for "AM" or 1..23 for "PM".', - HINT := 'Correct a hour value in the source string or remove AM|PM day part mark out of it.'; - - WHEN invalid_datetime_format THEN - RAISE USING MESSAGE := 'Conversion failed when converting time from character string.', - DETAIL := 'Incorrect using of pair of input parameters values during conversion process.', - HINT := 'Check the input parameters values, correct them if needed, and try again.'; - - WHEN invalid_text_representation THEN - GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT; - v_err_message := substring(pg_catalog.lower(v_err_message), 'integer\:\s\"(.*)\"'); - - RAISE USING MESSAGE := pg_catalog.format('Error while trying to convert "%s" value to SMALLINT data type.', - v_err_message), - DETAIL := 'Supplied value contains illegal characters.', - HINT := 'Correct supplied value, remove all illegal characters.'; + WHEN invalid_character_value_for_cast THEN + RAISE USING MESSAGE := 'The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.', + DETAIL := 'Use of incorrect pair of input parameter values during conversion process.', + HINT := 'Check input parameter values, correct them if needed, and try again.'; END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; CREATE OR REPLACE FUNCTION sys.babelfish_conv_time_to_string(IN p_datatype TEXT, @@ -2023,7 +2292,13 @@ BEGIN END IF; v_hours := PG_CATALOG.ltrim(to_char(p_timeval, 'HH12'), '0'); - v_fseconds := sys.babelfish_get_microsecs_from_fractsecs(to_char(p_timeval, 'US'), v_scale); + v_fseconds := sys.babelfish_get_microsecs_from_fractsecs_v2(to_char(p_timeval, 'US'), v_scale); + + -- Following condition will handle overflow of fractsecs + IF (v_fseconds::INTEGER < 0) THEN + v_fseconds := PG_CATALOG.repeat('0', LEAST(v_scale, 6)); + p_timeval := p_timeval + INTERVAL '1 second'; + END IF; IF (v_scale = 7) THEN v_fseconds := pg_catalog.concat(v_fseconds, '0'); @@ -2203,7 +2478,7 @@ EXCEPTION END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; CREATE OR REPLACE FUNCTION sys.babelfish_get_int_part(IN p_srcnumber DOUBLE PRECISION) @@ -2218,7 +2493,7 @@ BEGIN END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; CREATE OR REPLACE FUNCTION sys.babelfish_get_jobs () @@ -2367,7 +2642,11 @@ $BODY$ LANGUAGE plpgsql STABLE; -CREATE OR REPLACE FUNCTION sys.babelfish_get_microsecs_from_fractsecs(IN p_fractsecs TEXT, +/* + * Following function sys.babelfish_get_microsecs_from_fractsecs_v2 rounds off p_fractsecs to the given scale + * if result overflows then return -1 + */ +CREATE OR REPLACE FUNCTION sys.babelfish_get_microsecs_from_fractsecs_v2(IN p_fractsecs TEXT, IN p_scale NUMERIC DEFAULT 7) RETURNS VARCHAR AS @@ -2396,9 +2675,13 @@ BEGIN v_decplaces := v_fractsecs_len - v_pureplaces_len; - v_rnd_fractsecs := round(v_fractsecs::INTEGER, (v_pureplaces_len - (v_scale - (v_fractsecs_len - v_pureplaces_len))) * (-1)); + v_rnd_fractsecs := round(v_fractsecs::INTEGER, (v_pureplaces_len - (v_scale - v_decplaces)) * (-1)); + + IF (char_length(v_rnd_fractsecs::TEXT) > v_fractsecs_len) THEN + RETURN '-1'; + END IF; - v_fractsecs := pg_catalog.concat(pg_catalog.replace(rpad('', v_decplaces), ' ', '0'), v_rnd_fractsecs); + v_fractsecs := lpad(v_rnd_fractsecs::TEXT, v_fractsecs_len, '0'); RETURN substring(v_fractsecs, 1, CASE WHEN (v_scale >= 7) THEN 6 @@ -2415,7 +2698,7 @@ EXCEPTION END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; CREATE OR REPLACE FUNCTION sys.babelfish_get_monthnum_by_name(IN p_monthname TEXT, @@ -2489,8 +2772,12 @@ DECLARE v_minutes VARCHAR COLLATE "C"; v_seconds VARCHAR COLLATE "C"; v_fractsecs VARCHAR COLLATE "C"; + v_sign VARCHAR COLLATE "C"; + v_offhours VARCHAR COLLATE "C"; + v_offminutes VARCHAR COLLATE "C"; v_daypart VARCHAR COLLATE "C"; v_timepart VARCHAR COLLATE "C"; + v_offset VARCHAR COLLATE "C"; v_timeunit VARCHAR COLLATE "C"; v_err_message VARCHAR COLLATE "C"; v_timeunit_mask VARCHAR COLLATE "C"; @@ -2498,6 +2785,7 @@ DECLARE AMPM_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*([AP]M)'; TIMEUNIT_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(\d{1,2})\s*'; FRACTSECS_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(\d{1,9})'; + TIME_OFFSET_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('((\-|\+)', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '|Z)'); HHMMSSFS_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, @@ -2510,8 +2798,10 @@ BEGIN v_timepart := pg_catalog.upper(pg_catalog.btrim(p_timepart)); v_timeunit := pg_catalog.upper(pg_catalog.btrim(p_timeunit)); - v_daypart := substring(v_timepart, 'AM|PM'); - v_timepart := pg_catalog.btrim(regexp_replace(v_timepart, coalesce(v_daypart, ''), '')); + v_daypart := substring(v_timepart, AMPM_REGEXP); + v_offset := substring(v_timepart, TIME_OFFSET_REGEXP); + v_timepart := pg_catalog.btrim(regexp_replace(v_timepart, AMPM_REGEXP, '')); + v_timepart := pg_catalog.btrim(regexp_replace(v_timepart, TIME_OFFSET_REGEXP, '')); v_timeunit_mask := CASE @@ -2533,6 +2823,12 @@ BEGIN v_seconds := v_regmatch_groups[3]; v_fractsecs := v_regmatch_groups[4]; END IF; + + v_regmatch_groups := regexp_matches(v_offset, TIME_OFFSET_REGEXP, 'gi'); + + v_sign := coalesce(v_regmatch_groups[2], '+'); + v_offhours := coalesce(v_regmatch_groups[3], '0'); + v_offminutes := coalesce(v_regmatch_groups[4], '0'); IF (v_timeunit = 'HOURS' AND v_daypart IS NOT NULL) THEN @@ -2552,6 +2848,9 @@ BEGIN WHEN 'MINUTES' THEN v_minutes WHEN 'SECONDS' THEN v_seconds WHEN 'FRACTSECONDS' THEN v_fractsecs + WHEN 'OFFHOURS' THEN v_offhours + WHEN 'OFFMINUTES' THEN v_offminutes + WHEN 'OFFSIGN' THEN v_sign END; EXCEPTION WHEN numeric_value_out_of_range THEN @@ -4706,11 +5005,24 @@ BEGIN v_res_datetime := to_timestamp(to_char(v_res_datetime, 'DD.MM.YYYY.HH24.MI'), 'DD.MM.YYYY.HH24.MI'); END IF; ELSE - v_fseconds := sys.babelfish_get_microsecs_from_fractsecs(rpad(v_fseconds, 9, '0'), v_scale); + v_fseconds := sys.babelfish_get_microsecs_from_fractsecs_v2(rpad(v_fseconds, 9, '0'), v_scale); + + -- Following condition will handle overflow of fractsecs + IF (v_fseconds::INTEGER < 0) THEN + v_fseconds := PG_CATALOG.repeat('0', LEAST(v_scale, 6)); + v_seconds := (v_seconds::INTEGER + 1)::TEXT; + END IF; + v_seconds := pg_catalog.concat_ws('.', v_seconds, v_fseconds); v_res_datetime := make_timestamp(v_year, v_month::SMALLINT, v_day::SMALLINT, v_hours, v_minutes, v_seconds::NUMERIC); + + IF (v_res_datetime > make_timestamp(9999, 12, 31, 23, 59, 59.999999)) THEN + -- if rounding of fractional seconds caused the date and time to go out of range + -- then max date and time that can be stored for p_datatype will be used + v_res_datetime := make_timestamp(9999, 12, 31, 23, 59, pg_catalog.concat_ws('.', '59', PG_CATALOG.repeat('9', LEAST(v_scale, 6)))::NUMERIC); + END IF; END IF; EXCEPTION WHEN OTHERS THEN @@ -5756,11 +6068,23 @@ BEGIN v_hours := 12; END IF; - v_fseconds := sys.babelfish_get_microsecs_from_fractsecs(rpad(v_fseconds, 9, '0'), v_scale); + v_fseconds := sys.babelfish_get_microsecs_from_fractsecs_v2(rpad(v_fseconds, 9, '0'), v_scale); + -- Following condition will handle overflow of fractsecs + IF (v_fseconds::INTEGER < 0) THEN + v_fseconds := PG_CATALOG.repeat('0', LEAST(v_scale, 6)); + v_seconds := (v_seconds::INTEGER + 1)::TEXT; + END IF; + v_seconds := pg_catalog.concat_ws('.', v_seconds, v_fseconds); v_res_time := make_time(v_hours, v_minutes, v_seconds::NUMERIC); + IF (v_res_time > make_time(23, 59, 59.999999)) THEN + -- if rounding of fractional seconds caused the time to go out of range + -- then max time that can be stored for time will be used + v_res_time := make_time(23, 59, pg_catalog.concat_ws('.', '59', PG_CATALOG.repeat('9', LEAST(v_scale, 6)))::NUMERIC); + END IF; + RETURN v_res_time; EXCEPTION WHEN invalid_datetime_format OR datetime_field_overflow THEN @@ -9448,31 +9772,33 @@ LANGUAGE plpgsql STABLE RETURNS NULL ON NULL INPUT; -CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_string_to_date(IN p_datestring TEXT, - IN p_style NUMERIC DEFAULT 0) -RETURNS DATE +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_string_to_datetime2(IN p_datatype TEXT, + IN p_datetimestring TEXT, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIMESTAMP WITHOUT TIME ZONE AS $BODY$ BEGIN - RETURN sys.babelfish_conv_string_to_date(p_datestring, - p_style); + RETURN sys.babelfish_conv_string_to_datetime2(p_datatype, + p_datetimestring, + p_style); EXCEPTION WHEN OTHERS THEN RETURN NULL; END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; -CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_string_to_datetime(IN p_datatype TEXT, +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_string_to_datetime_v2(IN p_datatype TEXT, IN p_datetimestring TEXT, IN p_style NUMERIC DEFAULT 0) RETURNS TIMESTAMP WITHOUT TIME ZONE AS $BODY$ BEGIN - RETURN sys.babelfish_conv_string_to_datetime(p_datatype, + RETURN sys.babelfish_conv_string_to_datetime_v2(p_datatype, p_datetimestring , p_style); EXCEPTION @@ -9481,26 +9807,26 @@ EXCEPTION END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; -CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_string_to_time(IN p_datatype TEXT, - IN p_timestring TEXT, - IN p_style NUMERIC DEFAULT 0) -RETURNS TIME WITHOUT TIME ZONE +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_string_to_datetimeoffset(IN p_datatype TEXT, + IN p_datetimestring TEXT, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET AS $BODY$ BEGIN - RETURN sys.babelfish_conv_string_to_time(p_datatype, - p_timestring, - p_style); + RETURN sys.babelfish_conv_string_to_datetimeoffset(p_datatype, + p_datetimestring , + p_style); EXCEPTION WHEN OTHERS THEN RETURN NULL; END; $BODY$ LANGUAGE plpgsql -STABLE +IMMUTABLE RETURNS NULL ON NULL INPUT; CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_time_to_string(IN p_datatype TEXT, @@ -9524,7 +9850,7 @@ LANGUAGE plpgsql STABLE RETURNS NULL ON NULL INPUT; --- convertion to date +-- conversion to date CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg TEXT, IN try BOOL, IN p_style NUMERIC DEFAULT 0) @@ -9533,127 +9859,366 @@ AS $BODY$ BEGIN IF try THEN - RETURN sys.babelfish_try_conv_string_to_date(arg, p_style); + RETURN sys.babelfish_try_conv_string_to_datetime2('DATE', arg, p_style); ELSE - RETURN sys.babelfish_conv_string_to_date(arg, p_style); + RETURN sys.babelfish_conv_string_to_datetime2('DATE', arg, p_style); END IF; END; $BODY$ LANGUAGE plpgsql -STABLE; +IMMUTABLE; -CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg anyelement, +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg sys.VARCHAR, IN try BOOL, - IN p_style NUMERIC DEFAULT 0) + IN p_style NUMERIC DEFAULT 0) RETURNS DATE AS $BODY$ BEGIN - IF try THEN - RETURN sys.babelfish_try_conv_to_date(arg); - ELSE - RETURN CAST(arg AS DATE); - END IF; + RETURN sys.babelfish_conv_helper_to_date(arg::TEXT, try, p_style); END; $BODY$ LANGUAGE plpgsql -STABLE; +IMMUTABLE; -CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_date(IN arg anyelement) +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) RETURNS DATE AS $BODY$ BEGIN - RETURN CAST(arg AS DATE); - EXCEPTION - WHEN OTHERS THEN - RETURN NULL; + RETURN sys.babelfish_conv_helper_to_date(arg::TEXT, try, p_style); END; $BODY$ LANGUAGE plpgsql -STABLE; +IMMUTABLE; --- convertion to time -CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN arg TEXT, +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg sys.BPCHAR, IN try BOOL, - IN p_style NUMERIC DEFAULT 0) -RETURNS TIME + IN p_style NUMERIC DEFAULT 0) +RETURNS DATE AS $BODY$ BEGIN - IF try THEN - RETURN sys.babelfish_try_conv_string_to_time('TIME', arg, p_style); - ELSE - RETURN sys.babelfish_conv_string_to_time('TIME', arg, p_style); - END IF; + RETURN sys.babelfish_conv_helper_to_date(arg::TEXT, try, p_style); END; $BODY$ LANGUAGE plpgsql -STABLE; +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS DATE +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_date(arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; -CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN arg anyelement, +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg anyelement, IN try BOOL, IN p_style NUMERIC DEFAULT 0) -RETURNS TIME +RETURNS DATE AS $BODY$ +DECLARE + resdate DATE; BEGIN IF try THEN - RETURN sys.babelfish_try_conv_to_time(arg); + resdate := sys.babelfish_try_conv_to_date(arg); ELSE - RETURN CAST(arg AS TIME); + BEGIN + resdate := CAST(arg AS DATE); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to date is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type date.'; + END; END IF; + + RETURN resdate; END; $BODY$ LANGUAGE plpgsql -STABLE; +IMMUTABLE; -CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_time(IN arg anyelement) -RETURNS TIME +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_date(IN arg anyelement) +RETURNS DATE AS $BODY$ BEGIN - RETURN CAST(arg AS TIME); + RETURN CAST(arg AS DATE); EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to date is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); WHEN OTHERS THEN RETURN NULL; END; $BODY$ LANGUAGE plpgsql -STABLE; +IMMUTABLE; --- convertion to datetime -CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN arg TEXT, - IN try BOOL, - IN p_style NUMERIC DEFAULT 0) -RETURNS sys.DATETIME +-- conversion to time +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg TEXT, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME AS $BODY$ +DECLARE + v_res_datatype TEXT COLLATE C; BEGIN + IF (typmod = -1) THEN + v_res_datatype := 'TIME'; + ELSE + v_res_datatype := PG_CATALOG.format('TIME(%s)', typmod); + END IF; + IF try THEN - RETURN sys.babelfish_try_conv_string_to_datetime('DATETIME', arg, p_style); + RETURN sys.babelfish_try_conv_string_to_datetime2(v_res_datatype, arg, p_style); ELSE - RETURN sys.babelfish_conv_string_to_datetime('DATETIME', arg, p_style); + RETURN sys.babelfish_conv_string_to_datetime2(v_res_datatype, arg, p_style); END IF; END; $BODY$ LANGUAGE plpgsql -STABLE; - +IMMUTABLE; -CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_datetime(IN arg anyelement) -RETURNS sys.DATETIME +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME AS $BODY$ BEGIN - RETURN CAST(arg AS TIMESTAMP); - EXCEPTION - WHEN OTHERS THEN - RETURN NULL; + RETURN sys.babelfish_conv_helper_to_time(typmod, arg::TEXT, try, p_style); END; $BODY$ LANGUAGE plpgsql -STABLE; +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_time(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg sys.BPCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_time(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_time(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME +AS +$BODY$ +DECLARE + restime TIME; +BEGIN + IF try THEN + restime := sys.babelfish_try_conv_to_time(arg); + ELSE + BEGIN + restime := CAST(arg AS TIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to time is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type time.'; + END; + END IF; + + RETURN restime; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_time(IN arg anyelement) +RETURNS TIME +AS +$BODY$ +BEGIN + RETURN CAST(arg AS TIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to time is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +-- conversion to datetime +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg TEXT, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +DECLARE + v_res_datatype TEXT COLLATE C; +BEGIN + IF (typmod = -1) THEN + v_res_datatype := 'DATETIME'; + ELSE + v_res_datatype := PG_CATALOG.format('DATETIME(%s)', typmod); + END IF; + + IF try THEN + RETURN sys.babelfish_try_conv_string_to_datetime_v2(v_res_datatype, arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_datetime_v2(v_res_datatype, arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg sys.BPCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +DECLARE + resdatetime sys.DATETIME; +BEGIN + IF try THEN + resdatetime := sys.babelfish_try_conv_to_datetime(arg); + ELSE + BEGIN + resdatetime := CAST(arg AS sys.DATETIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetime is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type datetime.'; + END; + END IF; + + RETURN resdatetime; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_datetime(IN arg anyelement) +RETURNS sys.DATETIME +AS +$BODY$ +BEGIN + RETURN CAST(arg AS sys.DATETIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetime is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_varbinary(IN arg anyelement, IN try BOOL, @@ -9761,6 +10326,390 @@ LANGUAGE plpgsql IMMUTABLE STRICT; +-- conversion to datetime2 +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg TEXT, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +DECLARE + v_res_datatype TEXT COLLATE C; +BEGIN + IF (typmod = -1) THEN + v_res_datatype := 'DATETIME2'; + ELSE + v_res_datatype := PG_CATALOG.format('DATETIME2(%s)', typmod); + END IF; + + IF try THEN + RETURN sys.babelfish_try_conv_string_to_datetime2(v_res_datatype, arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_datetime2(v_res_datatype, arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime2(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime2(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg sys.BPCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime2(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime2(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +DECLARE + resdatetime sys.DATETIME2; +BEGIN + IF try THEN + resdatetime := sys.babelfish_try_conv_to_datetime2(arg); + ELSE + BEGIN + resdatetime := CAST(arg AS sys.DATETIME2); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetime2 is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type datetime2.'; + END; + END IF; + + RETURN resdatetime; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_datetime2(IN arg anyelement) +RETURNS sys.DATETIME2 +AS +$BODY$ +BEGIN + RETURN CAST(arg AS sys.DATETIME2); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetime2 is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +-- conversion to datetimeoffset +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg TEXT, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +DECLARE + v_res_datatype TEXT COLLATE C; +BEGIN + IF (typmod = -1) THEN + v_res_datatype := 'DATETIMEOFFSET'; + ELSE + v_res_datatype := PG_CATALOG.format('DATETIMEOFFSET(%s)', typmod); + END IF; + + IF try THEN + RETURN sys.babelfish_try_conv_string_to_datetimeoffset(v_res_datatype, arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_datetimeoffset(v_res_datatype, arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetimeoffset(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetimeoffset(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg sys.BPCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetimeoffset(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetimeoffset(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +DECLARE + resdatetimeoffset sys.DATETIMEOFFSET; +BEGIN + IF try THEN + resdatetimeoffset := sys.babelfish_try_conv_to_datetimeoffset(arg); + ELSE + BEGIN + resdatetimeoffset := CAST(arg AS sys.DATETIMEOFFSET); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetimeoffset is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type datetimeoffset.'; + END; + END IF; + + RETURN resdatetimeoffset; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_datetimeoffset(IN arg anyelement) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +BEGIN + RETURN CAST(arg AS sys.DATETIMEOFFSET); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetimeoffset is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +-- conversion to smalldatetime +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg TEXT, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +DECLARE + v_res_datatype TEXT COLLATE C; +BEGIN + IF (typmod = -1) THEN + v_res_datatype := 'SMALLDATETIME'; + ELSE + v_res_datatype := PG_CATALOG.format('SMALLDATETIME(%s)', typmod); + END IF; + + IF try THEN + RETURN sys.babelfish_try_conv_string_to_datetime_v2(v_res_datatype, arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_datetime_v2(v_res_datatype, arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_smalldatetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_smalldatetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg sys.BPCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_smalldatetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_smalldatetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +DECLARE + resdatetime sys.SMALLDATETIME; +BEGIN + IF try THEN + resdatetime := sys.babelfish_try_conv_to_smalldatetime(arg); + ELSE + BEGIN + resdatetime := CAST(arg AS sys.SMALLDATETIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to smalldatetime is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type smalldatetime.'; + END; + END IF; + + RETURN resdatetime; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_smalldatetime(IN arg anyelement) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +BEGIN + RETURN CAST(arg AS sys.SMALLDATETIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to smalldatetime is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + -- convertion to varchar CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_varchar(IN typename TEXT, IN arg TEXT, diff --git a/contrib/babelfishpg_tsql/sql/sys_functions.sql b/contrib/babelfishpg_tsql/sql/sys_functions.sql index d9892b90f4..f2a0e70ba1 100644 --- a/contrib/babelfishpg_tsql/sql/sys_functions.sql +++ b/contrib/babelfishpg_tsql/sql/sys_functions.sql @@ -4713,8 +4713,8 @@ BEGIN ELSE -- Round datetime to fixed bins (e.g. .000, .003, .007) IF date_arg_datatype = 'sys.datetime'::regtype THEN - date := sys.babelfish_conv_string_to_datetime('DATETIME', date::TEXT)::sys.datetime; - origin := sys.babelfish_conv_string_to_datetime('DATETIME', origin::TEXT)::sys.datetime; + date := sys.babelfish_conv_string_to_datetime_v2('DATETIME', date::TEXT)::sys.datetime; + origin := sys.babelfish_conv_string_to_datetime_v2('DATETIME', origin::TEXT)::sys.datetime; END IF; -- when datepart is {year, quarter, month} make use of AGE() function to find number of buckets IF datepart IN ('year', 'quarter', 'month') THEN diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql index 09c2678aec..17233a1912 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql @@ -3,6 +3,36 @@ -- add 'sys' to search path for the convenience SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false); +-- Drops an object if it does not have any dependent objects. +-- Is a temporary procedure for use by the upgrade script. Will be dropped at the end of the upgrade. +-- Please have this be one of the first statements executed in this upgrade script. +CREATE OR REPLACE PROCEDURE babelfish_drop_deprecated_object(object_type varchar, schema_name varchar, object_name varchar) AS +$$ +DECLARE + error_msg text; + query1 text; + query2 text; +BEGIN + + query1 := pg_catalog.format('alter extension babelfishpg_tsql drop %s %s.%s', object_type, schema_name, object_name); + query2 := pg_catalog.format('drop %s %s.%s', object_type, schema_name, object_name); + + execute query1; + execute query2; +EXCEPTION + when object_not_in_prerequisite_state then --if 'alter extension' statement fails + GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT; + raise warning '%', error_msg; + when dependent_objects_still_exist then --if 'drop view' statement fails + GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT; + raise warning '%', error_msg; + when undefined_function then --if function does not exists + GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT; + raise warning '%', error_msg; +end +$$ +LANGUAGE plpgsql; + CREATE OR REPLACE FUNCTION sys.babelfish_update_server_collation_name() RETURNS VOID LANGUAGE C AS 'babelfishpg_common', 'babelfish_update_server_collation_name'; @@ -40,6 +70,5264 @@ $$; * final behaviour. */ + +DO $$ +DECLARE + exception_message text; +BEGIN + ALTER FUNCTION sys.babelfish_conv_helper_to_time(TEXT, BOOL, NUMERIC) RENAME TO babelfish_conv_helper_to_time_with_arg_text_deprecated_in_5_1_0; +EXCEPTION + WHEN undefined_function THEN + GET STACKED DIAGNOSTICS + exception_message = MESSAGE_TEXT; + RAISE WARNING '%', exception_message; +END; +$$; + +DO $$ +DECLARE + exception_message text; +BEGIN + ALTER FUNCTION sys.babelfish_conv_helper_to_time(ANYELEMENT, BOOL, NUMERIC) RENAME TO babelfish_conv_helper_to_time_with_arg_anyelement_deprecated_in_5_1_0; +EXCEPTION + WHEN undefined_function THEN + GET STACKED DIAGNOSTICS + exception_message = MESSAGE_TEXT; + RAISE WARNING '%', exception_message; +END; +$$; + +DO $$ +DECLARE + exception_message text; +BEGIN + ALTER FUNCTION sys.babelfish_conv_helper_to_datetime(TEXT, BOOL, NUMERIC) RENAME TO babelfish_conv_helper_to_datetime_deprecated_in_5_1_0; +EXCEPTION + WHEN undefined_function THEN + GET STACKED DIAGNOSTICS + exception_message = MESSAGE_TEXT; + RAISE WARNING '%', exception_message; +END; +$$; + +CREATE OR REPLACE FUNCTION sys.babelfish_get_microsecs_from_fractsecs_v2(IN p_fractsecs TEXT, + IN p_scale NUMERIC DEFAULT 7) +RETURNS VARCHAR +AS +$BODY$ +DECLARE + v_scale SMALLINT; + v_decplaces INTEGER; + v_fractsecs VARCHAR COLLATE "C"; + v_pureplaces VARCHAR COLLATE "C"; + v_rnd_fractsecs INTEGER; + v_fractsecs_len INTEGER; + v_pureplaces_len INTEGER; + v_err_message VARCHAR COLLATE "C"; +BEGIN + v_fractsecs := pg_catalog.btrim(p_fractsecs); + v_fractsecs_len := char_length(v_fractsecs); + v_scale := floor(p_scale)::SMALLINT; + + IF (v_fractsecs_len < 7) THEN + v_fractsecs := rpad(v_fractsecs, 7, '0'); + v_fractsecs_len := char_length(v_fractsecs); + END IF; + + v_pureplaces := trim(leading '0' from v_fractsecs); + v_pureplaces_len := char_length(v_pureplaces); + + v_decplaces := v_fractsecs_len - v_pureplaces_len; + + v_rnd_fractsecs := round(v_fractsecs::INTEGER, (v_pureplaces_len - (v_scale - v_decplaces)) * (-1)); + + IF (char_length(v_rnd_fractsecs::TEXT) > v_fractsecs_len) THEN + RETURN '-1'; + END IF; + + v_fractsecs := lpad(v_rnd_fractsecs::TEXT, v_fractsecs_len, '0'); + + RETURN substring(v_fractsecs, 1, CASE + WHEN (v_scale >= 7) THEN 6 + ELSE v_scale + END); +EXCEPTION + WHEN invalid_text_representation THEN + GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT; + v_err_message := substring(pg_catalog.lower(v_err_message), 'integer\:\s\"(.*)\"'); + + RAISE USING MESSAGE := pg_catalog.format('Error while trying to convert "%s" value to SMALLINT data type.', v_err_message), + DETAIL := 'Supplied value contains illegal characters.', + HINT := 'Correct supplied value, remove all illegal characters.'; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.babelfish_get_timeunit_from_string(IN p_timepart TEXT, + IN p_timeunit TEXT) +RETURNS VARCHAR +AS +$BODY$ +DECLARE + v_hours VARCHAR COLLATE "C"; + v_minutes VARCHAR COLLATE "C"; + v_seconds VARCHAR COLLATE "C"; + v_fractsecs VARCHAR COLLATE "C"; + v_sign VARCHAR COLLATE "C"; + v_offhours VARCHAR COLLATE "C"; + v_offminutes VARCHAR COLLATE "C"; + v_daypart VARCHAR COLLATE "C"; + v_timepart VARCHAR COLLATE "C"; + v_offset VARCHAR COLLATE "C"; + v_timeunit VARCHAR COLLATE "C"; + v_err_message VARCHAR COLLATE "C"; + v_timeunit_mask VARCHAR COLLATE "C"; + v_regmatch_groups TEXT[]; + AMPM_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*([AP]M)'; + TIMEUNIT_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(\d{1,2})\s*'; + FRACTSECS_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(\d{1,9})'; + TIME_OFFSET_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('((\-|\+)', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '|Z)'); + HHMMSSFS_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', TIMEUNIT_REGEXP, + '\:', TIMEUNIT_REGEXP, + '\:', TIMEUNIT_REGEXP, + '(?:\.|\:)', FRACTSECS_REGEXP, '$'); + HHMMSS_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '$'); + HHMMFS_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\.', FRACTSECS_REGEXP, '$'); + HHMM_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '$'); + HH_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', TIMEUNIT_REGEXP, '$'); +BEGIN + v_timepart := pg_catalog.upper(pg_catalog.btrim(p_timepart)); + v_timeunit := pg_catalog.upper(pg_catalog.btrim(p_timeunit)); + + v_daypart := substring(v_timepart, AMPM_REGEXP); + v_offset := substring(v_timepart, TIME_OFFSET_REGEXP); + v_timepart := pg_catalog.btrim(regexp_replace(v_timepart, AMPM_REGEXP, '')); + v_timepart := pg_catalog.btrim(regexp_replace(v_timepart, TIME_OFFSET_REGEXP, '')); + + v_timeunit_mask := + CASE + WHEN (v_timepart ~* HHMMSSFS_REGEXP) THEN HHMMSSFS_REGEXP + WHEN (v_timepart ~* HHMMSS_REGEXP) THEN HHMMSS_REGEXP + WHEN (v_timepart ~* HHMMFS_REGEXP) THEN HHMMFS_REGEXP + WHEN (v_timepart ~* HHMM_REGEXP) THEN HHMM_REGEXP + WHEN (v_timepart ~* HH_REGEXP) THEN HH_REGEXP + END; + + v_regmatch_groups := regexp_matches(v_timepart, v_timeunit_mask, 'gi'); + + v_hours := v_regmatch_groups[1]; + v_minutes := v_regmatch_groups[2]; + + IF (v_timepart ~* HHMMFS_REGEXP) THEN + v_fractsecs := v_regmatch_groups[3]; + ELSE + v_seconds := v_regmatch_groups[3]; + v_fractsecs := v_regmatch_groups[4]; + END IF; + + v_regmatch_groups := regexp_matches(v_offset, TIME_OFFSET_REGEXP, 'gi'); + + v_sign := coalesce(v_regmatch_groups[2], '+'); + v_offhours := coalesce(v_regmatch_groups[3], '0'); + v_offminutes := coalesce(v_regmatch_groups[4], '0'); + + IF (v_timeunit = 'HOURS' AND v_daypart IS NOT NULL) + THEN + IF ((v_daypart = 'AM' AND v_hours::SMALLINT NOT BETWEEN 0 AND 12) OR + (v_daypart = 'PM' AND v_hours::SMALLINT NOT BETWEEN 1 AND 23)) + THEN + RAISE numeric_value_out_of_range; + ELSIF (v_daypart = 'PM' AND v_hours::SMALLINT < 12) THEN + v_hours := (v_hours::SMALLINT + 12)::VARCHAR; + ELSIF (v_daypart = 'AM' AND v_hours::SMALLINT = 12) THEN + v_hours := (v_hours::SMALLINT - 12)::VARCHAR; + END IF; + END IF; + + RETURN CASE v_timeunit + WHEN 'HOURS' THEN v_hours + WHEN 'MINUTES' THEN v_minutes + WHEN 'SECONDS' THEN v_seconds + WHEN 'FRACTSECONDS' THEN v_fractsecs + WHEN 'OFFHOURS' THEN v_offhours + WHEN 'OFFMINUTES' THEN v_offminutes + WHEN 'OFFSIGN' THEN v_sign + END; +EXCEPTION + WHEN numeric_value_out_of_range THEN + RAISE USING MESSAGE := 'Could not extract correct hour value due to it''s inconsistency with AM|PM day part mark.', + DETAIL := 'Extracted hour value doesn''t fall in correct day part mark range: 0..12 for "AM" or 1..23 for "PM".', + HINT := 'Correct a hour value in the source string or remove AM|PM day part mark out of it.'; + + WHEN invalid_text_representation THEN + GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT; + v_err_message := substring(pg_catalog.lower(v_err_message), 'integer\:\s\"(.*)\"'); + + RAISE USING MESSAGE := pg_catalog.format('Error while trying to convert "%s" value to SMALLINT data type.', v_err_message), + DETAIL := 'Supplied value contains illegal characters.', + HINT := 'Correct supplied value, remove all illegal characters.'; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_string_to_datetime2(IN p_datatype TEXT, + IN p_datetimestring TEXT, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIMESTAMP WITHOUT TIME ZONE +AS +$BODY$ +DECLARE + v_day VARCHAR COLLATE "C"; + v_year VARCHAR COLLATE "C"; + v_month VARCHAR COLLATE "C"; + v_style SMALLINT; + v_scale SMALLINT; + v_hours VARCHAR COLLATE "C"; + v_hijridate DATE; + v_minutes VARCHAR COLLATE "C"; + v_seconds VARCHAR COLLATE "C"; + v_fseconds VARCHAR COLLATE "C"; + v_sign VARCHAR COLLATE "C" = NULL::VARCHAR; + v_offhours VARCHAR COLLATE "C" = NULL::VARCHAR; + v_offminutes VARCHAR COLLATE "C" = NULL::VARCHAR; + v_datatype VARCHAR COLLATE "C"; + v_timepart VARCHAR COLLATE "C"; + v_leftpart VARCHAR COLLATE "C"; + v_middlepart VARCHAR COLLATE "C"; + v_rightpart VARCHAR COLLATE "C"; + v_datestring VARCHAR COLLATE "C"; + v_err_message VARCHAR COLLATE "C"; + v_date_format VARCHAR COLLATE "C"; + v_res_datatype VARCHAR COLLATE "C"; + v_datetimestring VARCHAR COLLATE "C"; + v_datatype_groups TEXT[]; + v_regmatch_groups TEXT[]; + v_lang_metadata_json JSONB; + v_compmonth_regexp VARCHAR COLLATE "C"; + v_resdatetime TIMESTAMP(6) WITHOUT TIME ZONE; + v_language VARCHAR COLLATE "C"; + CONVERSION_LANG CONSTANT VARCHAR COLLATE "C" := ''; + DATE_FORMAT CONSTANT VARCHAR COLLATE "C" := ''; + DAYMM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; + FULLYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{4})'; + SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; + COMPYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2}|\d{4})'; + AMPM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:[AP]M)'; + MASKSEP_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:\.|-|/)'; + TIMEUNIT_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,2}\s*'; + FRACTSECS_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,9}\s*'; + DATATYPE_REGEXP CONSTANT VARCHAR COLLATE "C" := '^(DATE|TIME|DATETIME2|DATETIMEOFFSET)\s*(?:\()?\s*((?:-)?\d+)?\s*(?:\))?$'; + TIME_OFFSET_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('\s*((\-|\+)\s*(', TIMEUNIT_REGEXP, ')\s*\:\s*(', TIMEUNIT_REGEXP, ')|Z)\s*'); + HHMMSSFSOFF_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('(', TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '(?:\.|\:)', FRACTSECS_REGEXP, AMPM_REGEXP, '?)(', TIME_OFFSET_REGEXP, ')?'); + HHMMSSFSOFF_DOT_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('(', TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '(?:\.)', FRACTSECS_REGEXP, AMPM_REGEXP, '?)(', TIME_OFFSET_REGEXP, ')?'); + HHMMSSFSOFF_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFSOFF_PART_REGEXP, ')$'); + DEFMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '$'); + DEFMASK2_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK2_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, '$'); + DEFMASK3_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*($comp_month$)\s*', DAYMM_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK3_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*($comp_month$)\s*', DAYMM_REGEXP, '$'); + DEFMASK4_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*($comp_month$)', '\s*(', HHMMSSFSOFF_PART_REGEXP, ')?$'); + DEFMASK4_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*($comp_month$)$'); + DEFMASK5_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '\s*($comp_month$)', '\s*(', HHMMSSFSOFF_PART_REGEXP, ')?$'); + DEFMASK5_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '\s*($comp_month$)$'); + DEFMASK6_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK6_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '$'); + DEFMASK7_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK7_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '$'); + DEFMASK8_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', COMPYEAR_REGEXP, '\s*($comp_month$)', '\s*(', HHMMSSFSOFF_PART_REGEXP, ')?$'); + DEFMASK8_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', COMPYEAR_REGEXP, '\s*($comp_month$)$'); + DEFMASK8_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', SHORTYEAR_REGEXP, '\s*($comp_month$)$'); + DEFMASK9_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK9_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*\,?\s*', COMPYEAR_REGEXP, '$'); + DEFMASK9_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*', SHORTYEAR_REGEXP, '$'); + DEFMASK9_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '($comp_month$)\s*\,?\s*', FULLYEAR_REGEXP, '$'); + DEFMASK10_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DEFMASK10_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '$'); + DEFMASK10_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*-\s*($comp_month$)\s*-\s*', COMPYEAR_REGEXP, '$'); + DEFMASK10_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\/\s*($comp_month$)\s*\/\s*', COMPYEAR_REGEXP, '$'); + DEFMASK10_4_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\.\s*($comp_month$)\s*\.\s*', COMPYEAR_REGEXP, '$'); + DOT_SLASH_DASH_COMPYEAR1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DOT_SLASH_DASH_COMPYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '$'); + DASH_COMPYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*-\s*', DAYMM_REGEXP, '\s*-\s*', COMPYEAR_REGEXP, '$'); + SLASH_COMPYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\/\s*', DAYMM_REGEXP, '\s*\/\s*', COMPYEAR_REGEXP, '$'); + DOT_COMPYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '\s*\.\s*', COMPYEAR_REGEXP, '$'); + DOT_SLASH_DASH_SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', SHORTYEAR_REGEXP, '$'); + DOT_SLASH_DASH_FULLYEAR1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DOT_SLASH_DASH_FULLYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '$'); + FULLYEAR_DOT_SLASH_DASH1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + FULLYEAR_DOT_SLASH_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '$'); + FULLYEAR_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*-\s*', DAYMM_REGEXP, '\s*-\s*', DAYMM_REGEXP, '$'); + FULLYEAR_SLASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*\/\s*', DAYMM_REGEXP, '\s*\/\s*', DAYMM_REGEXP, '$'); + FULLYEAR_DOT1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '$'); + DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*(\s+', '(', HHMMSSFSOFF_PART_REGEXP, ')', ')?$'); + DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '$'); + DASH_FULLYEAR_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*-\s*', FULLYEAR_REGEXP, '\s*-\s*', DAYMM_REGEXP, '$'); + SLASH_FULLYEAR_SLASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\/\s*', FULLYEAR_REGEXP, '\s*\/\s*', DAYMM_REGEXP, '$'); + DOT_FULLYEAR_DOT1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\.\s*', FULLYEAR_REGEXP, '\s*\.\s*', DAYMM_REGEXP, '$'); + FULLYEAR_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '\s*\d{4}', '(\s+(', HHMMSSFSOFF_PART_REGEXP, '))?$'); + SHORT_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '\s*\d{6}', '(\s+(', HHMMSSFSOFF_PART_REGEXP, '))?$'); + FULL_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', '\s*\d{8}', '(\s+(', HHMMSSFSOFF_PART_REGEXP, '))?$'); + W3C_XML_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, '(', '(\-|\+)', '(\d{2})', '\:', '(\d{2})', '|', 'Z', ')','$'); + W3C_XML_Z_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, 'Z','$'); + ISO_8601_DATETIMEOFFSET_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, 'T', '\d{2}', '\:', '\d{1,2}', '\:', '\d{1,2}', '(?:\.', '\d{1,9}', ')?', '((\-|\+)', '\d{2}', '\:', '\d{2}','|Z)?$'); +BEGIN + v_datatype := pg_catalog.btrim(p_datatype); + v_datetimestring := pg_catalog.upper(pg_catalog.btrim(p_datetimestring)); + v_style := floor(p_style)::SMALLINT; + + v_datatype_groups := regexp_matches(v_datatype, DATATYPE_REGEXP, 'gi'); + + v_res_datatype := pg_catalog.upper(v_datatype_groups[1]); + v_scale := v_datatype_groups[2]::SMALLINT; + + IF (v_res_datatype IS NULL) THEN + RAISE datatype_mismatch; + ELSIF (v_res_datatype = 'DATE' AND v_scale IS NOT NULL) + THEN + RAISE invalid_indicator_parameter_value; + ELSIF (coalesce(v_scale, 0) NOT BETWEEN 0 AND 7) + THEN + RAISE interval_field_overflow; + ELSIF (v_scale IS NULL) THEN + -- currently datetime2, datetimeoffset and time only support factional seconds + -- upto 6 digits hence set v_scale to 6 to get consistent behaviour in datetime2(7) and datetime2 + v_scale := 6; + END IF; + + IF (scale(p_style) > 0) THEN + RAISE most_specific_type_mismatch; + ELSIF (NOT ((v_style BETWEEN 0 AND 14) OR + (v_style BETWEEN 20 AND 25) OR + (v_style BETWEEN 100 AND 114) OR + (v_style IN (120, 121, 126, 127, 130, 131)))) + THEN + RAISE invalid_parameter_value; + END IF; + + -- For W3C_XML_REGEXP, there is no need of maintaining v_timepart and v_datestring + IF (v_datetimestring ~* W3C_XML_REGEXP) + THEN + v_timepart := NULL; + v_datestring := NULL; + ELSE + v_timepart := pg_catalog.btrim(substring(v_datetimestring, PG_CATALOG.concat('(', HHMMSSFSOFF_PART_REGEXP, ')'))); + v_datestring := pg_catalog.btrim(regexp_replace(v_datetimestring, PG_CATALOG.concat('T?', '(', HHMMSSFSOFF_PART_REGEXP, ')'), '', 'gi')); + END IF; + + v_language := CASE + WHEN (v_style IN (130, 131)) THEN 'HIJRI' + ELSE CONVERSION_LANG + END; + + BEGIN + v_lang_metadata_json := sys.babelfish_get_lang_metadata_json(v_language); + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_escape_sequence; + END; + + v_date_format := coalesce(nullif(DATE_FORMAT, ''), v_lang_metadata_json ->> 'date_format'); + + v_compmonth_regexp := array_to_string(array_cat(ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_shortnames')), + ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_names'))), '|'); + + -- If datetime string has some part as 'AMZ' or 'PMZ' then its invalid datetime format + IF (v_datetimestring ~* pg_catalog.concat(AMPM_REGEXP, 'Z')) + THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_datetimestring ~* pg_catalog.replace(DEFMASK1_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK2_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK3_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK4_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK5_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK6_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK7_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK8_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK9_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK10_0_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + IF (v_datestring ~* pg_catalog.replace(DEFMASK1_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK1_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[2]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); + v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK2_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK2_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[1]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK3_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK3_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[3]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_year := v_regmatch_groups[1]; + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK4_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK4_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[2]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + v_year := v_regmatch_groups[1]; + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK5_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK5_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[1]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + v_year := sys.babelfish_get_full_year(v_regmatch_groups[2]); + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK6_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK6_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[3]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); + v_year := v_regmatch_groups[2]; + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK7_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK7_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[2]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); + v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK8_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + IF (v_datetimestring ~* pg_catalog.replace(DEFMASK8_2_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK8_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := '01'; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_year := sys.babelfish_get_full_year(v_regmatch_groups[1]); + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK9_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + IF (v_datetimestring ~* pg_catalog.replace(DEFMASK9_2_REGEXP, '$comp_month$', v_compmonth_regexp) OR + (v_datestring !~* pg_catalog.replace(DEFMASK9_2_REGEXP, '$comp_month$', v_compmonth_regexp) AND + v_datestring !~* pg_catalog.replace(DEFMASK9_3_REGEXP, '$comp_month$', v_compmonth_regexp))) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK9_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := '01'; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); + v_year := sys.babelfish_get_full_year(v_regmatch_groups[2]); + ELSE + IF ((v_datestring !~* pg_catalog.replace(DEFMASK10_2_REGEXP, '$comp_month$', v_compmonth_regexp)) AND + (v_datestring !~* pg_catalog.replace(DEFMASK10_3_REGEXP, '$comp_month$', v_compmonth_regexp)) AND + (v_datestring !~* pg_catalog.replace(DEFMASK10_4_REGEXP, '$comp_month$', v_compmonth_regexp))) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK10_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[1]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); + END IF; + ELSIF (v_datetimestring ~* DOT_SLASH_DASH_COMPYEAR1_0_REGEXP) + THEN + IF ((v_datestring !~* DASH_COMPYEAR1_1_REGEXP) AND + (v_datestring !~* SLASH_COMPYEAR1_1_REGEXP) AND + (v_datestring !~* DOT_COMPYEAR1_1_REGEXP)) + THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_style IN (6, 7, 8, 9, 12, 13, 14, 24, 100, 106, 107, 108, 109, 112, 113, 114, 130)) + THEN + RAISE invalid_regular_expression; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, DOT_SLASH_DASH_COMPYEAR1_1_REGEXP, 'gi'); + v_leftpart := v_regmatch_groups[1]; + v_middlepart := v_regmatch_groups[2]; + v_rightpart := v_regmatch_groups[3]; + + IF (v_datestring ~* DOT_SLASH_DASH_SHORTYEAR_REGEXP) + THEN + IF ((v_style IN (1, 10, 22)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MDY')) + THEN + v_day := v_middlepart; + v_month := v_leftpart; + v_year := sys.babelfish_get_full_year(v_rightpart); + + ELSIF ((v_style IN (2, 11)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'YMD')) + THEN + v_day := v_rightpart; + v_month := v_middlepart; + v_year := sys.babelfish_get_full_year(v_leftpart); + + ELSIF ((v_style IN (3, 4, 5)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DMY')) + THEN + v_day := v_leftpart; + v_month := v_middlepart; + v_year := sys.babelfish_get_full_year(v_rightpart); + + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DYM') + THEN + v_day = v_leftpart; + v_month = v_rightpart; + v_year = sys.babelfish_get_full_year(v_middlepart); + + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MYD') + THEN + v_day := v_rightpart; + v_month := v_leftpart; + v_year = sys.babelfish_get_full_year(v_middlepart); + + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'YDM') + THEN + RAISE character_not_in_repertoire; + ELSE + RAISE invalid_datetime_format; + END IF; + ELSIF (v_datestring ~* DOT_SLASH_DASH_FULLYEAR1_1_REGEXP) + THEN + v_year := v_rightpart; + IF ((v_style IN (103, 104, 105, 131)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DMY')) + THEN + v_day := v_leftpart; + v_month := v_middlepart; + + ELSIF ((v_style IN (101, 110)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MDY')) + THEN + v_day := v_middlepart; + v_month := v_leftpart; + ELSE + RAISE invalid_datetime_format; + END IF; + END IF; + ELSIF (v_datetimestring ~* FULLYEAR_DOT_SLASH_DASH1_0_REGEXP) + THEN + IF ((v_datestring !~* FULLYEAR_DASH1_1_REGEXP) AND + (v_datestring !~* FULLYEAR_SLASH1_1_REGEXP) AND + (v_datestring !~* FULLYEAR_DOT1_1_REGEXP)) + THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_style IN (6, 7, 8, 9, 12, 13, 14, 24, 100, 106, 107, 108, 109, 112, 113, 114, 130)) + THEN + RAISE invalid_regular_expression; + ELSIF (v_style IN (1, 2, 3, 4, 5, 10, 11, 22, 101, 103, 104, 105, 110, 131)) THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, FULLYEAR_DOT_SLASH_DASH1_1_REGEXP, 'gi'); + -- DATEFORMAT 'YDM' is not supported hence only applicable dateformat can be used here is YMD + v_year := v_regmatch_groups[1]; + v_day := v_regmatch_groups[3]; + v_month := v_regmatch_groups[2]; + ELSIF (v_datetimestring ~* DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_0_REGEXP) + THEN + IF ((v_datestring !~* DASH_FULLYEAR_DASH1_1_REGEXP) AND + (v_datestring !~* SLASH_FULLYEAR_SLASH1_1_REGEXP) AND + (v_datestring !~* DOT_FULLYEAR_DOT1_1_REGEXP)) + THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_style IN (6, 7, 8, 9, 12, 13, 14, 24, 100, 106, 107, 108, 109, 112, 113, 114, 130)) + THEN + RAISE invalid_regular_expression; + ELSIF (v_style IN (1, 2, 3, 4, 5, 10, 11, 20, 21, 22, 23, 25, 101, 102, 103, 104, 105, 110, 111, 120, 121, 126, 127, 131)) THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_1_REGEXP, 'gi'); + v_leftpart := v_regmatch_groups[1]; + v_year := v_regmatch_groups[2]; + v_rightpart := v_regmatch_groups[3]; + + IF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MYD') + THEN + v_day := v_rightpart; + v_month := v_leftpart; + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DYM') + THEN + v_day := v_leftpart; + v_month := v_rightpart; + ELSE + RAISE invalid_datetime_format; + END IF; + ELSIF ((v_datetimestring ~* FULLYEAR_DIGITMASK1_0_REGEXP OR + v_datetimestring ~* SHORT_DIGITMASK1_0_REGEXP OR + v_datetimestring ~* FULL_DIGITMASK1_0_REGEXP)) + THEN + IF (v_datestring ~* '^\d{4}$') + THEN + v_day := '01'; + v_month := '01'; + v_year := substr(v_datestring, 1, 4); + + ELSIF (v_datestring ~* '^\d{6}$') + THEN + v_day := substr(v_datestring, 5, 2); + v_month := substr(v_datestring, 3, 2); + v_year := sys.babelfish_get_full_year(substr(v_datestring, 1, 2)); + + ELSIF (v_datestring ~* '^\d{8}$') + THEN + v_day := substr(v_datestring, 7, 2); + v_month := substr(v_datestring, 5, 2); + v_year := substr(v_datestring, 1, 4); + END IF; + ELSIF (v_datetimestring ~* HHMMSSFSOFF_REGEXP OR length(v_datetimestring) = 0) + THEN + v_day := '01'; + v_month := '01'; + v_year := '1900'; + ELSIF (v_datetimestring ~* W3C_XML_REGEXP) + THEN + v_regmatch_groups := regexp_matches(v_datetimestring, W3C_XML_REGEXP, 'gi'); + v_day := v_regmatch_groups[3]; + v_month := v_regmatch_groups[2]; + v_year := v_regmatch_groups[1]; + + IF (v_datetimestring !~* W3C_XML_Z_REGEXP) + THEN + v_sign := v_regmatch_groups[5]; + v_offhours := v_regmatch_groups[6]; + v_offminutes := v_regmatch_groups[7]; + IF ((v_offhours::SMALLINT NOT BETWEEN 0 AND 14) OR + (v_offminutes::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_offhours::SMALLINT = 14 AND v_offminutes::SMALLINT != 0)) + THEN + RAISE invalid_datetime_format; + END IF; + ELSE + v_sign := '+'; + v_offhours := '0'; + v_offminutes := '0'; + END IF; + ELSIF (v_datetimestring ~* ISO_8601_DATETIMEOFFSET_REGEXP) + THEN + v_regmatch_groups := regexp_matches(v_datetimestring, ISO_8601_DATETIMEOFFSET_REGEXP, 'gi'); + + v_day := v_regmatch_groups[3]; + v_month := v_regmatch_groups[2]; + v_year := v_regmatch_groups[1]; + ELSE + RAISE invalid_datetime_format; + END IF; + + IF (v_style IN (130, 131)) + THEN + -- validate date according to hijri date format + IF ((v_month::SMALLINT NOT BETWEEN 1 AND 12) OR + (v_day::SMALLINT NOT BETWEEN 1 AND 30) OR + ((MOD(v_month::SMALLINT, 2) = 0 AND v_month::SMALLINT != 12) AND v_day::SMALLINT = 30)) + THEN + RAISE invalid_character_value_for_cast; + END IF; + + -- for hijri leap year + IF (v_month::SMALLINT = 12) + THEN + -- check for a leap year + IF (MOD(v_year::SMALLINT, 30) IN (2, 5, 7, 10, 13, 16, 18, 21, 24, 26, 29)) + THEN + IF (v_day::SMALLINT NOT BETWEEN 1 AND 30) + THEN + RAISE invalid_character_value_for_cast; + END IF; + ELSE + IF (v_day::SMALLINT NOT BETWEEN 1 AND 29) + THEN + RAISE invalid_character_value_for_cast; + END IF; + END IF; + END IF; + + v_hijridate := sys.babelfish_conv_hijri_to_greg(v_day, v_month, v_year) - 1; + v_day = to_char(v_hijridate, 'DD'); + v_month = to_char(v_hijridate, 'MM'); + v_year = to_char(v_hijridate, 'YYYY'); + END IF; + + BEGIN + v_hours := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'HOURS'), '0'); + v_minutes := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'MINUTES'), '0'); + v_seconds := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'SECONDS'), '0'); + v_fseconds := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'FRACTSECONDS'), '0'); + + -- v_offhours and v_offminutes will be already set for W3C_XML datetime string format + v_sign := coalesce(v_sign, sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFSIGN'), '+'); + v_offhours := coalesce(v_offhours, sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFHOURS'), '0'); + v_offminutes := coalesce(v_offminutes, sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFMINUTES'), '0'); + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_character_value_for_cast; + END; + + -- validate time and offset + IF ((v_hours::SMALLINT NOT BETWEEN 0 AND 23) OR + (v_minutes::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_seconds::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_offhours::SMALLINT NOT BETWEEN 0 AND 14) OR + (v_offminutes::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_offhours::SMALLINT = 14 AND v_offminutes::SMALLINT != 0)) + THEN + RAISE invalid_character_value_for_cast; + END IF; + + -- validate date according to gregorian date format + IF ((v_year::SMALLINT NOT BETWEEN 1 AND 9999) OR + (v_month::SMALLINT NOT BETWEEN 1 AND 12) OR + ((v_month::SMALLINT IN (1,3,5,7,8,10,12)) AND (v_day::SMALLINT NOT BETWEEN 1 AND 31)) OR + ((v_month::SMALLINT IN (4,6,9,11)) AND (v_day::SMALLINT NOT BETWEEN 1 AND 30))) + THEN + RAISE invalid_character_value_for_cast; + ELSIF (v_month::SMALLINT = 2) + THEN + -- check for a leap year + IF ((v_year::SMALLINT % 4 = 0) AND ((v_year::SMALLINT % 100 <> 0) or (v_year::SMALLINT % 400 = 0))) + THEN + IF (v_day::SMALLINT NOT BETWEEN 1 AND 29) + THEN + RAISE invalid_character_value_for_cast; + END IF; + ELSE + IF (v_day::SMALLINT NOT BETWEEN 1 AND 28) + THEN + RAISE invalid_character_value_for_cast; + END IF; + END IF; + END IF; + + IF (v_timepart !~* PG_CATALOG.concat('^(', HHMMSSFSOFF_DOT_PART_REGEXP, ')$') AND char_length(v_fseconds) > 3) + THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_timepart !~* PG_CATALOG.concat('^(', HHMMSSFSOFF_DOT_PART_REGEXP, ')$')) THEN + -- if before fractional seconds there is a ':' + v_fseconds := lpad(v_fseconds, 3, '0'); + END IF; + + IF (v_scale = 0) THEN + v_seconds := pg_catalog.concat_ws('.', v_seconds, v_fseconds); + v_seconds := round(v_seconds::NUMERIC, 0)::TEXT; + ELSE + v_fseconds := sys.babelfish_get_microsecs_from_fractsecs_v2(v_fseconds, v_scale); + + -- Following condition will handle overflow of fractsecs + IF (v_fseconds::INTEGER < 0) THEN + v_fseconds := PG_CATALOG.repeat('0', LEAST(v_scale, 6)); + v_seconds := (v_seconds::INTEGER + 1)::TEXT; + END IF; + + v_seconds := pg_catalog.concat_ws('.', v_seconds, v_fseconds); + END IF; + + IF (v_res_datatype = 'DATE') + THEN + v_resdatetime := make_timestamp(v_year::SMALLINT, v_month::SMALLINT, v_day::SMALLINT,0,0,0); + ELSIF (v_res_datatype = 'TIME') + THEN + v_resdatetime := make_timestamp(9999, 12, 31, v_hours::SMALLINT, v_minutes::SMALLINT, v_seconds::NUMERIC); + ELSE + v_resdatetime := make_timestamp(v_year::SMALLINT, v_month::SMALLINT, v_day::SMALLINT, + v_hours::SMALLINT, v_minutes::SMALLINT, v_seconds::NUMERIC); + END IF; + + IF (v_resdatetime > make_timestamp(9999, 12, 31, 23, 59, 59.999999)) THEN + -- if rounding of fractional seconds caused the date and time to go out of range + -- then max date and time that can be stored for p_datatype will be used + v_resdatetime := make_timestamp(9999, 12, 31, 23, 59, pg_catalog.concat_ws('.', '59', PG_CATALOG.repeat('9', LEAST(v_scale, 6)))::NUMERIC); + END IF; + + RETURN v_resdatetime; +EXCEPTION + WHEN most_specific_type_mismatch THEN + RAISE USING MESSAGE := 'Argument data type numeric is invalid for argument 3 of conv_string_to_datetime2 function.', + DETAIL := 'Use of incorrect "style" parameter value during conversion process.', + HINT := 'Change "style" parameter to the proper value and try again.'; + + WHEN invalid_parameter_value THEN + RAISE USING MESSAGE := pg_catalog.format('The style %s is not supported for conversions from varchar to %s.', v_style, PG_CATALOG.lower(v_res_datatype)), + DETAIL := 'Use of incorrect "style" parameter value during conversion process.', + HINT := 'Change "style" parameter to the proper value and try again.'; + + WHEN invalid_regular_expression THEN + RAISE USING MESSAGE := pg_catalog.format('The input character string does not follow style %s, either change the input character string or use a different style.', v_style), + DETAIL := 'Selected "style" param value isn''t valid for conversion of passed character string.', + HINT := 'Either change the input character string or use a different style.'; + + WHEN datatype_mismatch THEN + RAISE USING MESSAGE := 'Data type should be one of these values: ''DATE'', ''TIME''/''TIME(n)'', ''DATETIME2''/''DATETIME2(n)'', ''DATETIMEOFFSET''/''DATETIMEOFFSET(n)''.', + DETAIL := 'Use of incorrect "datatype" parameter value during conversion process.', + HINT := 'Change "datatype" parameter to the proper value and try again.'; + + WHEN invalid_indicator_parameter_value THEN + RAISE USING MESSAGE := pg_catalog.format('CAST or CONVERT: invalid attributes specified for type ''%s''', v_res_datatype), + DETAIL := 'Use of incorrect scale value, which is not corresponding to specified data type.', + HINT := 'Change data type scale component or select different data type and try again.'; + + WHEN interval_field_overflow THEN + RAISE USING MESSAGE := pg_catalog.format('Specified scale %s is invalid.', v_scale), + DETAIL := 'Use of incorrect data type scale value during conversion process.', + HINT := 'Change scale component of data type parameter to be in range [0..7] and try again.'; + + WHEN invalid_datetime_format THEN + RAISE USING MESSAGE := 'Conversion failed when converting date and/or time from character string.', + DETAIL := 'Incorrect using of pair of input parameters values during conversion process.', + HINT := 'Check the input parameters values, correct them if needed, and try again.'; + + WHEN invalid_character_value_for_cast THEN + RAISE USING MESSAGE := pg_catalog.format('The conversion of a varchar data type to a %s data type resulted in an out-of-range value.', PG_CATALOG.lower(v_res_datatype)), + DETAIL := 'Use of incorrect pair of input parameter values during conversion process.', + HINT := 'Check input parameter values, correct them if needed, and try again.'; + + WHEN character_not_in_repertoire THEN + RAISE USING MESSAGE := 'This session''s YDM date format is not supported when converting from this character string format to date, time, datetime2 or datetimeoffset. Change the session''s date format or provide a style to the explicit conversion.', + DETAIL := 'Use of incorrect DATE_FORMAT constant value regarding string format parameter during conversion process.', + HINT := 'Change DATE_FORMAT constant to one of these values: MDY|DMY|DYM, recompile function and try again.'; + + WHEN invalid_escape_sequence THEN + RAISE USING MESSAGE := pg_catalog.format('Invalid CONVERSION_LANG constant value - ''%s''. Allowed values are: ''English'', ''Deutsch'', etc.', + CONVERSION_LANG), + DETAIL := 'Compiled incorrect CONVERSION_LANG constant value in function''s body.', + HINT := 'Correct CONVERSION_LANG constant value in function''s body, recompile it and try again.'; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_string_to_datetime_v2(IN p_datatype TEXT, + IN p_datetimestring TEXT, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIMESTAMP WITHOUT TIME ZONE +AS +$BODY$ +DECLARE + v_day VARCHAR COLLATE "C"; + v_year VARCHAR COLLATE "C"; + v_month VARCHAR COLLATE "C"; + v_style SMALLINT; + v_scale SMALLINT; + v_hours VARCHAR COLLATE "C"; + v_hijridate DATE; + v_minutes VARCHAR COLLATE "C"; + v_seconds VARCHAR COLLATE "C"; + v_fseconds VARCHAR COLLATE "C"; + v_datatype VARCHAR COLLATE "C"; + v_timepart VARCHAR COLLATE "C"; + v_leftpart VARCHAR COLLATE "C"; + v_middlepart VARCHAR COLLATE "C"; + v_rightpart VARCHAR COLLATE "C"; + v_datestring VARCHAR COLLATE "C"; + v_err_message VARCHAR COLLATE "C"; + v_date_format VARCHAR COLLATE "C"; + v_res_datatype VARCHAR COLLATE "C"; + v_datetimestring VARCHAR COLLATE "C"; + v_datatype_groups TEXT[]; + v_regmatch_groups TEXT[]; + v_lang_metadata_json JSONB; + v_compmonth_regexp VARCHAR COLLATE "C"; + v_resdatetime TIMESTAMP(6) WITHOUT TIME ZONE; + v_language VARCHAR COLLATE "C"; + CONVERSION_LANG CONSTANT VARCHAR COLLATE "C" := ''; + DATE_FORMAT CONSTANT VARCHAR COLLATE "C" := ''; + DAYMM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; + FULLYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{4})'; + SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; + COMPYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2}|\d{4})'; + AMPM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:[AP]M)'; + MASKSEP_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:\.|-|/)'; + TIMEUNIT_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,2}\s*'; + FRACTSECS_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,3}\s*'; + DATATYPE_REGEXP CONSTANT VARCHAR COLLATE "C" := '^(DATETIME|SMALLDATETIME)\s*(?:\()?\s*((?:-)?\d+)?\s*(?:\))?$'; + HHMMSSFS_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat( TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\.', FRACTSECS_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '(?:\.|\:)', FRACTSECS_REGEXP, AMPM_REGEXP, '?'); + HHMMSSFS_DOT_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat( TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\.', FRACTSECS_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '(?:\.)', FRACTSECS_REGEXP, AMPM_REGEXP, '?'); + HHMMSSFS_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')$'); + DEFMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '$'); + DEFMASK1_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '$'); + DEFMASK1_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,\s*', DAYMM_REGEXP, '\s+', COMPYEAR_REGEXP, '$'); + DEFMASK2_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + DAYMM_REGEXP, '\s*(?:,|', MASKSEP_REGEXP, ')', '?\s*($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK2_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*(?:,|', MASKSEP_REGEXP, ')', '?\s*($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, '$'); + DEFMASK2_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*(?:,|', MASKSEP_REGEXP, ')', '\s*($comp_month$)\s*,?\s*', COMPYEAR_REGEXP, '$'); + DEFMASK3_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK3_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '$'); + DEFMASK3_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '$'); + DEFMASK3_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,\s*', DAYMM_REGEXP, '$'); + DEFMASK4_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*', '\s*(?:,|', MASKSEP_REGEXP, ')', '?\s*($comp_month$)', + '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); + DEFMASK4_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*(?:,|', MASKSEP_REGEXP, ')', '?\s*($comp_month$)$'); + DEFMASK4_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '\s*(?:,|', MASKSEP_REGEXP, ')', '\s*($comp_month$)$'); + DEFMASK5_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + DAYMM_REGEXP, '(?:\s+|\s*,\s*)', COMPYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)', + '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); + DEFMASK5_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '(?:\s+|\s*,\s*)', COMPYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)$'); + DEFMASK5_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '(?:\s+|\s*,\s*)', COMPYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)$'); + DEFMASK5_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '(?:\s*,\s*)', COMPYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)$'); + DEFMASK6_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', + MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK6_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '$'); + DEFMASK6_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '$'); + DEFMASK6_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,\s*', FULLYEAR_REGEXP, '\s+', DAYMM_REGEXP, '$'); + DEFMASK7_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', + MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK7_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '$'); + DEFMASK7_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*,?\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '$'); + DEFMASK7_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,\s*', DAYMM_REGEXP, '\s*,\s*', COMPYEAR_REGEXP, '$'); + DEFMASK8_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)', + '\s*(', HHMMSSFS_PART_REGEXP, ')?$'); + DEFMASK8_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '?\s*($comp_month$)$'); + DEFMASK8_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)$'); + DEFMASK9_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', HHMMSSFS_PART_REGEXP, ')?\s*', + MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK9_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '?\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, '$'); + DEFMASK9_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', MASKSEP_REGEXP, '\s*($comp_month$)\s*,?\s*', FULLYEAR_REGEXP, '$'); + DEFMASK10_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DEFMASK10_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*($comp_month$)\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '$'); + DEFMASK10_2_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*-\s*($comp_month$)\s*-\s*', COMPYEAR_REGEXP, '$'); + DEFMASK10_3_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\/\s*($comp_month$)\s*\/\s*', COMPYEAR_REGEXP, '$'); + DEFMASK10_4_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*\.\s*($comp_month$)\s*\.\s*', COMPYEAR_REGEXP, '$'); + DOT_SLASH_DASH_COMPYEAR1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + DAYMM_REGEXP, '\s*(?:\.|/|-)\s*', DAYMM_REGEXP, '\s*(?:\.|/|-)\s*', COMPYEAR_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DOT_SLASH_DASH_COMPYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', COMPYEAR_REGEXP, '$'); + DOT_SLASH_DASH_SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', SHORTYEAR_REGEXP, '$'); + DOT_SLASH_DASH_FULLYEAR1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + DAYMM_REGEXP, '\s*(?:\.|/|-)\s*', DAYMM_REGEXP, '\s*(?:\.|/|-)\s*', FULLYEAR_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DOT_SLASH_DASH_FULLYEAR1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '$'); + + FULLYEAR_DOT_SLASH_DASH1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + FULLYEAR_DOT_SLASH_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '$'); + + DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*', + DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, + '\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_1_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', DAYMM_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', FULLYEAR_REGEXP, '\s*', MASKSEP_REGEXP, '\s*', DAYMM_REGEXP, '$'); + + FULLYEAR_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*\d{4}\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + SHORT_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*\d{6}\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + FULL_DIGITMASK1_0_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^(', '(', HHMMSSFS_PART_REGEXP, ')', '\s+)?\s*\d{8}\s*(\s+', '(', HHMMSSFS_PART_REGEXP, ')', ')?$'); + ISO_8601_DATETIME_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', '(\d{2})', '-', '(\d{2})', 'T', '\d{2}', '\:', '\d{2}', '\:', '\d{2}', '(?:\.', FRACTSECS_REGEXP, ')?','$'); +BEGIN + v_datatype := pg_catalog.btrim(p_datatype); + v_datetimestring := pg_catalog.upper(pg_catalog.btrim(p_datetimestring)); + v_style := floor(p_style)::SMALLINT; + + v_datatype_groups := regexp_matches(v_datatype, DATATYPE_REGEXP, 'gi'); + + v_res_datatype := pg_catalog.upper(v_datatype_groups[1]); + v_scale := v_datatype_groups[2]::SMALLINT; + + IF (v_res_datatype IS NULL) THEN + RAISE datatype_mismatch; + ELSIF (v_scale IS NOT NULL) + THEN + RAISE invalid_indicator_parameter_value; + ELSIF (v_scale IS NULL) THEN + v_scale := 7; + END IF; + + IF (scale(p_style) > 0) THEN + RAISE most_specific_type_mismatch; + END IF; + + v_timepart := pg_catalog.btrim(substring(v_datetimestring, PG_CATALOG.concat('(', HHMMSSFS_PART_REGEXP, ')'))); + v_datestring := pg_catalog.btrim(regexp_replace(v_datetimestring, PG_CATALOG.concat('T?', '(', HHMMSSFS_PART_REGEXP, ')'), '', 'gi')); + + v_language := CASE + WHEN (v_style IN (130, 131)) THEN 'HIJRI' + ELSE CONVERSION_LANG + END; + + BEGIN + v_lang_metadata_json := sys.babelfish_get_lang_metadata_json(v_language); + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_escape_sequence; + END; + + v_date_format := coalesce(nullif(DATE_FORMAT, ''), v_lang_metadata_json ->> 'date_format'); + + v_compmonth_regexp := array_to_string(array_cat(ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_shortnames')), + ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_names'))), '|'); + + IF (v_datetimestring ~* pg_catalog.replace(DEFMASK1_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK2_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK3_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK4_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK5_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK6_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK7_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK8_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK9_0_REGEXP, '$comp_month$', v_compmonth_regexp) OR + v_datetimestring ~* pg_catalog.replace(DEFMASK10_0_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + IF (v_style = 127) THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_datestring ~* pg_catalog.replace(DEFMASK1_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK1_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[2]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); + + -- For v_style 130 and 131, 1 or 2 digit year is out of range + IF (v_style IN (130, 131) AND v_regmatch_groups[3]::SMALLINT <= 99) + THEN + RAISE invalid_character_value_for_cast; + END IF; + v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK2_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK2_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[1]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + + -- For v_style 130 and 131, 1 or 2 digit year is out of range + IF (v_style IN (130, 131) AND v_regmatch_groups[3]::SMALLINT <= 99) + THEN + RAISE invalid_character_value_for_cast; + END IF; + v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK3_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK3_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[3]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_year := v_regmatch_groups[1]; + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK4_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK4_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[2]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + v_year := v_regmatch_groups[1]; + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK5_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK5_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[1]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + + -- For v_style 130 and 131, 1 or 2 digit year is out of range + IF (v_style IN (130, 131) AND v_regmatch_groups[2]::SMALLINT <= 99) + THEN + RAISE invalid_character_value_for_cast; + END IF; + v_year := sys.babelfish_get_full_year(v_regmatch_groups[2]); + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK6_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK6_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[3]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); + v_year := v_regmatch_groups[2]; + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK7_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK7_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[2]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); + + -- For v_style 130 and 131, 1 or 2 digit year is out of range + IF (v_style IN (130, 131) AND v_regmatch_groups[3]::SMALLINT <= 99) + THEN + RAISE invalid_character_value_for_cast; + END IF; + v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK8_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK8_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := '01'; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_year := v_regmatch_groups[1]; + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK9_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK9_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := '01'; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[1], v_lang_metadata_json); + v_year := v_regmatch_groups[2]; + + ELSIF (v_datestring ~* pg_catalog.replace(DEFMASK10_1_REGEXP, '$comp_month$', v_compmonth_regexp)) + THEN + v_regmatch_groups := regexp_matches(v_datestring, pg_catalog.replace(DEFMASK10_1_REGEXP, '$comp_month$', v_compmonth_regexp), 'gi'); + v_day := v_regmatch_groups[1]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + + -- For v_style 130 and 131, 1 or 2 digit year is out of range + IF (v_style IN (130, 131) AND v_regmatch_groups[3]::SMALLINT <= 99) + THEN + RAISE invalid_character_value_for_cast; + END IF; + v_year := sys.babelfish_get_full_year(v_regmatch_groups[3]); + ELSE + RAISE invalid_character_value_for_cast; + END IF; + ELSIF (v_datetimestring ~* DOT_SLASH_DASH_COMPYEAR1_0_REGEXP) + THEN + v_regmatch_groups := regexp_matches(v_datestring, DOT_SLASH_DASH_COMPYEAR1_1_REGEXP, 'gi'); + v_leftpart := v_regmatch_groups[1]; + v_middlepart := v_regmatch_groups[2]; + v_rightpart := v_regmatch_groups[3]; + + IF (v_datestring ~* DOT_SLASH_DASH_SHORTYEAR_REGEXP) + THEN + IF (v_style NOT IN (0, 1, 2, 3, 4, 5, 10, 11)) + THEN + RAISE invalid_datetime_format; + END IF; + + IF ((v_style IN (1, 10)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MDY')) + THEN + v_day := v_middlepart; + v_month := v_leftpart; + v_year := sys.babelfish_get_full_year(v_rightpart); + + ELSIF ((v_style IN (2, 11)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'YMD')) + THEN + v_day := v_rightpart; + v_month := v_middlepart; + v_year := sys.babelfish_get_full_year(v_leftpart); + + ELSIF ((v_style IN (3, 4, 5)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DMY')) + THEN + v_day := v_leftpart; + v_month := v_middlepart; + v_year := sys.babelfish_get_full_year(v_rightpart); + + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'DYM') + THEN + v_day = v_leftpart; + v_month = v_rightpart; + v_year = sys.babelfish_get_full_year(v_middlepart); + + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'MYD') + THEN + v_day := v_rightpart; + v_month := v_leftpart; + v_year = sys.babelfish_get_full_year(v_middlepart); + + ELSIF ((v_style IS NULL OR v_style = 0) AND v_date_format = 'YDM') + THEN + v_day := v_middlepart; + v_month := v_rightpart; + v_year := sys.babelfish_get_full_year(v_leftpart); + END IF; + ELSIF (v_datestring ~* DOT_SLASH_DASH_FULLYEAR1_1_REGEXP) + THEN + IF (v_style NOT IN (0, 20, 21, 101, 102, 103, 104, 105, 110, 111, 120, 121, 130, 131)) + THEN + RAISE invalid_datetime_format; + END IF; + + v_year := v_rightpart; + IF ((v_style IN (103, 104, 105, 130, 131)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format IN ('DMY', 'DYM', 'YDM'))) + THEN + v_day := v_leftpart; + v_month := v_middlepart; + + ELSIF ((v_style IN (20, 21, 101, 102, 110, 111, 120, 121)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format IN ('MDY', 'MYD', 'YMD'))) + THEN + v_day := v_middlepart; + v_month := v_leftpart; + END IF; + END IF; + ELSIF (v_datetimestring ~* FULLYEAR_DOT_SLASH_DASH1_0_REGEXP) + THEN + IF (v_style NOT IN (0, 20, 21, 101, 102, 103, 104, 105, 110, 111, 120, 121, 130, 131)) + THEN + RAISE invalid_datetime_format; + ELSIF (v_style IN (130, 131) AND v_res_datatype = 'SMALLDATETIME') + THEN + RAISE invalid_character_value_for_cast; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, FULLYEAR_DOT_SLASH_DASH1_1_REGEXP, 'gi'); + v_year := v_regmatch_groups[1]; + v_middlepart := v_regmatch_groups[2]; + v_rightpart := v_regmatch_groups[3]; + + IF ((v_style IN (20, 21, 101, 102, 110, 111, 120, 121)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format IN ('MDY', 'MYD', 'YMD'))) + THEN + v_day := v_rightpart; + v_month := v_middlepart; + + ELSIF ((v_style IN (103, 104, 105, 130, 131)) OR + ((v_style IS NULL OR v_style = 0) AND v_date_format IN ('DMY', 'DYM', 'YDM'))) + THEN + v_day := v_middlepart; + v_month := v_rightpart; + END IF; + ELSIF (v_datetimestring ~* DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_0_REGEXP) + THEN + IF (v_style IS NOT NULL AND v_style != 0) + THEN + RAISE invalid_datetime_format; + ELSIF (v_style IN (130, 131) AND v_res_datatype = 'SMALLDATETIME') + THEN + RAISE invalid_character_value_for_cast; + END IF; + + v_regmatch_groups := regexp_matches(v_datestring, DOT_SLASH_DASH_FULLYEAR_DOT_SLASH_DASH1_1_REGEXP, 'gi'); + v_leftpart := v_regmatch_groups[1]; + v_year := v_regmatch_groups[2]; + v_rightpart := v_regmatch_groups[3]; + + IF (v_date_format IN ('MYD', 'MDY', 'YMD')) + THEN + v_day := v_rightpart; + v_month := v_leftpart; + ELSIF (v_date_format IN ('DYM', 'DMY', 'YDM')) + THEN + v_day := v_leftpart; + v_month := v_rightpart; + ELSE + RAISE invalid_datetime_format; + END IF; + ELSIF (v_datetimestring ~* FULLYEAR_DIGITMASK1_0_REGEXP OR + v_datetimestring ~* SHORT_DIGITMASK1_0_REGEXP OR + v_datetimestring ~* FULL_DIGITMASK1_0_REGEXP) + THEN + IF (v_style = 127 AND v_datestring !~* '^\d{4}$') + THEN + RAISE invalid_datetime_format; + ELSIF (v_style IN (130, 131) AND v_res_datatype = 'SMALLDATETIME') + THEN + RAISE invalid_character_value_for_cast; + END IF; + + IF (v_datestring ~* '^\d{4}$') + THEN + v_day := '01'; + v_month := '01'; + v_year := substr(v_datestring, 1, 4); + + ELSIF (v_datestring ~* '^\d{6}$') + THEN + v_day := substr(v_datestring, 5, 2); + v_month := substr(v_datestring, 3, 2); + v_year := sys.babelfish_get_full_year(substr(v_datestring, 1, 2)); + + ELSIF (v_datestring ~* '^\d{8}$') + THEN + v_day := substr(v_datestring, 7, 2); + v_month := substr(v_datestring, 5, 2); + v_year := substr(v_datestring, 1, 4); + END IF; + ELSIF (v_datetimestring ~* HHMMSSFS_REGEXP OR length(v_datetimestring) = 0) + THEN + v_day := '01'; + v_month := '01'; + v_year := '1900'; + ELSIF (v_datetimestring ~* ISO_8601_DATETIME_REGEXP) + THEN + IF (v_style IN (130, 131)) + THEN + RAISE invalid_character_value_for_cast; + END IF; + v_regmatch_groups := regexp_matches(v_datetimestring, ISO_8601_DATETIME_REGEXP, 'gi'); + + v_day := v_regmatch_groups[3]; + v_month := v_regmatch_groups[2]; + v_year := v_regmatch_groups[1]; + ELSE + RAISE invalid_datetime_format; + END IF; + + -- DATETIME/SMALLDATETIME supports time part in either left or right side of date part, + -- but having time on both side of date part should throw error + IF ((SELECT COUNT(*) FROM regexp_matches(v_datetimestring, HHMMSSFS_PART_REGEXP)) > 1) + THEN + RAISE invalid_character_value_for_cast; + END IF; + + IF ((v_datetimestring !~* HHMMSSFS_REGEXP AND + length(v_datetimestring) != 0) AND + v_style IN (130, 131)) + THEN + -- validate date according to hijri date format + IF ((v_month::SMALLINT NOT BETWEEN 1 AND 12) OR + (v_day::SMALLINT NOT BETWEEN 1 AND 30) OR + ((MOD(v_month::SMALLINT, 2) = 0 AND v_month::SMALLINT != 12) AND v_day::SMALLINT = 30)) + THEN + RAISE invalid_character_value_for_cast; + END IF; + + -- for hijri leap year + IF (v_month::SMALLINT = 12) + THEN + -- check for a leap year + IF (MOD(v_year::SMALLINT, 30) IN (2, 5, 7, 10, 13, 16, 18, 21, 24, 26, 29)) + THEN + IF (v_day::SMALLINT NOT BETWEEN 1 AND 30) + THEN + RAISE invalid_character_value_for_cast; + END IF; + ELSE + IF (v_day::SMALLINT NOT BETWEEN 1 AND 29) + THEN + RAISE invalid_character_value_for_cast; + END IF; + END IF; + END IF; + + v_hijridate := sys.babelfish_conv_hijri_to_greg(v_day, v_month, v_year) - 1; + v_day = to_char(v_hijridate, 'DD'); + v_month = to_char(v_hijridate, 'MM'); + v_year = to_char(v_hijridate, 'YYYY'); + END IF; + + BEGIN + v_hours := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'HOURS'), '0'); + v_minutes := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'MINUTES'), '0'); + v_seconds := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'SECONDS'), '0'); + v_fseconds := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'FRACTSECONDS'), '0'); + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_character_value_for_cast; + END; + + -- validate time + IF ((v_hours::SMALLINT NOT BETWEEN 0 AND 23) OR + (v_minutes::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_seconds::SMALLINT NOT BETWEEN 0 AND 59)) + THEN + RAISE invalid_character_value_for_cast; + END IF; + + -- validate date according to gregorian date format + IF ((v_year::SMALLINT NOT BETWEEN 1 AND 9999) OR + (v_month::SMALLINT NOT BETWEEN 1 AND 12) OR + ((v_month::SMALLINT IN (1,3,5,7,8,10,12)) AND (v_day::SMALLINT NOT BETWEEN 1 AND 31)) OR + ((v_month::SMALLINT IN (4,6,9,11)) AND (v_day::SMALLINT NOT BETWEEN 1 AND 30)) OR + ((v_res_datatype = 'DATETIME') AND (v_year::SMALLINT NOT BETWEEN 1753 AND 9999)) OR + ((v_res_datatype = 'SMALLDATETIME') AND + ((v_year::SMALLINT NOT BETWEEN 1900 AND 2079) OR + (v_year::SMALLINT = 2079 AND + ((v_month::SMALLINT NOT BETWEEN 1 AND 6) OR (v_day::SMALLINT NOT BETWEEN 1 AND 6)))))) + THEN + RAISE invalid_character_value_for_cast; + ELSIF (v_month::SMALLINT = 2) + THEN + -- check for a leap year + IF ((v_year::SMALLINT % 4 = 0) AND ((v_year::SMALLINT % 100 <> 0) or (v_year::SMALLINT % 400 = 0))) + THEN + IF (v_day::SMALLINT NOT BETWEEN 1 AND 29) + THEN + RAISE invalid_character_value_for_cast; + END IF; + ELSE + IF (v_day::SMALLINT NOT BETWEEN 1 AND 28) + THEN + RAISE invalid_character_value_for_cast; + END IF; + END IF; + END IF; + + -- validate boundary condition for date and time + IF ((v_res_datatype = 'SMALLDATETIME' AND + (v_year::SMALLINT = 2079 AND v_month::SMALLINT = 6 AND v_day::SMALLINT = 6 AND + v_hours::SMALLINT = 23 AND v_minutes::SMALLINT = 59 AND + (v_seconds::SMALLINT > 29 OR (v_seconds::SMALLINT = 29 AND v_fseconds::SMALLINT > 998)))) OR + (v_res_datatype = 'DATETIME' AND + (v_year::SMALLINT = 9999 AND v_month::SMALLINT = 12 AND v_day::SMALLINT = 31 AND + v_hours::SMALLINT = 23 AND v_minutes::SMALLINT = 59 AND v_seconds::SMALLINT = 59 AND v_fseconds::SMALLINT > 998)) + ) + THEN + RAISE invalid_character_value_for_cast; + END IF; + + IF (v_timepart ~* PG_CATALOG.concat('^(', HHMMSSFS_DOT_PART_REGEXP, ')$')) THEN + -- if before fractional seconds there is a '.' + v_resdatetime := sys.datetimefromparts(v_year, v_month, v_day, + v_hours, v_minutes, v_seconds, + rpad(v_fseconds, 3, '0')); + ELSE + -- if before fractional seconds there is a ':' + v_resdatetime := sys.datetimefromparts(v_year, v_month, v_day, + v_hours, v_minutes, v_seconds, + lpad(v_fseconds, 3, '0')); + END IF; + + IF (v_res_datatype = 'SMALLDATETIME' AND + to_char(v_resdatetime, 'SS') <> '00') + THEN + IF (to_char(v_resdatetime, 'SS')::SMALLINT >= 30) THEN + v_resdatetime := v_resdatetime + INTERVAL '1 minute'; + END IF; + + v_resdatetime := to_timestamp(to_char(v_resdatetime, 'DD.MM.YYYY.HH24.MI'), 'DD.MM.YYYY.HH24.MI'); + END IF; + + RETURN v_resdatetime; +EXCEPTION + WHEN most_specific_type_mismatch THEN + RAISE USING MESSAGE := 'Argument data type numeric is invalid for argument 3 of convert function.', + DETAIL := 'Use of incorrect "style" parameter value during conversion process.', + HINT := 'Change "style" parameter to the proper value and try again.'; + + WHEN invalid_parameter_value THEN + RAISE USING MESSAGE := pg_catalog.format('The style %s is not supported for conversions from varchar to %s.', v_style, PG_CATALOG.lower(v_res_datatype)), + DETAIL := 'Use of incorrect "style" parameter value during conversion process.', + HINT := 'Change "style" parameter to the proper value and try again.'; + + WHEN invalid_regular_expression THEN + RAISE USING MESSAGE := pg_catalog.format('The input character string does not follow style %s, either change the input character string or use a different style.', v_style), + DETAIL := 'Selected "style" param value isn''t valid for conversion of passed character string.', + HINT := 'Either change the input character string or use a different style.'; + + WHEN datatype_mismatch THEN + RAISE USING MESSAGE := 'Data type should be one of these values: ''DATETIME'', ''SMALLDATETIME''.', + DETAIL := 'Use of incorrect "datatype" parameter value during conversion process.', + HINT := 'Change "datatype" parameter to the proper value and try again.'; + + WHEN invalid_indicator_parameter_value THEN + RAISE USING MESSAGE := pg_catalog.format('CAST or CONVERT: invalid attributes specified for type ''%s''', PG_CATALOG.lower(v_res_datatype)), + DETAIL := 'Use of incorrect scale value, which is not corresponding to specified data type.', + HINT := 'Change data type scale component or select different data type and try again.'; + + WHEN interval_field_overflow THEN + RAISE USING MESSAGE := pg_catalog.format('Specified scale %s is invalid.', v_scale), + DETAIL := 'Use of incorrect data type scale value during conversion process.', + HINT := 'Change scale component of data type parameter to be in range [0..7] and try again.'; + + WHEN invalid_datetime_format THEN + RAISE USING MESSAGE := CASE v_res_datatype + WHEN 'SMALLDATETIME' THEN 'Conversion failed when converting character string to smalldatetime data type.' + ELSE 'Conversion failed when converting date and/or time from character string.' + END, + DETAIL := 'Incorrect using of pair of input parameters values during conversion process.', + HINT := 'Check the input parameters values, correct them if needed, and try again.'; + + WHEN invalid_character_value_for_cast THEN + RAISE USING MESSAGE := pg_catalog.format('The conversion of a varchar data type to a %s data type resulted in an out-of-range value.', PG_CATALOG.lower(v_res_datatype)), + DETAIL := 'Use of incorrect pair of input parameter values during conversion process.', + HINT := 'Check input parameter values, correct them if needed, and try again.'; + + WHEN invalid_escape_sequence THEN + RAISE USING MESSAGE := pg_catalog.format('Invalid CONVERSION_LANG constant value - ''%s''. Allowed values are: ''English'', ''Deutsch'', etc.', + CONVERSION_LANG), + DETAIL := 'Compiled incorrect CONVERSION_LANG constant value in function''s body.', + HINT := 'Correct CONVERSION_LANG constant value in function''s body, recompile it and try again.'; + + WHEN invalid_text_representation THEN + GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT; + v_err_message := substring(pg_catalog.lower(v_err_message), 'integer\:\s\"(.*)\"'); + + RAISE USING MESSAGE := pg_catalog.format('Error while trying to convert "%s" value to SMALLINT data type.', + v_err_message), + DETAIL := 'Passed argument value contains illegal characters.', + HINT := 'Correct passed argument value, remove all illegal characters.'; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_string_to_datetimeoffset(IN p_datatype TEXT, + IN p_datetimestring TEXT, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +DECLARE + v_sign VARCHAR COLLATE "C"; + v_offhours VARCHAR COLLATE "C"; + v_offminutes VARCHAR COLLATE "C"; + v_timepart VARCHAR COLLATE "C"; + v_datestring VARCHAR COLLATE "C"; + v_datetimestring VARCHAR COLLATE "C"; + v_regmatch_groups TEXT[]; + v_resdatetime TIMESTAMP(6) WITHOUT TIME ZONE; + v_resdatetime_string VARCHAR COLLATE "C"; + DAYMM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; + FULLYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{4})'; + AMPM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:[AP]M)'; + TIMEUNIT_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,2}\s*'; + FRACTSECS_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,9}\s*'; + TIME_OFFSET_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('\s*((\-|\+)\s*(', TIMEUNIT_REGEXP, ')\s*\:\s*(', TIMEUNIT_REGEXP, ')|Z)\s*'); + HHMMSSFSOFF_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('(', TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, AMPM_REGEXP, '?|', + TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '\:', TIMEUNIT_REGEXP, '(?:\.|\:)', FRACTSECS_REGEXP, AMPM_REGEXP, '?)(', TIME_OFFSET_REGEXP, ')?'); + W3C_XML_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, '(', '(\-|\+)', '\s*(\d{2})\s*', '\:', '\s*(\d{2})\s*', '|', 'Z', ')','$'); + W3C_XML_Z_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, 'Z','$'); +BEGIN + v_datetimestring := pg_catalog.upper(pg_catalog.trim(p_datetimestring)); + -- datetimestring validation and conversion will be done in babelfish_conv_string_to_datetime2 function and a timestamp will be returned + v_resdatetime := sys.babelfish_conv_string_to_datetime2(p_datatype, p_datetimestring, p_style); + + v_timepart := pg_catalog.btrim(substring(v_datetimestring, PG_CATALOG.concat('(', HHMMSSFSOFF_PART_REGEXP, ')'))); + v_datestring := pg_catalog.btrim(regexp_replace(v_datetimestring, PG_CATALOG.concat('T?', '(', HHMMSSFSOFF_PART_REGEXP, ')'), '', 'gi')); + + -- Get the time offset value + IF (v_datetimestring ~* W3C_XML_REGEXP) + THEN + v_regmatch_groups := regexp_matches(v_datetimestring, W3C_XML_REGEXP, 'gi'); + + IF (v_datetimestring !~* W3C_XML_Z_REGEXP) + THEN + v_sign := v_regmatch_groups[5]; + v_offhours := v_regmatch_groups[6]; + v_offminutes := v_regmatch_groups[7]; + ELSE + v_sign := '+'; + v_offhours := '0'; + v_offminutes := '0'; + END IF; + ELSE + BEGIN + v_sign := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFSIGN'), '+'); + v_offhours := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFHOURS'), '0'); + v_offminutes := coalesce(sys.babelfish_get_timeunit_from_string(v_timepart, 'OFFMINUTES'), '0'); + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_character_value_for_cast; + END; + END IF; + + -- validate offset + IF ((v_offhours::SMALLINT NOT BETWEEN 0 AND 14) OR + (v_offminutes::SMALLINT NOT BETWEEN 0 AND 59) OR + (v_offhours::SMALLINT = 14 AND v_offminutes::SMALLINT != 0)) + THEN + RAISE invalid_character_value_for_cast; + END IF; + + v_resdatetime_string := PG_CATALOG.concat(v_resdatetime::PG_CATALOG.TEXT,v_sign,v_offhours,':',v_offminutes); + + RETURN CAST(v_resdatetime_string AS sys.datetimeoffset); +EXCEPTION + WHEN invalid_character_value_for_cast THEN + RAISE USING MESSAGE := 'The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.', + DETAIL := 'Use of incorrect pair of input parameter values during conversion process.', + HINT := 'Check input parameter values, correct them if needed, and try again.'; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_string_to_datetime2(IN p_datatype TEXT, + IN p_datetimestring TEXT, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIMESTAMP WITHOUT TIME ZONE +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_string_to_datetime2(p_datatype, + p_datetimestring, + p_style); +EXCEPTION + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_string_to_datetime_v2(IN p_datatype TEXT, + IN p_datetimestring TEXT, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIMESTAMP WITHOUT TIME ZONE +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_string_to_datetime_v2(p_datatype, + p_datetimestring , + p_style); +EXCEPTION + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_string_to_datetimeoffset(IN p_datatype TEXT, + IN p_datetimestring TEXT, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_string_to_datetimeoffset(p_datatype, + p_datetimestring , + p_style); +EXCEPTION + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg TEXT, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS DATE +AS +$BODY$ +BEGIN + IF try THEN + RETURN sys.babelfish_try_conv_string_to_datetime2('DATE', arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_datetime2('DATE', arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS DATE +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_date(arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS DATE +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_date(arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg sys.BPCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS DATE +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_date(arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS DATE +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_date(arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_date(IN arg anyelement) +RETURNS DATE +AS +$BODY$ +BEGIN + RETURN CAST(arg AS DATE); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to date is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_date(IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS DATE +AS +$BODY$ +DECLARE + resdate DATE; +BEGIN + IF try THEN + resdate := sys.babelfish_try_conv_to_date(arg); + ELSE + BEGIN + resdate := CAST(arg AS DATE); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to date is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type date.'; + END; + END IF; + + RETURN resdate; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg TEXT, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME +AS +$BODY$ +DECLARE + v_res_datatype TEXT COLLATE C; +BEGIN + IF (typmod = -1) THEN + v_res_datatype := 'TIME'; + ELSE + v_res_datatype := PG_CATALOG.format('TIME(%s)', typmod); + END IF; + + IF try THEN + RETURN sys.babelfish_try_conv_string_to_datetime2(v_res_datatype, arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_datetime2(v_res_datatype, arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_time(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_time(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg sys.BPCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_time(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_time(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_time(IN arg anyelement) +RETURNS TIME +AS +$BODY$ +BEGIN + RETURN CAST(arg AS TIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to time is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_time(IN typmod INTEGER, + IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS TIME +AS +$BODY$ +DECLARE + restime TIME; +BEGIN + IF try THEN + restime := sys.babelfish_try_conv_to_time(arg); + ELSE + BEGIN + restime := CAST(arg AS TIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to time is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type time.'; + END; + END IF; + + RETURN restime; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg TEXT, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +DECLARE + v_res_datatype TEXT COLLATE C; +BEGIN + IF (typmod = -1) THEN + v_res_datatype := 'DATETIME'; + ELSE + v_res_datatype := PG_CATALOG.format('DATETIME(%s)', typmod); + END IF; + + IF try THEN + RETURN sys.babelfish_try_conv_string_to_datetime_v2(v_res_datatype, arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_datetime_v2(v_res_datatype, arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg sys.BPCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_datetime(IN arg anyelement) +RETURNS sys.DATETIME +AS +$BODY$ +BEGIN + RETURN CAST(arg AS sys.DATETIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetime is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime(IN typmod INTEGER, + IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME +AS +$BODY$ +DECLARE + resdatetime sys.DATETIME; +BEGIN + IF try THEN + resdatetime := sys.babelfish_try_conv_to_datetime(arg); + ELSE + BEGIN + resdatetime := CAST(arg AS sys.DATETIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetime is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type datetime.'; + END; + END IF; + + RETURN resdatetime; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg TEXT, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +DECLARE + v_res_datatype TEXT COLLATE C; +BEGIN + IF (typmod = -1) THEN + v_res_datatype := 'DATETIME2'; + ELSE + v_res_datatype := PG_CATALOG.format('DATETIME2(%s)', typmod); + END IF; + + IF try THEN + RETURN sys.babelfish_try_conv_string_to_datetime2(v_res_datatype, arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_datetime2(v_res_datatype, arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime2(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime2(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg sys.BPCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime2(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetime2(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_datetime2(IN arg anyelement) +RETURNS sys.DATETIME2 +AS +$BODY$ +BEGIN + RETURN CAST(arg AS sys.DATETIME2); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetime2 is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetime2(IN typmod INTEGER, + IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIME2 +AS +$BODY$ +DECLARE + resdatetime sys.DATETIME2; +BEGIN + IF try THEN + resdatetime := sys.babelfish_try_conv_to_datetime2(arg); + ELSE + BEGIN + resdatetime := CAST(arg AS sys.DATETIME2); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetime2 is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type datetime2.'; + END; + END IF; + + RETURN resdatetime; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg TEXT, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +DECLARE + v_res_datatype TEXT COLLATE C; +BEGIN + IF (typmod = -1) THEN + v_res_datatype := 'DATETIMEOFFSET'; + ELSE + v_res_datatype := PG_CATALOG.format('DATETIMEOFFSET(%s)', typmod); + END IF; + + IF try THEN + RETURN sys.babelfish_try_conv_string_to_datetimeoffset(v_res_datatype, arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_datetimeoffset(v_res_datatype, arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetimeoffset(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetimeoffset(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg sys.BPCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetimeoffset(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_datetimeoffset(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_datetimeoffset(IN arg anyelement) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +BEGIN + RETURN CAST(arg AS sys.DATETIMEOFFSET); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetimeoffset is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_datetimeoffset(IN typmod INTEGER, + IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.DATETIMEOFFSET +AS +$BODY$ +DECLARE + resdatetimeoffset sys.DATETIMEOFFSET; +BEGIN + IF try THEN + resdatetimeoffset := sys.babelfish_try_conv_to_datetimeoffset(arg); + ELSE + BEGIN + resdatetimeoffset := CAST(arg AS sys.DATETIMEOFFSET); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to datetimeoffset is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type datetimeoffset.'; + END; + END IF; + + RETURN resdatetimeoffset; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg TEXT, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +DECLARE + v_res_datatype TEXT COLLATE C; +BEGIN + IF (typmod = -1) THEN + v_res_datatype := 'SMALLDATETIME'; + ELSE + v_res_datatype := PG_CATALOG.format('SMALLDATETIME(%s)', typmod); + END IF; + + IF try THEN + RETURN sys.babelfish_try_conv_string_to_datetime_v2(v_res_datatype, arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_datetime_v2(v_res_datatype, arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_smalldatetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg sys.NVARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_smalldatetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg sys.BPCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_smalldatetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg sys.NCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_helper_to_smalldatetime(typmod, arg::TEXT, try, p_style); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_smalldatetime(IN arg anyelement) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +BEGIN + RETURN CAST(arg AS sys.SMALLDATETIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to smalldatetime is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_smalldatetime(IN typmod INTEGER, + IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.SMALLDATETIME +AS +$BODY$ +DECLARE + resdatetime sys.SMALLDATETIME; +BEGIN + IF try THEN + resdatetime := sys.babelfish_try_conv_to_smalldatetime(arg); + ELSE + BEGIN + resdatetime := CAST(arg AS sys.SMALLDATETIME); + EXCEPTION + WHEN cannot_coerce THEN + RAISE USING MESSAGE := pg_catalog.format('Explicit conversion from data type %s to smalldatetime is not allowed.', format_type(pg_typeof(arg)::oid, NULL)); + WHEN datetime_field_overflow THEN + RAISE USING MESSAGE := 'Arithmetic overflow error converting expression to data type smalldatetime.'; + END; + END IF; + + RETURN resdatetime; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_datetime_to_string(IN p_datatype TEXT, + IN p_src_datatype TEXT, + IN p_datetimeval TIMESTAMP(6) WITHOUT TIME ZONE, + IN p_style NUMERIC DEFAULT -1) +RETURNS TEXT +AS +$BODY$ +DECLARE + v_day VARCHAR COLLATE "C"; + v_hour VARCHAR COLLATE "C"; + v_month SMALLINT; + v_style SMALLINT; + v_scale SMALLINT; + v_resmask VARCHAR COLLATE "C"; + v_language VARCHAR COLLATE "C"; + v_datatype VARCHAR COLLATE "C"; + v_fseconds VARCHAR COLLATE "C"; + v_fractsep VARCHAR COLLATE "C"; + v_monthname VARCHAR COLLATE "C"; + v_resstring VARCHAR COLLATE "C"; + v_lengthexpr VARCHAR COLLATE "C"; + v_maxlength SMALLINT; + v_res_length SMALLINT; + v_err_message VARCHAR COLLATE "C"; + v_src_datatype VARCHAR COLLATE "C"; + v_res_datatype VARCHAR COLLATE "C"; + v_lang_metadata_json JSONB; + VARCHAR_MAX CONSTANT SMALLINT := 8000; + NVARCHAR_MAX CONSTANT SMALLINT := 4000; + CONVERSION_LANG CONSTANT VARCHAR COLLATE "C" := ''; + DATATYPE_REGEXP CONSTANT VARCHAR COLLATE "C" := '^\s*(CHAR|NCHAR|VARCHAR|NVARCHAR|CHARACTER VARYING)\s*$'; + SRCDATATYPE_MASK_REGEXP VARCHAR COLLATE "C" := '^(?:DATETIME|SMALLDATETIME|DATETIME2)\s*(?:\s*\(\s*(\d+)\s*\)\s*)?$'; + DATATYPE_MASK_REGEXP CONSTANT VARCHAR COLLATE "C" := '^\s*(?:CHAR|NCHAR|VARCHAR|NVARCHAR|CHARACTER VARYING)\s*\(\s*(\d+|MAX)\s*\)\s*$'; + v_datetimeval TIMESTAMP(6) WITHOUT TIME ZONE; +BEGIN + v_datatype := pg_catalog.upper(pg_catalog.btrim(p_datatype)); + v_src_datatype := pg_catalog.upper(pg_catalog.btrim(p_src_datatype)); + v_style := floor(p_style)::SMALLINT; + + IF (v_src_datatype ~* SRCDATATYPE_MASK_REGEXP) + THEN + v_scale := substring(v_src_datatype, SRCDATATYPE_MASK_REGEXP)::SMALLINT; + + v_src_datatype := PG_CATALOG.rtrim(split_part(v_src_datatype, '(', 1)); + + IF (v_src_datatype <> 'DATETIME2' AND v_scale IS NOT NULL) THEN + RAISE invalid_indicator_parameter_value; + ELSIF (v_scale NOT BETWEEN 0 AND 7) THEN + RAISE invalid_regular_expression; + END IF; + + v_scale := coalesce(v_scale, 7); + ELSE + RAISE most_specific_type_mismatch; + END IF; + + IF (scale(p_style) > 0) THEN + RAISE escape_character_conflict; + ELSIF (NOT ((v_style BETWEEN 0 AND 14) OR + (v_style BETWEEN 20 AND 25) OR + (v_style BETWEEN 100 AND 114) OR + v_style IN (-1, 120, 121, 126, 127, 130, 131))) + THEN + RAISE invalid_parameter_value; + END IF; + + IF (v_datatype ~* DATATYPE_MASK_REGEXP) THEN + v_res_datatype := PG_CATALOG.rtrim(split_part(v_datatype, '(', 1)); + + v_maxlength := CASE + WHEN (v_res_datatype IN ('CHAR', 'VARCHAR')) THEN VARCHAR_MAX + ELSE NVARCHAR_MAX + END; + + v_lengthexpr := substring(v_datatype, DATATYPE_MASK_REGEXP); + + IF (v_lengthexpr <> 'MAX' AND char_length(v_lengthexpr) > 4) + THEN + RAISE interval_field_overflow; + END IF; + + v_res_length := CASE v_lengthexpr + WHEN 'MAX' THEN v_maxlength + ELSE v_lengthexpr::SMALLINT + END; + ELSIF (v_datatype ~* DATATYPE_REGEXP) THEN + v_res_datatype := v_datatype; + ELSE + RAISE datatype_mismatch; + END IF; + + v_datetimeval := CASE + WHEN (v_style NOT IN (130, 131)) THEN p_datetimeval + ELSE sys.babelfish_conv_greg_to_hijri(p_datetimeval) + INTERVAL '1 day' + END; + + v_day := PG_CATALOG.ltrim(to_char(v_datetimeval, 'DD'), '0'); + v_hour := PG_CATALOG.ltrim(to_char(v_datetimeval, 'HH12'), '0'); + v_month := to_char(v_datetimeval, 'MM')::SMALLINT; + + v_language := CASE + WHEN (v_style IN (130, 131)) THEN 'HIJRI' + ELSE CONVERSION_LANG + END; + BEGIN + v_lang_metadata_json := sys.babelfish_get_lang_metadata_json(v_language); + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_character_value_for_cast; + END; + + v_monthname := (v_lang_metadata_json -> 'months_shortnames') ->> v_month - 1; + + IF (v_src_datatype IN ('DATETIME', 'SMALLDATETIME')) THEN + v_fseconds := sys.babelfish_round_fractseconds(to_char(v_datetimeval, 'MS')); + + IF (v_fseconds::INTEGER = 1000) THEN + v_fseconds := '000'; + v_datetimeval := v_datetimeval + INTERVAL '1 second'; + ELSE + v_fseconds := lpad(v_fseconds, 3, '0'); + END IF; + ELSE + v_fseconds := sys.babelfish_get_microsecs_from_fractsecs_v2(to_char(v_datetimeval, 'US'), v_scale); + + -- Following condition will handle overflow of fractsecs + IF (v_fseconds::INTEGER < 0) THEN + v_fseconds := PG_CATALOG.repeat('0', LEAST(v_scale, 6)); + v_datetimeval := v_datetimeval + INTERVAL '1 second'; + END IF; + + IF (v_scale = 7) THEN + v_fseconds := pg_catalog.concat(v_fseconds, '0'); + END IF; + END IF; + + v_fractsep := CASE v_src_datatype + WHEN 'DATETIME2' THEN '.' + ELSE ':' + END; + + IF ((v_style = -1 AND v_src_datatype <> 'DATETIME2') OR + v_style IN (0, 9, 100, 109)) + THEN + v_resmask := pg_catalog.format('$mnme$ %s YYYY %s:MI%s', + lpad(v_day, 2, ' '), + lpad(v_hour, 2, ' '), + CASE + WHEN (v_style IN (-1, 0, 100)) THEN 'AM' + ELSE pg_catalog.format(':SS:%sAM', v_fseconds) + END); + ELSIF (v_style = 1) THEN + v_resmask := 'MM/DD/YY'; + ELSIF (v_style = 101) THEN + v_resmask := 'MM/DD/YYYY'; + ELSIF (v_style = 2) THEN + v_resmask := 'YY.MM.DD'; + ELSIF (v_style = 102) THEN + v_resmask := 'YYYY.MM.DD'; + ELSIF (v_style = 3) THEN + v_resmask := 'DD/MM/YY'; + ELSIF (v_style = 103) THEN + v_resmask := 'DD/MM/YYYY'; + ELSIF (v_style = 4) THEN + v_resmask := 'DD.MM.YY'; + ELSIF (v_style = 104) THEN + v_resmask := 'DD.MM.YYYY'; + ELSIF (v_style = 5) THEN + v_resmask := 'DD-MM-YY'; + ELSIF (v_style = 105) THEN + v_resmask := 'DD-MM-YYYY'; + ELSIF (v_style = 6) THEN + v_resmask := 'DD $mnme$ YY'; + ELSIF (v_style = 106) THEN + v_resmask := 'DD $mnme$ YYYY'; + ELSIF (v_style = 7) THEN + v_resmask := '$mnme$ DD, YY'; + ELSIF (v_style = 107) THEN + v_resmask := '$mnme$ DD, YYYY'; + ELSIF (v_style IN (8, 24, 108)) THEN + v_resmask := 'HH24:MI:SS'; + ELSIF (v_style = 10) THEN + v_resmask := 'MM-DD-YY'; + ELSIF (v_style = 110) THEN + v_resmask := 'MM-DD-YYYY'; + ELSIF (v_style = 11) THEN + v_resmask := 'YY/MM/DD'; + ELSIF (v_style = 111) THEN + v_resmask := 'YYYY/MM/DD'; + ELSIF (v_style = 12) THEN + v_resmask := 'YYMMDD'; + ELSIF (v_style = 112) THEN + v_resmask := 'YYYYMMDD'; + ELSIF (v_style IN (13, 113)) THEN + v_resmask := pg_catalog.format('DD $mnme$ YYYY HH24:MI:SS%s%s', v_fractsep, v_fseconds); + ELSIF (v_style IN (14, 114)) THEN + v_resmask := pg_catalog.format('HH24:MI:SS%s%s', v_fractsep, v_fseconds); + ELSIF (v_style IN (20, 120)) THEN + v_resmask := 'YYYY-MM-DD HH24:MI:SS'; + ELSIF ((v_style = -1 AND v_src_datatype = 'DATETIME2') OR + v_style IN (21, 25, 121)) + THEN + v_resmask := pg_catalog.format('YYYY-MM-DD HH24:MI:SS.%s', v_fseconds); + ELSIF (v_style = 22) THEN + v_resmask := pg_catalog.format('MM/DD/YY %s:MI:SS AM', lpad(v_hour, 2, ' ')); + ELSIF (v_style = 23) THEN + v_resmask := 'YYYY-MM-DD'; + ELSIF (v_style IN (126, 127)) THEN + v_resmask := CASE v_src_datatype + WHEN 'SMALLDATETIME' THEN 'YYYY-MM-DDT$rem$HH24:MI:SS' + ELSE pg_catalog.format('YYYY-MM-DDT$rem$HH24:MI:SS.%s', v_fseconds) + END; + ELSIF (v_style IN (130, 131)) THEN + v_resmask := pg_catalog.concat(CASE p_style + WHEN 131 THEN pg_catalog.format('%s/MM/YYYY ', lpad(v_day, 2, ' ')) + ELSE pg_catalog.format('%s $mnme$ YYYY ', lpad(v_day, 2, ' ')) + END, + pg_catalog.format('%s:MI:SS%s%sAM', lpad(v_hour, 2, ' '), v_fractsep, v_fseconds)); + END IF; + + v_resstring := to_char(v_datetimeval, v_resmask); + v_resstring := pg_catalog.replace(v_resstring, '$mnme$', v_monthname); + v_resstring := pg_catalog.replace(v_resstring, '$rem$', ''); + + v_resstring := substring(v_resstring, 1, coalesce(v_res_length, char_length(v_resstring))); + v_res_length := coalesce(v_res_length, + CASE v_res_datatype + WHEN 'CHAR' THEN 30 + ELSE 60 + END); + RETURN CASE + WHEN (v_res_datatype NOT IN ('CHAR', 'NCHAR')) THEN v_resstring + ELSE rpad(v_resstring, v_res_length, ' ') + END; +EXCEPTION + WHEN most_specific_type_mismatch THEN + RAISE USING MESSAGE := 'Source data type should be one of these values: ''DATETIME'', ''SMALLDATETIME'', ''DATETIME2'' or ''DATETIME2(n)''.', + DETAIL := 'Use of incorrect "src_datatype" parameter value during conversion process.', + HINT := 'Change "srcdatatype" parameter to the proper value and try again.'; + + WHEN invalid_regular_expression THEN + RAISE USING MESSAGE := pg_catalog.format('The source data type scale (%s) given to the convert specification exceeds the maximum allowable value (7).', + v_scale), + DETAIL := 'Use of incorrect scale value of source data type parameter during conversion process.', + HINT := 'Change scale component of source data type parameter to the allowable value and try again.'; + + WHEN invalid_indicator_parameter_value THEN + RAISE USING MESSAGE := pg_catalog.format('Invalid attributes specified for data type %s.', v_src_datatype), + DETAIL := 'Use of incorrect scale value, which is not corresponding to specified data type.', + HINT := 'Change data type scale component or select different data type and try again.'; + + WHEN escape_character_conflict THEN + RAISE USING MESSAGE := 'Argument data type NUMERIC is invalid for argument 4 of convert function.', + DETAIL := 'Use of incorrect "style" parameter value during conversion process.', + HINT := 'Change "style" parameter to the proper value and try again.'; + + WHEN invalid_parameter_value THEN + RAISE USING MESSAGE := pg_catalog.format('%s is not a valid style number when converting from %s to a character string.', + v_style, v_src_datatype), + DETAIL := 'Use of incorrect "style" parameter value during conversion process.', + HINT := 'Change "style" parameter to the proper value and try again.'; + + WHEN interval_field_overflow THEN + RAISE USING MESSAGE := pg_catalog.format('The size (%s) given to the convert specification ''%s'' exceeds the maximum allowed for any data type (%s).', + v_lengthexpr, pg_catalog.lower(v_res_datatype), v_maxlength), + DETAIL := 'Use of incorrect size value of data type parameter during conversion process.', + HINT := 'Change size component of data type parameter to the allowable value and try again.'; + + WHEN datatype_mismatch THEN + RAISE USING MESSAGE := 'Data type should be one of these values: ''CHAR(n|MAX)'', ''NCHAR(n|MAX)'', ''VARCHAR(n|MAX)'', ''NVARCHAR(n|MAX)''.', + DETAIL := 'Use of incorrect "datatype" parameter value during conversion process.', + HINT := 'Change "datatype" parameter to the proper value and try again.'; + + WHEN invalid_character_value_for_cast THEN + RAISE USING MESSAGE := pg_catalog.format('Invalid CONVERSION_LANG constant value - ''%s''. Allowed values are: ''English'', ''Deutsch'', etc.', + CONVERSION_LANG), + DETAIL := 'Compiled incorrect CONVERSION_LANG constant value in function''s body.', + HINT := 'Correct CONVERSION_LANG constant value in function''s body, recompile it and try again.'; + + WHEN invalid_text_representation THEN + GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT; + v_err_message := substring(pg_catalog.lower(v_err_message), 'integer\:\s\"(.*)\"'); + + RAISE USING MESSAGE := pg_catalog.format('Error while trying to convert "%s" value to SMALLINT data type.', + v_err_message), + DETAIL := 'Supplied value contains illegal characters.', + HINT := 'Correct supplied value, remove all illegal characters.'; +END; +$BODY$ +LANGUAGE plpgsql +STABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_time_to_string(IN p_datatype TEXT, + IN p_src_datatype TEXT, + IN p_timeval TIME(6) WITHOUT TIME ZONE, + IN p_style NUMERIC DEFAULT 25) +RETURNS TEXT +AS +$BODY$ +DECLARE + v_hours VARCHAR COLLATE "C"; + v_style SMALLINT; + v_scale SMALLINT; + v_resmask VARCHAR COLLATE "C"; + v_fseconds VARCHAR COLLATE "C"; + v_datatype VARCHAR COLLATE "C"; + v_resstring VARCHAR COLLATE "C"; + v_lengthexpr VARCHAR COLLATE "C"; + v_res_length SMALLINT; + v_res_datatype VARCHAR COLLATE "C"; + v_src_datatype VARCHAR COLLATE "C"; + v_res_maxlength SMALLINT; + VARCHAR_MAX CONSTANT SMALLINT := 8000; + NVARCHAR_MAX CONSTANT SMALLINT := 4000; + -- We use the regex below to make sure input p_datatype is one of them + DATATYPE_REGEXP CONSTANT VARCHAR COLLATE "C" := '^\s*(CHAR|NCHAR|VARCHAR|NVARCHAR|CHARACTER VARYING)\s*$'; + -- We use the regex below to get the length of the datatype, if specified + -- For example, to get the '10' out of 'varchar(10)' + DATATYPE_MASK_REGEXP CONSTANT VARCHAR COLLATE "C" := '^\s*(?:CHAR|NCHAR|VARCHAR|NVARCHAR|CHARACTER VARYING)\s*\(\s*(\d+|MAX)\s*\)\s*$'; + SRCDATATYPE_MASK_REGEXP VARCHAR COLLATE "C" := '^\s*(?:TIME)\s*(?:\s*\(\s*(\d+)\s*\)\s*)?\s*$'; +BEGIN + v_datatype := pg_catalog.upper(pg_catalog.btrim(p_datatype)); + v_src_datatype := pg_catalog.upper(pg_catalog.btrim(p_src_datatype)); + v_style := floor(p_style)::SMALLINT; + + IF (v_src_datatype ~* SRCDATATYPE_MASK_REGEXP) + THEN + v_scale := coalesce(substring(v_src_datatype, SRCDATATYPE_MASK_REGEXP)::SMALLINT, 7); + + IF (v_scale NOT BETWEEN 0 AND 7) THEN + RAISE invalid_regular_expression; + END IF; + ELSE + RAISE most_specific_type_mismatch; + END IF; + + IF (v_datatype ~* DATATYPE_MASK_REGEXP) + THEN + v_res_datatype := PG_CATALOG.rtrim(split_part(v_datatype, '(', 1)); + + v_res_maxlength := CASE + WHEN (v_res_datatype IN ('CHAR', 'VARCHAR')) THEN VARCHAR_MAX + ELSE NVARCHAR_MAX + END; + + v_lengthexpr := substring(v_datatype, DATATYPE_MASK_REGEXP); + + IF (v_lengthexpr <> 'MAX' AND char_length(v_lengthexpr) > 4) THEN + RAISE interval_field_overflow; + END IF; + + v_res_length := CASE v_lengthexpr + WHEN 'MAX' THEN v_res_maxlength + ELSE v_lengthexpr::SMALLINT + END; + ELSIF (v_datatype ~* DATATYPE_REGEXP) THEN + v_res_datatype := v_datatype; + ELSE + RAISE datatype_mismatch; + END IF; + + IF (scale(p_style) > 0) THEN + RAISE escape_character_conflict; + ELSIF (NOT ((v_style BETWEEN 0 AND 14) OR + (v_style BETWEEN 20 AND 25) OR + (v_style BETWEEN 100 AND 114) OR + v_style IN (120, 121, 126, 127, 130, 131))) + THEN + RAISE invalid_parameter_value; + ELSIF ((v_style BETWEEN 1 AND 7) OR + (v_style BETWEEN 10 AND 12) OR + (v_style BETWEEN 101 AND 107) OR + (v_style BETWEEN 110 AND 112) OR + v_style = 23) + THEN + RAISE invalid_datetime_format; + END IF; + + v_hours := PG_CATALOG.ltrim(to_char(p_timeval, 'HH12'), '0'); + v_fseconds := sys.babelfish_get_microsecs_from_fractsecs_v2(to_char(p_timeval, 'US'), v_scale); + + -- Following condition will handle overflow of fractsecs + IF (v_fseconds::INTEGER < 0) THEN + v_fseconds := PG_CATALOG.repeat('0', LEAST(v_scale, 6)); + p_timeval := p_timeval + INTERVAL '1 second'; + END IF; + + IF (v_scale = 7) THEN + v_fseconds := pg_catalog.concat(v_fseconds, '0'); + END IF; + + IF (v_style IN (0, 100)) + THEN + v_resmask := pg_catalog.concat(v_hours, ':MIAM'); + ELSIF (v_style IN (8, 20, 24, 108, 120)) + THEN + v_resmask := 'HH24:MI:SS'; + ELSIF (v_style IN (9, 109)) + THEN + v_resmask := CASE + WHEN (char_length(v_fseconds) = 0) THEN pg_catalog.concat(v_hours, ':MI:SSAM') + ELSE pg_catalog.format('%s:MI:SS.%sAM', v_hours, v_fseconds) + END; + ELSIF (v_style IN (13, 14, 21, 25, 113, 114, 121, 126, 127)) + THEN + v_resmask := CASE + WHEN (char_length(v_fseconds) = 0) THEN 'HH24:MI:SS' + ELSE pg_catalog.concat('HH24:MI:SS.', v_fseconds) + END; + ELSIF (v_style = 22) + THEN + v_resmask := pg_catalog.format('%s:MI:SS AM', lpad(v_hours, 2, ' ')); + ELSIF (v_style IN (130, 131)) + THEN + v_resmask := CASE + WHEN (char_length(v_fseconds) = 0) THEN pg_catalog.concat(lpad(v_hours, 2, ' '), ':MI:SSAM') + ELSE pg_catalog.format('%s:MI:SS.%sAM', lpad(v_hours, 2, ' '), v_fseconds) + END; + END IF; + + v_resstring := to_char(p_timeval, v_resmask); + + v_resstring := substring(v_resstring, 1, coalesce(v_res_length, char_length(v_resstring))); + v_res_length := coalesce(v_res_length, + CASE v_res_datatype + WHEN 'CHAR' THEN 30 + ELSE 60 + END); + RETURN CASE + WHEN (v_res_datatype NOT IN ('CHAR', 'NCHAR')) THEN v_resstring + ELSE rpad(v_resstring, v_res_length, ' ') + END; +EXCEPTION + WHEN most_specific_type_mismatch THEN + RAISE USING MESSAGE := 'Source data type should be ''TIME'' or ''TIME(n)''.', + DETAIL := 'Use of incorrect "src_datatype" parameter value during conversion process.', + HINT := 'Change "src_datatype" parameter to the proper value and try again.'; + + WHEN invalid_regular_expression THEN + RAISE USING MESSAGE := pg_catalog.format('The source data type scale (%s) given to the convert specification exceeds the maximum allowable value (7).', + v_scale), + DETAIL := 'Use of incorrect scale value of source data type parameter during conversion process.', + HINT := 'Change scale component of source data type parameter to the allowable value and try again.'; + + WHEN interval_field_overflow THEN + RAISE USING MESSAGE := pg_catalog.format('The size (%s) given to the convert specification ''%s'' exceeds the maximum allowed for any data type (%s).', + v_lengthexpr, pg_catalog.lower(v_res_datatype), v_res_maxlength), + DETAIL := 'Use of incorrect size value of target data type parameter during conversion process.', + HINT := 'Change size component of data type parameter to the allowable value and try again.'; + + WHEN escape_character_conflict THEN + RAISE USING MESSAGE := 'Argument data type NUMERIC is invalid for argument 4 of convert function.', + DETAIL := 'Use of incorrect "style" parameter value during conversion process.', + HINT := 'Change "style" parameter to the proper value and try again.'; + + WHEN invalid_parameter_value THEN + RAISE USING MESSAGE := pg_catalog.format('%s is not a valid style number when converting from TIME to a character string.', v_style), + DETAIL := 'Use of incorrect "style" parameter value during conversion process.', + HINT := 'Change "style" parameter to the proper value and try again.'; + + WHEN datatype_mismatch THEN + RAISE USING MESSAGE := 'Data type should be one of these values: ''CHAR(n|MAX)'', ''NCHAR(n|MAX)'', ''VARCHAR(n|MAX)'', ''NVARCHAR(n|MAX)''.', + DETAIL := 'Use of incorrect "datatype" parameter value during conversion process.', + HINT := 'Change "datatype" parameter to the proper value and try again.'; + + WHEN invalid_datetime_format THEN + RAISE USING MESSAGE := pg_catalog.format('Error converting data type TIME to %s.', + PG_CATALOG.rtrim(split_part(pg_catalog.btrim(p_datatype), '(', 1))), + DETAIL := 'Incorrect using of pair of input parameters values during conversion process.', + HINT := 'Check the input parameters values, correct them if needed, and try again.'; +END; +$BODY$ +LANGUAGE plpgsql +STABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.babelfish_parse_to_datetime(IN p_datatype TEXT, + IN p_datetimestring TEXT, + IN p_culture TEXT DEFAULT '') +RETURNS TIMESTAMP WITHOUT TIME ZONE +AS +$BODY$ +DECLARE + v_day VARCHAR COLLATE "C"; + v_year SMALLINT; + v_month VARCHAR COLLATE "C"; + v_res_date DATE; + v_scale SMALLINT; + v_hijridate DATE; + v_culture VARCHAR COLLATE "C"; + v_dayparts TEXT[]; + v_resmask VARCHAR COLLATE "C"; + v_datatype VARCHAR COLLATE "C"; + v_raw_year VARCHAR COLLATE "C"; + v_left_part VARCHAR COLLATE "C"; + v_right_part VARCHAR COLLATE "C"; + v_resmask_fi VARCHAR COLLATE "C"; + v_timestring VARCHAR COLLATE "C"; + v_correctnum VARCHAR COLLATE "C"; + v_weekdaynum SMALLINT; + v_err_message VARCHAR COLLATE "C"; + v_date_format VARCHAR COLLATE "C"; + v_weekdaynames TEXT[]; + v_hours SMALLINT := 0; + v_minutes SMALLINT := 0; + v_res_datatype VARCHAR COLLATE "C"; + v_error_message VARCHAR COLLATE "C"; + v_found BOOLEAN := TRUE; + v_compday_regexp VARCHAR COLLATE "C"; + v_regmatch_groups TEXT[]; + v_datatype_groups TEXT[]; + v_datetimestring VARCHAR COLLATE "C"; + v_seconds VARCHAR COLLATE "C" := '0'; + v_fseconds VARCHAR COLLATE "C" := '0'; + v_compmonth_regexp VARCHAR COLLATE "C"; + v_lang_metadata_json JSONB; + v_resmask_cnt SMALLINT := 10; + v_res_datetime TIMESTAMP(6) WITHOUT TIME ZONE; + DAYMM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; + FULLYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{3,4})'; + SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; + COMPYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,4})'; + AMPM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:[AP]M|ص|م)'; + TIMEUNIT_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,2}\s*'; + MASKSEPONE_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(?:/|-)?'; + MASKSEPTWO_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(?:\s|/|-|\.|,)'; + MASKSEPTWO_FI_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(?:\s|/|-|,)'; + MASKSEPTHREE_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(?:/|-|\.|,)'; + TIME_MASKSEP_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:\s|\.|,)*'; + TIME_MASKSEP_FI_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:\s|,)*'; + WEEKDAYAMPM_START_REGEXP CONSTANT VARCHAR COLLATE "C" := '(^|[[:digit:][:space:]\.,])'; + WEEKDAYAMPM_END_REGEXP CONSTANT VARCHAR COLLATE "C" := '([[:digit:][:space:]\.,]|$)(?=[^/-]|$)'; + CORRECTNUM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:([+-]\d{1,4})(?:[[:space:]\.,]|[AP]M|ص|م|$))'; + DATATYPE_REGEXP CONSTANT VARCHAR COLLATE "C" := '^(DATETIME|SMALLDATETIME|DATETIME2)\s*(?:\()?\s*((?:-)?\d+)?\s*(?:\))?$'; + ANNO_DOMINI_REGEXP VARCHAR COLLATE "C" := '(AD|A\.D\.)'; + ANNO_DOMINI_COMPREGEXP VARCHAR COLLATE "C" := pg_catalog.concat(WEEKDAYAMPM_START_REGEXP, ANNO_DOMINI_REGEXP, WEEKDAYAMPM_END_REGEXP); + HHMMSSFS_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := + pg_catalog.concat(TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '\:', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '(?!\d)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?|', + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '\:', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '\:', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '(?!\d)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?|', + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '\:', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '\:', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\s*\d{1,2}\.\d+(?!\d)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?|', + AMPM_REGEXP, '?'); + HHMMSSFS_PART_FI_REGEXP CONSTANT VARCHAR COLLATE "C" := + pg_catalog.concat(TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '[\:\.]', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '(?!\d)', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?\.?|', + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '[\:\.]', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '[\:\.]', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '(?!\d)', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?|', + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '[\:\.]', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '[\:\.]', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, '\s*\d{1,2}\.\d+(?!\d)\.?', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?|', + AMPM_REGEXP, '?'); + v_defmask1_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, + '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_REGEXP, '(?:[\.|,]+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)', TIME_MASKSEP_REGEXP, '$'); + v_defmask1_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, + '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_FI_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:', MASKSEPTWO_FI_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[,]+', AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_FI_REGEXP, '(?:[\.|,]+', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask2_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, + '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_REGEXP, '(?:(?:[\.|,]+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?)|', + CORRECTNUM_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, '$'); + v_defmask2_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, + '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_FI_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_FI_REGEXP, '(?:(?:[\.|,]+', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?)|', + CORRECTNUM_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask3_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, ')|', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + TIME_MASKSEP_REGEXP, '(', TIME_MASKSEP_REGEXP, AMPM_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask3_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + TIME_MASKSEP_FI_REGEXP, '[\./]?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)', + FULLYEAR_REGEXP, + TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask4_0_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, '\s*(', AMPM_REGEXP, ')', + TIME_MASKSEP_REGEXP, '$'); + v_defmask4_1_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:\s|,)+', + DAYMM_REGEXP, '\s*(', AMPM_REGEXP, ')', + TIME_MASKSEP_REGEXP, '$'); + v_defmask4_2_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '\s*[\.]+', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, '\s*(', AMPM_REGEXP, ')', + TIME_MASKSEP_REGEXP, '$'); + v_defmask5_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask5_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask6_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|\.|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_REGEXP, '))?', TIME_MASKSEP_REGEXP, '$'); + v_defmask6_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:\s*[\.])?', + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask7_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|\.|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_REGEXP, '))?', TIME_MASKSEP_REGEXP, '$'); + v_defmask7_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask8_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:[\.|,]+', AMPM_REGEXP, ')?', + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask8_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_FI_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:[\,]+|\s*/\s*)', AMPM_REGEXP, ')?', + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask9_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', + HHMMSSFS_PART_REGEXP, + ')', TIME_MASKSEP_REGEXP, '$'); + v_defmask9_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, '(', + HHMMSSFS_PART_FI_REGEXP, + ')', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask10_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)?', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask10_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)?', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask11_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask11_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask12_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask12_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask13_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$'); + v_defmask13_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask14_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + '($comp_month$)' + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)', TIME_MASKSEP_REGEXP, + COMPYEAR_REGEXP, + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask14_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + '($comp_month$)' + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)', TIME_MASKSEP_FI_REGEXP, + COMPYEAR_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask15_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + COMPYEAR_REGEXP, + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask15_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + COMPYEAR_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask16_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)', TIME_MASKSEP_REGEXP, + COMPYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask16_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)', TIME_MASKSEP_REGEXP, + COMPYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask17_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask17_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask18_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask18_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask19_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|\.|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_REGEXP, '))?', TIME_MASKSEP_REGEXP, '$'); + v_defmask19_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + CONVERSION_LANG CONSTANT VARCHAR COLLATE "C" := ''; + DATE_FORMAT CONSTANT VARCHAR COLLATE "C" := ''; +BEGIN + v_datatype := pg_catalog.btrim(p_datatype); + v_datetimestring := pg_catalog.upper(pg_catalog.btrim(p_datetimestring)); + v_culture := coalesce(nullif(pg_catalog.upper(pg_catalog.btrim(p_culture)), ''), 'EN-US'); + + v_datatype_groups := regexp_matches(v_datatype, DATATYPE_REGEXP, 'gi'); + + v_res_datatype := pg_catalog.upper(v_datatype_groups[1]); + v_scale := v_datatype_groups[2]::SMALLINT; + + IF (v_res_datatype IS NULL) THEN + RAISE datatype_mismatch; + ELSIF (v_res_datatype <> 'DATETIME2' AND v_scale IS NOT NULL) + THEN + RAISE invalid_indicator_parameter_value; + ELSIF (coalesce(v_scale, 0) NOT BETWEEN 0 AND 7) + THEN + RAISE interval_field_overflow; + ELSIF (v_scale IS NULL) THEN + v_scale := 7; + END IF; + + v_dayparts := ARRAY(SELECT pg_catalog.upper(array_to_string(regexp_matches(v_datetimestring, '[AP]M|ص|م', 'gi'), ''))); + + IF (array_length(v_dayparts, 1) > 1) THEN + RAISE invalid_datetime_format; + END IF; + + BEGIN + v_lang_metadata_json := sys.babelfish_get_lang_metadata_json(coalesce(nullif(CONVERSION_LANG, ''), p_culture)); + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_parameter_value; + END; + + v_compday_regexp := array_to_string(array_cat(array_cat(ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'days_names')), + ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'days_shortnames'))), + ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'days_extrashortnames'))), '|'); + + v_weekdaynames := ARRAY(SELECT array_to_string(regexp_matches(v_datetimestring, v_compday_regexp, 'gi'), '')); + + IF (array_length(v_weekdaynames, 1) > 1) THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_weekdaynames[1] IS NOT NULL AND + v_datetimestring ~* pg_catalog.concat(WEEKDAYAMPM_START_REGEXP, '(', v_compday_regexp, ')', WEEKDAYAMPM_END_REGEXP)) + THEN + v_datetimestring := pg_catalog.replace(v_datetimestring, v_weekdaynames[1], ' '); + END IF; + + IF (v_datetimestring ~* ANNO_DOMINI_COMPREGEXP) + THEN + IF (v_culture !~ 'EN[-_]US|DA[-_]DK|SV[-_]SE|EN[-_]GB|HI[-_]IS') THEN + RAISE invalid_datetime_format; + END IF; + + v_datetimestring := regexp_replace(v_datetimestring, + ANNO_DOMINI_COMPREGEXP, + regexp_replace(array_to_string(regexp_matches(v_datetimestring, ANNO_DOMINI_COMPREGEXP, 'gi'), ''), + ANNO_DOMINI_REGEXP, ' ', 'gi'), + 'gi'); + END IF; + + v_date_format := coalesce(nullif(pg_catalog.upper(pg_catalog.btrim(DATE_FORMAT)), ''), v_lang_metadata_json ->> 'date_format'); + + v_compmonth_regexp := + array_to_string(array_cat(array_cat(ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_shortnames')), + ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_names'))), + array_cat(ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_extrashortnames')), + ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_extranames'))) + ), '|'); + + IF ((v_datetimestring ~* v_defmask1_regexp AND v_culture <> 'FI') OR + (v_datetimestring ~* v_defmask1_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_datetimestring ~ pg_catalog.concat(CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV') + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datetimestring, CASE v_culture + WHEN 'FI' THEN v_defmask1_fi_regexp + ELSE v_defmask1_regexp + END, 'gi'); + v_timestring := v_regmatch_groups[2]; + v_correctnum := coalesce(v_regmatch_groups[1], v_regmatch_groups[3], + v_regmatch_groups[5], v_regmatch_groups[6]); + + IF (v_date_format = 'DMY' OR + v_culture IN ('SV-SE', 'SV_SE', 'LV-LV', 'LV_LV')) + THEN + v_day := v_regmatch_groups[4]; + v_month := v_regmatch_groups[7]; + ELSE + v_day := v_regmatch_groups[7]; + v_month := v_regmatch_groups[4]; + END IF; + + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA')) + THEN + IF (v_day::SMALLINT > 30 OR + v_month::SMALLINT > 12) THEN + RAISE invalid_datetime_format; + END IF; + + v_raw_year := to_char(sys.babelfish_conv_greg_to_hijri(current_date + 1), 'YYYY'); + v_hijridate := sys.babelfish_conv_hijri_to_greg(v_day, v_month, v_raw_year) - 1; + + v_day := to_char(v_hijridate, 'DD'); + v_month := to_char(v_hijridate, 'MM'); + v_year := to_char(v_hijridate, 'YYYY')::SMALLINT; + ELSE + v_year := to_char(current_date, 'YYYY')::SMALLINT; + END IF; + + ELSIF ((v_datetimestring ~* v_defmask6_regexp AND v_culture <> 'FI') OR + (v_datetimestring ~* v_defmask6_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA') OR + (v_datetimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{3,4}', + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, '\d{1,2}|', + '\d{3,4}', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}\s*(?:\.)+|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV')) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datetimestring, CASE v_culture + WHEN 'FI' THEN v_defmask6_fi_regexp + ELSE v_defmask6_regexp + END, 'gi'); + v_timestring := pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[5]); + v_day := v_regmatch_groups[4]; + v_month := v_regmatch_groups[3]; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_regmatch_groups[2]::SMALLINT - 543 + ELSE v_regmatch_groups[2]::SMALLINT + END; + + ELSIF ((v_datetimestring ~* v_defmask2_regexp AND v_culture <> 'FI') OR + (v_datetimestring ~* v_defmask2_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA') OR + (v_datetimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{3,4}', + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?))', TIME_MASKSEP_REGEXP, '\d{1,2}|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV')) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datetimestring, CASE v_culture + WHEN 'FI' THEN v_defmask2_fi_regexp + ELSE v_defmask2_regexp + END, 'gi'); + v_timestring := v_regmatch_groups[2]; + v_correctnum := coalesce(v_regmatch_groups[1], v_regmatch_groups[3], v_regmatch_groups[5], + v_regmatch_groups[6], v_regmatch_groups[8], v_regmatch_groups[9]); + v_day := '01'; + v_month := v_regmatch_groups[7]; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_regmatch_groups[4]::SMALLINT - 543 + ELSE v_regmatch_groups[4]::SMALLINT + END; + + ELSIF (v_datetimestring ~* v_defmask4_1_regexp OR + (v_datetimestring ~* v_defmask4_2_regexp AND v_culture !~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV') OR + (v_datetimestring ~* v_defmask9_regexp AND v_culture <> 'FI') OR + (v_datetimestring ~* v_defmask9_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_datetimestring ~ pg_catalog.concat('\d+\s*\.?(?:,+|,*', AMPM_REGEXP, ')', TIME_MASKSEP_FI_REGEXP, '\.+', TIME_MASKSEP_REGEXP, '$|', + '\d+\s*\.', TIME_MASKSEP_FI_REGEXP, '\.', TIME_MASKSEP_FI_REGEXP, '$') AND + v_culture = 'FI') + THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_datetimestring ~* v_defmask4_0_regexp) THEN + v_timestring := (regexp_matches(v_datetimestring, v_defmask4_0_regexp, 'gi'))[1]; + ELSE + v_timestring := v_datetimestring; + END IF; + + v_res_date := current_date; + v_day := to_char(v_res_date, 'DD'); + v_month := to_char(v_res_date, 'MM'); + v_year := to_char(v_res_date, 'YYYY')::SMALLINT; + + ELSIF ((v_datetimestring ~* v_defmask3_regexp AND v_culture <> 'FI') OR + (v_datetimestring ~* v_defmask3_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA') OR + (v_datetimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', + TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, '|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV')) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datetimestring, CASE v_culture + WHEN 'FI' THEN v_defmask3_fi_regexp + ELSE v_defmask3_regexp + END, 'gi'); + v_timestring := v_regmatch_groups[1]; + v_day := '01'; + v_month := v_regmatch_groups[2]; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_regmatch_groups[3]::SMALLINT - 543 + ELSE v_regmatch_groups[3]::SMALLINT + END; + + ELSIF ((v_datetimestring ~* v_defmask5_regexp AND v_culture <> 'FI') OR + (v_datetimestring ~* v_defmask5_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA') OR + (v_datetimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{3,4}', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$|', + '\d{1,2}', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{3,4}\s*(?:\.)+|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV')) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datetimestring, v_defmask5_regexp, 'gi'); + v_timestring := pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[5]); + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_regmatch_groups[4]::SMALLINT - 543 + ELSE v_regmatch_groups[4]::SMALLINT + END; + + IF (v_date_format = 'DMY' OR + v_culture IN ('LV-LV', 'LV_LV')) + THEN + v_day := v_regmatch_groups[2]; + v_month := v_regmatch_groups[3]; + ELSE + v_day := v_regmatch_groups[3]; + v_month := v_regmatch_groups[2]; + END IF; + + ELSIF ((v_datetimestring ~* v_defmask7_regexp AND v_culture <> 'FI') OR + (v_datetimestring ~* v_defmask7_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA') OR + (v_datetimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', + MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{3,4}|', + '\d{3,4}', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}\s*(?:\.)+|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV')) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datetimestring, CASE v_culture + WHEN 'FI' THEN v_defmask7_fi_regexp + ELSE v_defmask7_regexp + END, 'gi'); + v_timestring := pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[5]); + v_day := v_regmatch_groups[4]; + v_month := v_regmatch_groups[2]; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_regmatch_groups[3]::SMALLINT - 543 + ELSE v_regmatch_groups[3]::SMALLINT + END; + + ELSIF ((v_datetimestring ~* v_defmask8_regexp AND v_culture <> 'FI') OR + (v_datetimestring ~* v_defmask8_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_datetimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', + MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}|', + '\d{1,2}', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}\s*(?:\.)+|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'FI|DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV') + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_datetimestring, CASE v_culture + WHEN 'FI' THEN v_defmask8_fi_regexp + ELSE v_defmask8_regexp + END, 'gi'); + v_timestring := pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[5]); + + IF (v_date_format = 'DMY' OR + v_culture IN ('LV-LV', 'LV_LV')) + THEN + v_day := v_regmatch_groups[2]; + v_month := v_regmatch_groups[3]; + v_raw_year := v_regmatch_groups[4]; + ELSIF (v_date_format = 'YMD') + THEN + v_day := v_regmatch_groups[4]; + v_month := v_regmatch_groups[3]; + v_raw_year := v_regmatch_groups[2]; + ELSE + v_day := v_regmatch_groups[3]; + v_month := v_regmatch_groups[2]; + v_raw_year := v_regmatch_groups[4]; + END IF; + + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA')) + THEN + IF (v_day::SMALLINT > 30 OR + v_month::SMALLINT > 12) THEN + RAISE invalid_datetime_format; + END IF; + + v_raw_year := sys.babelfish_get_full_year(v_raw_year, '14'); + v_hijridate := sys.babelfish_conv_hijri_to_greg(v_day, v_month, v_raw_year) - 1; + + v_day := to_char(v_hijridate, 'DD'); + v_month := to_char(v_hijridate, 'MM'); + v_year := to_char(v_hijridate, 'YYYY')::SMALLINT; + + ELSIF (v_culture IN ('TH-TH', 'TH_TH')) THEN + v_year := sys.babelfish_get_full_year(v_raw_year)::SMALLINT - 43; + ELSE + v_year := sys.babelfish_get_full_year(v_raw_year, '', 29)::SMALLINT; + END IF; + ELSE + v_found := FALSE; + END IF; + + WHILE (NOT v_found AND v_resmask_cnt < 20) + LOOP + v_resmask := pg_catalog.replace(CASE v_resmask_cnt + WHEN 10 THEN v_defmask10_regexp + WHEN 11 THEN v_defmask11_regexp + WHEN 12 THEN v_defmask12_regexp + WHEN 13 THEN v_defmask13_regexp + WHEN 14 THEN v_defmask14_regexp + WHEN 15 THEN v_defmask15_regexp + WHEN 16 THEN v_defmask16_regexp + WHEN 17 THEN v_defmask17_regexp + WHEN 18 THEN v_defmask18_regexp + WHEN 19 THEN v_defmask19_regexp + END, + '$comp_month$', v_compmonth_regexp); + + v_resmask_fi := pg_catalog.replace(CASE v_resmask_cnt + WHEN 10 THEN v_defmask10_fi_regexp + WHEN 11 THEN v_defmask11_fi_regexp + WHEN 12 THEN v_defmask12_fi_regexp + WHEN 13 THEN v_defmask13_fi_regexp + WHEN 14 THEN v_defmask14_fi_regexp + WHEN 15 THEN v_defmask15_fi_regexp + WHEN 16 THEN v_defmask16_fi_regexp + WHEN 17 THEN v_defmask17_fi_regexp + WHEN 18 THEN v_defmask18_fi_regexp + WHEN 19 THEN v_defmask19_fi_regexp + END, + '$comp_month$', v_compmonth_regexp); + + IF ((v_datetimestring ~* v_resmask AND v_culture <> 'FI') OR + (v_datetimestring ~* v_resmask_fi AND v_culture = 'FI')) + THEN + v_found := TRUE; + v_regmatch_groups := regexp_matches(v_datetimestring, CASE v_culture + WHEN 'FI' THEN v_resmask_fi + ELSE v_resmask + END, 'gi'); + v_timestring := CASE + WHEN v_resmask_cnt IN (10, 11, 12, 13) THEN pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[4]) + ELSE pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[5]) + END; + + IF (v_resmask_cnt = 10) + THEN + IF (v_regmatch_groups[3] = 'MAR' AND + v_culture IN ('IT-IT', 'IT_IT')) + THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_date_format = 'YMD' AND v_culture NOT IN ('SV-SE', 'SV_SE', 'LV-LV', 'LV_LV')) + THEN + v_day := '01'; + v_year := sys.babelfish_get_full_year(v_regmatch_groups[2], '', 29)::SMALLINT; + ELSE + v_day := v_regmatch_groups[2]; + v_year := to_char(current_date, 'YYYY')::SMALLINT; + END IF; + + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + v_raw_year := to_char(sys.babelfish_conv_greg_to_hijri(current_date + 1), 'YYYY'); + + ELSIF (v_resmask_cnt = 11) + THEN + IF (v_date_format IN ('YMD', 'MDY') AND v_culture NOT IN ('SV-SE', 'SV_SE')) + THEN + v_day := v_regmatch_groups[3]; + v_year := to_char(current_date, 'YYYY')::SMALLINT; + ELSE + v_day := '01'; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN sys.babelfish_get_full_year(v_regmatch_groups[3])::SMALLINT - 43 + ELSE sys.babelfish_get_full_year(v_regmatch_groups[3], '', 29)::SMALLINT + END; + END IF; + + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_raw_year := sys.babelfish_get_full_year(pg_catalog.substring(v_year::TEXT, 3, 2), '14'); + + ELSIF (v_resmask_cnt = 12) + THEN + v_day := '01'; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + v_raw_year := v_regmatch_groups[2]; + + ELSIF (v_resmask_cnt = 13) + THEN + v_day := '01'; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_raw_year := v_regmatch_groups[3]; + + ELSIF (v_resmask_cnt IN (14, 15, 16)) + THEN + IF (v_resmask_cnt = 14) + THEN + v_left_part := v_regmatch_groups[4]; + v_right_part := v_regmatch_groups[3]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + ELSIF (v_resmask_cnt = 15) + THEN + v_left_part := v_regmatch_groups[4]; + v_right_part := v_regmatch_groups[2]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + ELSE + v_left_part := v_regmatch_groups[3]; + v_right_part := v_regmatch_groups[2]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[4], v_lang_metadata_json); + END IF; + + IF (char_length(v_left_part) <= 2) + THEN + IF (v_date_format = 'YMD' AND v_culture NOT IN ('LV-LV', 'LV_LV')) + THEN + v_day := v_left_part; + v_raw_year := sys.babelfish_get_full_year(v_right_part, '14'); + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN sys.babelfish_get_full_year(v_right_part)::SMALLINT - 43 + ELSE sys.babelfish_get_full_year(v_right_part, '', 29)::SMALLINT + END; + BEGIN + v_res_date := make_date(v_year, v_month::SMALLINT, v_day::SMALLINT); + EXCEPTION + WHEN OTHERS THEN + v_day := v_right_part; + v_raw_year := sys.babelfish_get_full_year(v_left_part, '14'); + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN sys.babelfish_get_full_year(v_left_part)::SMALLINT - 43 + ELSE sys.babelfish_get_full_year(v_left_part, '', 29)::SMALLINT + END; + END; + END IF; + + IF (v_date_format IN ('MDY', 'DMY') OR v_culture IN ('LV-LV', 'LV_LV')) + THEN + v_day := v_right_part; + v_raw_year := sys.babelfish_get_full_year(v_left_part, '14'); + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN sys.babelfish_get_full_year(v_left_part)::SMALLINT - 43 + ELSE sys.babelfish_get_full_year(v_left_part, '', 29)::SMALLINT + END; + BEGIN + v_res_date := make_date(v_year, v_month::SMALLINT, v_day::SMALLINT); + EXCEPTION + WHEN OTHERS THEN + v_day := v_left_part; + v_raw_year := sys.babelfish_get_full_year(v_right_part, '14'); + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN sys.babelfish_get_full_year(v_right_part)::SMALLINT - 43 + ELSE sys.babelfish_get_full_year(v_right_part, '', 29)::SMALLINT + END; + END; + END IF; + ELSE + v_day := v_right_part; + v_raw_year := v_left_part; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_left_part::SMALLINT - 543 + ELSE v_left_part::SMALLINT + END; + END IF; + + ELSIF (v_resmask_cnt = 17) + THEN + v_day := v_regmatch_groups[4]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + v_raw_year := v_regmatch_groups[2]; + + ELSIF (v_resmask_cnt = 18) + THEN + v_day := v_regmatch_groups[3]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[4], v_lang_metadata_json); + v_raw_year := v_regmatch_groups[2]; + + ELSIF (v_resmask_cnt = 19) + THEN + v_day := v_regmatch_groups[4]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_raw_year := v_regmatch_groups[3]; + END IF; + + IF (v_resmask_cnt NOT IN (10, 11, 14, 15, 16)) + THEN + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_raw_year::SMALLINT - 543 + ELSE v_raw_year::SMALLINT + END; + END IF; + + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA')) + THEN + IF (v_day::SMALLINT > 30 OR + (v_resmask_cnt NOT IN (10, 11, 14, 15, 16) AND v_year NOT BETWEEN 1318 AND 1501) OR + (v_resmask_cnt IN (14, 15, 16) AND v_raw_year::SMALLINT NOT BETWEEN 1318 AND 1501)) + THEN + RAISE invalid_datetime_format; + END IF; + + v_hijridate := sys.babelfish_conv_hijri_to_greg(v_day, v_month, v_raw_year) - 1; + + v_day := to_char(v_hijridate, 'DD'); + v_month := to_char(v_hijridate, 'MM'); + v_year := to_char(v_hijridate, 'YYYY')::SMALLINT; + END IF; + END IF; + + v_resmask_cnt := v_resmask_cnt + 1; + END LOOP; + + IF (NOT v_found) THEN + RAISE invalid_datetime_format; + END IF; + + IF (char_length(v_timestring) > 0 AND v_timestring NOT IN ('AM', 'ص', 'PM', 'م')) + THEN + IF (v_culture = 'FI') THEN + v_timestring := PG_CATALOG.translate(v_timestring, '.,', ': '); + + IF (char_length(split_part(v_timestring, ':', 4)) > 0) THEN + v_timestring := regexp_replace(v_timestring, ':(?=\s*\d+\s*:?\s*(?:[AP]M|ص|م)?\s*$)', '.'); + END IF; + END IF; + + v_timestring := pg_catalog.replace(regexp_replace(v_timestring, '\.?[AP]M|ص|م|\s|\,|\.\D|[\.|:]$', '', 'gi'), ':.', ':'); + BEGIN + v_hours := coalesce(split_part(v_timestring, ':', 1)::SMALLINT, 0); + + IF ((v_dayparts[1] IN ('AM', 'ص') AND v_hours NOT BETWEEN 0 AND 12) OR + (v_dayparts[1] IN ('PM', 'م') AND v_hours NOT BETWEEN 1 AND 23)) + THEN + RAISE invalid_datetime_format; + ELSIF (v_dayparts[1] = 'PM' AND v_hours < 12) THEN + v_hours := v_hours + 12; + ELSIF (v_dayparts[1] = 'AM' AND v_hours = 12) THEN + v_hours := v_hours - 12; + END IF; + + v_minutes := coalesce(nullif(split_part(v_timestring, ':', 2), '')::SMALLINT, 0); + v_seconds := coalesce(nullif(split_part(v_timestring, ':', 3), ''), '0'); + + IF (v_seconds ~ '\.') THEN + v_fseconds := split_part(v_seconds, '.', 2); + v_seconds := split_part(v_seconds, '.', 1); + END IF; + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_datetime_format; + END; + ELSIF (v_dayparts[1] IN ('PM', 'م')) + THEN + v_hours := 12; + END IF; + + BEGIN + IF (v_res_datatype IN ('DATETIME', 'SMALLDATETIME')) + THEN + v_res_datetime := sys.datetimefromparts(v_year, v_month::SMALLINT, v_day::SMALLINT, + v_hours, v_minutes, v_seconds::SMALLINT, + rpad(v_fseconds, 3, '0')::NUMERIC); + IF (v_res_datatype = 'SMALLDATETIME' AND + to_char(v_res_datetime, 'SS') <> '00') + THEN + IF (to_char(v_res_datetime, 'SS')::SMALLINT >= 30) THEN + v_res_datetime := v_res_datetime + INTERVAL '1 minute'; + END IF; + + v_res_datetime := to_timestamp(to_char(v_res_datetime, 'DD.MM.YYYY.HH24.MI'), 'DD.MM.YYYY.HH24.MI'); + END IF; + ELSE + v_fseconds := sys.babelfish_get_microsecs_from_fractsecs_v2(rpad(v_fseconds, 9, '0'), v_scale); + + -- Following condition will handle overflow of fractsecs + IF (v_fseconds::INTEGER < 0) THEN + v_fseconds := PG_CATALOG.repeat('0', LEAST(v_scale, 6)); + v_seconds := (v_seconds::INTEGER + 1)::TEXT; + END IF; + + v_seconds := pg_catalog.concat_ws('.', v_seconds, v_fseconds); + + v_res_datetime := make_timestamp(v_year, v_month::SMALLINT, v_day::SMALLINT, + v_hours, v_minutes, v_seconds::NUMERIC); + + IF (v_res_datetime > make_timestamp(9999, 12, 31, 23, 59, 59.999999)) THEN + -- if rounding of fractional seconds caused the date and time to go out of range + -- then max date and time that can be stored for p_datatype will be used + v_res_datetime := make_timestamp(9999, 12, 31, 23, 59, pg_catalog.concat_ws('.', '59', PG_CATALOG.repeat('9', LEAST(v_scale, 6)))::NUMERIC); + END IF; + END IF; + EXCEPTION + WHEN OTHERS THEN + GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT; + + IF (v_err_message ~* 'Cannot construct data type') THEN + RAISE invalid_datetime_format; + END IF; + END; + + IF (v_weekdaynames[1] IS NOT NULL) THEN + v_weekdaynum := sys.babelfish_get_weekdaynum_by_name(v_weekdaynames[1], v_lang_metadata_json); + + IF (CASE date_part('dow', v_res_date)::SMALLINT + WHEN 0 THEN 7 + ELSE date_part('dow', v_res_date)::SMALLINT + END <> v_weekdaynum) + THEN + RAISE invalid_datetime_format; + END IF; + END IF; + + RETURN v_res_datetime; +EXCEPTION + WHEN invalid_datetime_format OR datetime_field_overflow THEN + RAISE USING MESSAGE := pg_catalog.format('Error converting string value ''%s'' into data type %s using culture ''%s''.', + p_datetimestring, v_res_datatype, p_culture), + DETAIL := 'Incorrect using of pair of input parameters values during conversion process.', + HINT := 'Check the input parameters values, correct them if needed, and try again.'; + + WHEN datatype_mismatch THEN + RAISE USING MESSAGE := 'Data type should be one of these values: ''DATETIME'', ''SMALLDATETIME'', ''DATETIME2''/''DATETIME2(n)''.', + DETAIL := 'Use of incorrect "datatype" parameter value during conversion process.', + HINT := 'Change "datatype" parameter to the proper value and try again.'; + + WHEN invalid_indicator_parameter_value THEN + RAISE USING MESSAGE := pg_catalog.format('Invalid attributes specified for data type %s.', v_res_datatype), + DETAIL := 'Use of incorrect scale value, which is not corresponding to specified data type.', + HINT := 'Change data type scale component or select different data type and try again.'; + + WHEN interval_field_overflow THEN + RAISE USING MESSAGE := pg_catalog.format('Specified scale %s is invalid.', v_scale), + DETAIL := 'Use of incorrect data type scale value during conversion process.', + HINT := 'Change scale component of data type parameter to be in range [0..7] and try again.'; + + WHEN invalid_parameter_value THEN + RAISE USING MESSAGE := CASE char_length(coalesce(CONVERSION_LANG, '')) + WHEN 0 THEN pg_catalog.format('The culture parameter ''%s'' provided in the function call is not supported.', + p_culture) + ELSE pg_catalog.format('Invalid CONVERSION_LANG constant value - ''%s''. Allowed values are: ''English'', ''Deutsch'', etc.', + CONVERSION_LANG) + END, + DETAIL := 'Passed incorrect value for "p_culture" parameter or compiled incorrect CONVERSION_LANG constant value in function''s body.', + HINT := 'Check "p_culture" input parameter value, correct it if needed, and try again. Also check CONVERSION_LANG constant value.'; + + WHEN invalid_text_representation THEN + GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT; + v_err_message := substring(pg_catalog.lower(v_err_message), 'integer\:\s\"(.*)\"'); + + RAISE USING MESSAGE := pg_catalog.format('Error while trying to convert "%s" value to SMALLINT data type.', + v_err_message), + DETAIL := 'Supplied value contains illegal characters.', + HINT := 'Correct supplied value, remove all illegal characters.'; +END; +$BODY$ +LANGUAGE plpgsql +STABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.babelfish_parse_to_time(IN p_datatype TEXT, + IN p_srctimestring TEXT, + IN p_culture TEXT DEFAULT '') +RETURNS TIME WITHOUT TIME ZONE +AS +$BODY$ +DECLARE + v_day VARCHAR COLLATE "C"; + v_year SMALLINT; + v_month VARCHAR COLLATE "C"; + v_res_date DATE; + v_scale SMALLINT; + v_hijridate DATE; + v_culture VARCHAR COLLATE "C"; + v_dayparts TEXT[]; + v_resmask VARCHAR COLLATE "C"; + v_datatype VARCHAR COLLATE "C"; + v_raw_year VARCHAR COLLATE "C"; + v_left_part VARCHAR COLLATE "C"; + v_right_part VARCHAR COLLATE "C"; + v_resmask_fi VARCHAR COLLATE "C"; + v_timestring VARCHAR COLLATE "C"; + v_correctnum VARCHAR COLLATE "C"; + v_weekdaynum SMALLINT; + v_err_message VARCHAR COLLATE "C"; + v_date_format VARCHAR COLLATE "C"; + v_weekdaynames TEXT[]; + v_hours SMALLINT := 0; + v_srctimestring VARCHAR COLLATE "C"; + v_minutes SMALLINT := 0; + v_res_datatype VARCHAR COLLATE "C"; + v_error_message VARCHAR COLLATE "C"; + v_found BOOLEAN := TRUE; + v_compday_regexp VARCHAR COLLATE "C"; + v_regmatch_groups TEXT[]; + v_datatype_groups TEXT[]; + v_seconds VARCHAR COLLATE "C" := '0'; + v_fseconds VARCHAR COLLATE "C" := '0'; + v_compmonth_regexp VARCHAR COLLATE "C"; + v_lang_metadata_json JSONB; + v_resmask_cnt SMALLINT := 10; + v_res_time TIME WITHOUT TIME ZONE; + DAYMM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; + FULLYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{3,4})'; + SHORTYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,2})'; + COMPYEAR_REGEXP CONSTANT VARCHAR COLLATE "C" := '(\d{1,4})'; + AMPM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:[AP]M|ص|م)'; + TIMEUNIT_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*\d{1,2}\s*'; + MASKSEPONE_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(?:/|-)?'; + MASKSEPTWO_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(?:\s|/|-|\.|,)'; + MASKSEPTWO_FI_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(?:\s|/|-|,)'; + MASKSEPTHREE_REGEXP CONSTANT VARCHAR COLLATE "C" := '\s*(?:/|-|\.|,)'; + TIME_MASKSEP_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:\s|\.|,)*'; + TIME_MASKSEP_FI_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:\s|,)*'; + WEEKDAYAMPM_START_REGEXP CONSTANT VARCHAR COLLATE "C" := '(^|[[:digit:][:space:]\.,])'; + WEEKDAYAMPM_END_REGEXP CONSTANT VARCHAR COLLATE "C" := '([[:digit:][:space:]\.,]|$)(?=[^/-]|$)'; + CORRECTNUM_REGEXP CONSTANT VARCHAR COLLATE "C" := '(?:([+-]\d{1,4})(?:[[:space:]\.,]|[AP]M|ص|م|$))'; + DATATYPE_REGEXP CONSTANT VARCHAR COLLATE "C" := '^(TIME)\s*(?:\()?\s*((?:-)?\d+)?\s*(?:\))?$'; + ANNO_DOMINI_REGEXP VARCHAR COLLATE "C" := '(AD|A\.D\.)'; + ANNO_DOMINI_COMPREGEXP VARCHAR COLLATE "C" := pg_catalog.concat(WEEKDAYAMPM_START_REGEXP, ANNO_DOMINI_REGEXP, WEEKDAYAMPM_END_REGEXP); + HHMMSSFS_PART_REGEXP CONSTANT VARCHAR COLLATE "C" := + pg_catalog.concat(TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '\:', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '(?!\d)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?|', + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '\:', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '\:', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '(?!\d)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?|', + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '\:', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, TIMEUNIT_REGEXP, '\:', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\s*\d{1,2}\.\d+(?!\d)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?|', + AMPM_REGEXP, '?'); + HHMMSSFS_PART_FI_REGEXP CONSTANT VARCHAR COLLATE "C" := + pg_catalog.concat(TIMEUNIT_REGEXP, AMPM_REGEXP, '|', + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '[\:\.]', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '(?!\d)', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?\.?|', + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '[\:\.]', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '[\:\.]', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '(?!\d)', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?|', + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '[\:\.]', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, TIMEUNIT_REGEXP, '[\:\.]', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, '\s*\d{1,2}\.\d+(?!\d)\.?', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?|', + AMPM_REGEXP, '?'); + v_defmask1_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, + '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_REGEXP, '(?:[\.|,]+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)', TIME_MASKSEP_REGEXP, '$'); + v_defmask1_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, + '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_FI_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:', MASKSEPTWO_FI_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[,]+', AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_FI_REGEXP, '(?:[\.|,]+', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask2_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, + '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_REGEXP, '(?:(?:[\.|,]+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?)|', + CORRECTNUM_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, '$'); + v_defmask2_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, + '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_FI_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, + AMPM_REGEXP, TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_FI_REGEXP, '(?:(?:[\.|,]+', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, TIME_MASKSEP_FI_REGEXP, CORRECTNUM_REGEXP, '?)|', + CORRECTNUM_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask3_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, ')|', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + TIME_MASKSEP_REGEXP, '(', TIME_MASKSEP_REGEXP, AMPM_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask3_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + TIME_MASKSEP_FI_REGEXP, '[\./]?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)', + FULLYEAR_REGEXP, + TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask4_0_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, '\s*(', AMPM_REGEXP, ')', + TIME_MASKSEP_REGEXP, '$'); + v_defmask4_1_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:\s|,)+', + DAYMM_REGEXP, '\s*(', AMPM_REGEXP, ')', + TIME_MASKSEP_REGEXP, '$'); + v_defmask4_2_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '\s*[\.]+', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, '\s*(', AMPM_REGEXP, ')', + TIME_MASKSEP_REGEXP, '$'); + v_defmask5_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask5_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask6_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|\.|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_REGEXP, '))?', TIME_MASKSEP_REGEXP, '$'); + v_defmask6_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:\s*[\.])?', + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask7_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|\.|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_REGEXP, '))?', TIME_MASKSEP_REGEXP, '$'); + v_defmask7_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask8_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:[\.|,]+', AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:[\.|,]+', AMPM_REGEXP, ')?', + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask8_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_FI_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)|', + '(?:[,]+', AMPM_REGEXP, '))', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:[\,]+|\s*/\s*)', AMPM_REGEXP, ')?', + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask9_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', + HHMMSSFS_PART_REGEXP, + ')', TIME_MASKSEP_REGEXP, '$'); + v_defmask9_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, '(', + HHMMSSFS_PART_FI_REGEXP, + ')', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask10_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)?', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask10_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)?', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask11_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask11_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask12_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask12_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask13_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$'); + v_defmask13_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask14_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + '($comp_month$)' + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)', TIME_MASKSEP_REGEXP, + COMPYEAR_REGEXP, + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask14_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + '($comp_month$)' + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_FI_REGEXP, AMPM_REGEXP, '?)', TIME_MASKSEP_FI_REGEXP, + COMPYEAR_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask15_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + COMPYEAR_REGEXP, + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask15_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + COMPYEAR_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask16_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)', TIME_MASKSEP_REGEXP, + COMPYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask16_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + DAYMM_REGEXP, + '(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)', TIME_MASKSEP_REGEXP, + COMPYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask17_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask17_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask18_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, '$'); + v_defmask18_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, '(?:', AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))?)|', + '(?:(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '(?=(?:[[:space:]\.,])+))))', TIME_MASKSEP_REGEXP, + '($comp_month$)', + TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, '$'); + v_defmask19_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_REGEXP, '(', HHMMSSFS_PART_REGEXP, ')?', TIME_MASKSEP_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|\.|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_REGEXP, '))?', TIME_MASKSEP_REGEXP, '$'); + v_defmask19_fi_regexp VARCHAR COLLATE "C" := pg_catalog.concat('^', TIME_MASKSEP_FI_REGEXP, '(', HHMMSSFS_PART_FI_REGEXP, ')?', TIME_MASKSEP_FI_REGEXP, + '($comp_month$)', + '(?:', MASKSEPTHREE_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)?', TIME_MASKSEP_REGEXP, + FULLYEAR_REGEXP, + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, + DAYMM_REGEXP, + '((?:(?:\s|,)+|', AMPM_REGEXP, ')(?:', HHMMSSFS_PART_FI_REGEXP, '))?', TIME_MASKSEP_FI_REGEXP, '$'); + CONVERSION_LANG CONSTANT VARCHAR COLLATE "C" := ''; + DATE_FORMAT CONSTANT VARCHAR COLLATE "C" := ''; +BEGIN + v_datatype := pg_catalog.btrim(p_datatype); + v_srctimestring := pg_catalog.upper(pg_catalog.btrim(p_srctimestring)); + v_culture := coalesce(nullif(pg_catalog.upper(pg_catalog.btrim(p_culture)), ''), 'EN-US'); + + v_datatype_groups := regexp_matches(v_datatype, DATATYPE_REGEXP, 'gi'); + + v_res_datatype := pg_catalog.upper(v_datatype_groups[1]); + v_scale := v_datatype_groups[2]::SMALLINT; + + IF (v_res_datatype IS NULL) THEN + RAISE datatype_mismatch; + ELSIF (coalesce(v_scale, 0) NOT BETWEEN 0 AND 7) + THEN + RAISE interval_field_overflow; + ELSIF (v_scale IS NULL) THEN + v_scale := 7; + END IF; + + v_dayparts := ARRAY(SELECT pg_catalog.upper(array_to_string(regexp_matches(v_srctimestring, '[AP]M|ص|م', 'gi'), ''))); + + IF (array_length(v_dayparts, 1) > 1) THEN + RAISE invalid_datetime_format; + END IF; + + BEGIN + v_lang_metadata_json := sys.babelfish_get_lang_metadata_json(coalesce(nullif(CONVERSION_LANG, ''), p_culture)); + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_parameter_value; + END; + + v_compday_regexp := array_to_string(array_cat(array_cat(ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'days_names')), + ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'days_shortnames'))), + ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'days_extrashortnames'))), '|'); + + v_weekdaynames := ARRAY(SELECT array_to_string(regexp_matches(v_srctimestring, v_compday_regexp, 'gi'), '')); + + IF (array_length(v_weekdaynames, 1) > 1) THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_weekdaynames[1] IS NOT NULL AND + v_srctimestring ~* pg_catalog.concat(WEEKDAYAMPM_START_REGEXP, '(', v_compday_regexp, ')', WEEKDAYAMPM_END_REGEXP)) + THEN + v_srctimestring := pg_catalog.replace(v_srctimestring, v_weekdaynames[1], ' '); + END IF; + + IF (v_srctimestring ~* ANNO_DOMINI_COMPREGEXP) + THEN + IF (v_culture !~ 'EN[-_]US|DA[-_]DK|SV[-_]SE|EN[-_]GB|HI[-_]IS') THEN + RAISE invalid_datetime_format; + END IF; + + v_srctimestring := regexp_replace(v_srctimestring, + ANNO_DOMINI_COMPREGEXP, + regexp_replace(array_to_string(regexp_matches(v_srctimestring, ANNO_DOMINI_COMPREGEXP, 'gi'), ''), + ANNO_DOMINI_REGEXP, ' ', 'gi'), + 'gi'); + END IF; + + v_date_format := coalesce(nullif(pg_catalog.upper(pg_catalog.btrim(DATE_FORMAT)), ''), v_lang_metadata_json ->> 'date_format'); + + v_compmonth_regexp := + array_to_string(array_cat(array_cat(ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_shortnames')), + ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_names'))), + array_cat(ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_extrashortnames')), + ARRAY(SELECT jsonb_array_elements_text(v_lang_metadata_json -> 'months_extranames'))) + ), '|'); + + IF ((v_srctimestring ~* v_defmask1_regexp AND v_culture <> 'FI') OR + (v_srctimestring ~* v_defmask1_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_srctimestring ~ pg_catalog.concat(CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, + AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, + CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV') + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_srctimestring, CASE v_culture + WHEN 'FI' THEN v_defmask1_fi_regexp + ELSE v_defmask1_regexp + END, 'gi'); + v_timestring := v_regmatch_groups[2]; + v_correctnum := coalesce(v_regmatch_groups[1], v_regmatch_groups[3], + v_regmatch_groups[5], v_regmatch_groups[6]); + + IF (v_date_format = 'DMY' OR + v_culture IN ('SV-SE', 'SV_SE', 'LV-LV', 'LV_LV')) + THEN + v_day := v_regmatch_groups[4]; + v_month := v_regmatch_groups[7]; + ELSE + v_day := v_regmatch_groups[7]; + v_month := v_regmatch_groups[4]; + END IF; + + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA')) + THEN + IF (v_day::SMALLINT > 30 OR + v_month::SMALLINT > 12) THEN + RAISE invalid_datetime_format; + END IF; + + v_raw_year := to_char(sys.babelfish_conv_greg_to_hijri(current_date + 1), 'YYYY'); + v_hijridate := sys.babelfish_conv_hijri_to_greg(v_day, v_month, v_raw_year) - 1; + + v_day := to_char(v_hijridate, 'DD'); + v_month := to_char(v_hijridate, 'MM'); + v_year := to_char(v_hijridate, 'YYYY')::SMALLINT; + ELSE + v_year := to_char(current_date, 'YYYY')::SMALLINT; + END IF; + + ELSIF ((v_srctimestring ~* v_defmask6_regexp AND v_culture <> 'FI') OR + (v_srctimestring ~* v_defmask6_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA') OR + (v_srctimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{3,4}', + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '))', TIME_MASKSEP_REGEXP, '\d{1,2}|', + '\d{3,4}', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}\s*(?:\.)+|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV')) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_srctimestring, CASE v_culture + WHEN 'FI' THEN v_defmask6_fi_regexp + ELSE v_defmask6_regexp + END, 'gi'); + v_timestring := pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[5]); + v_day := v_regmatch_groups[4]; + v_month := v_regmatch_groups[3]; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_regmatch_groups[2]::SMALLINT - 543 + ELSE v_regmatch_groups[2]::SMALLINT + END; + + ELSIF ((v_srctimestring ~* v_defmask2_regexp AND v_culture <> 'FI') OR + (v_srctimestring ~* v_defmask2_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA') OR + (v_srctimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{3,4}', + '(?:(?:', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?)|', + '(?:', TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?', TIME_MASKSEP_REGEXP, + AMPM_REGEXP, TIME_MASKSEP_REGEXP, CORRECTNUM_REGEXP, '?))', TIME_MASKSEP_REGEXP, '\d{1,2}|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV')) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_srctimestring, CASE v_culture + WHEN 'FI' THEN v_defmask2_fi_regexp + ELSE v_defmask2_regexp + END, 'gi'); + v_timestring := v_regmatch_groups[2]; + v_correctnum := coalesce(v_regmatch_groups[1], v_regmatch_groups[3], v_regmatch_groups[5], + v_regmatch_groups[6], v_regmatch_groups[8], v_regmatch_groups[9]); + v_day := '01'; + v_month := v_regmatch_groups[7]; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_regmatch_groups[4]::SMALLINT - 543 + ELSE v_regmatch_groups[4]::SMALLINT + END; + + ELSIF (v_srctimestring ~* v_defmask4_1_regexp OR + (v_srctimestring ~* v_defmask4_2_regexp AND v_culture !~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV') OR + (v_srctimestring ~* v_defmask9_regexp AND v_culture <> 'FI') OR + (v_srctimestring ~* v_defmask9_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_srctimestring ~ pg_catalog.concat('\d+\s*\.?(?:,+|,*', AMPM_REGEXP, ')', TIME_MASKSEP_FI_REGEXP, '\.+', TIME_MASKSEP_REGEXP, '$|', + '\d+\s*\.', TIME_MASKSEP_FI_REGEXP, '\.', TIME_MASKSEP_FI_REGEXP, '$') AND + v_culture = 'FI') + THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_srctimestring ~* v_defmask4_0_regexp) THEN + v_timestring := (regexp_matches(v_srctimestring, v_defmask4_0_regexp, 'gi'))[1]; + ELSE + v_timestring := v_srctimestring; + END IF; + + v_res_date := current_date; + v_day := to_char(v_res_date, 'DD'); + v_month := to_char(v_res_date, 'MM'); + v_year := to_char(v_res_date, 'YYYY')::SMALLINT; + + ELSIF ((v_srctimestring ~* v_defmask3_regexp AND v_culture <> 'FI') OR + (v_srctimestring ~* v_defmask3_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA') OR + (v_srctimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', + TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, '|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV')) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_srctimestring, CASE v_culture + WHEN 'FI' THEN v_defmask3_fi_regexp + ELSE v_defmask3_regexp + END, 'gi'); + v_timestring := v_regmatch_groups[1]; + v_day := '01'; + v_month := v_regmatch_groups[2]; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_regmatch_groups[3]::SMALLINT - 543 + ELSE v_regmatch_groups[3]::SMALLINT + END; + + ELSIF ((v_srctimestring ~* v_defmask5_regexp AND v_culture <> 'FI') OR + (v_srctimestring ~* v_defmask5_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA') OR + (v_srctimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{3,4}', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$|', + '\d{1,2}', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{3,4}\s*(?:\.)+|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV')) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_srctimestring, v_defmask5_regexp, 'gi'); + v_timestring := pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[5]); + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_regmatch_groups[4]::SMALLINT - 543 + ELSE v_regmatch_groups[4]::SMALLINT + END; + + IF (v_date_format = 'DMY' OR + v_culture IN ('LV-LV', 'LV_LV')) + THEN + v_day := v_regmatch_groups[2]; + v_month := v_regmatch_groups[3]; + ELSE + v_day := v_regmatch_groups[3]; + v_month := v_regmatch_groups[2]; + END IF; + + ELSIF ((v_srctimestring ~* v_defmask7_regexp AND v_culture <> 'FI') OR + (v_srctimestring ~* v_defmask7_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA') OR + (v_srctimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', + MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{3,4}|', + '\d{3,4}', MASKSEPTWO_REGEXP, '?', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}\s*(?:\.)+|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV')) + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_srctimestring, CASE v_culture + WHEN 'FI' THEN v_defmask7_fi_regexp + ELSE v_defmask7_regexp + END, 'gi'); + v_timestring := pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[5]); + v_day := v_regmatch_groups[4]; + v_month := v_regmatch_groups[2]; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_regmatch_groups[3]::SMALLINT - 543 + ELSE v_regmatch_groups[3]::SMALLINT + END; + + ELSIF ((v_srctimestring ~* v_defmask8_regexp AND v_culture <> 'FI') OR + (v_srctimestring ~* v_defmask8_fi_regexp AND v_culture = 'FI')) + THEN + IF (v_srctimestring ~ pg_catalog.concat('\s*\d{1,2}\.\s*(?:\.|\d+(?!\d)\s*\.)', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', + MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}|', + '\d{1,2}', MASKSEPTWO_REGEXP, TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}', MASKSEPTWO_REGEXP, + TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '\d{1,2}\s*(?:\.)+|', + '\d+\s*(?:\.)+', TIME_MASKSEP_REGEXP, AMPM_REGEXP, '?', TIME_MASKSEP_REGEXP, '$') AND + v_culture ~ 'FI|DE[-_]DE|NN[-_]NO|CS[-_]CZ|PL[-_]PL|RO[-_]RO|SK[-_]SK|SL[-_]SI|BG[-_]BG|RU[-_]RU|TR[-_]TR|ET[-_]EE|LV[-_]LV') + THEN + RAISE invalid_datetime_format; + END IF; + + v_regmatch_groups := regexp_matches(v_srctimestring, CASE v_culture + WHEN 'FI' THEN v_defmask8_fi_regexp + ELSE v_defmask8_regexp + END, 'gi'); + v_timestring := pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[5]); + + IF (v_date_format = 'DMY' OR + v_culture IN ('LV-LV', 'LV_LV')) + THEN + v_day := v_regmatch_groups[2]; + v_month := v_regmatch_groups[3]; + v_raw_year := v_regmatch_groups[4]; + ELSIF (v_date_format = 'YMD') + THEN + v_day := v_regmatch_groups[4]; + v_month := v_regmatch_groups[3]; + v_raw_year := v_regmatch_groups[2]; + ELSE + v_day := v_regmatch_groups[3]; + v_month := v_regmatch_groups[2]; + v_raw_year := v_regmatch_groups[4]; + END IF; + + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA')) + THEN + IF (v_day::SMALLINT > 30 OR + v_month::SMALLINT > 12) THEN + RAISE invalid_datetime_format; + END IF; + + v_raw_year := sys.babelfish_get_full_year(v_raw_year, '14'); + v_hijridate := sys.babelfish_conv_hijri_to_greg(v_day, v_month, v_raw_year) - 1; + + v_day := to_char(v_hijridate, 'DD'); + v_month := to_char(v_hijridate, 'MM'); + v_year := to_char(v_hijridate, 'YYYY')::SMALLINT; + + ELSIF (v_culture IN ('TH-TH', 'TH_TH')) THEN + v_year := sys.babelfish_get_full_year(v_raw_year)::SMALLINT - 43; + ELSE + v_year := sys.babelfish_get_full_year(v_raw_year, '', 29)::SMALLINT; + END IF; + ELSE + v_found := FALSE; + END IF; + + WHILE (NOT v_found AND v_resmask_cnt < 20) + LOOP + v_resmask := pg_catalog.replace(CASE v_resmask_cnt + WHEN 10 THEN v_defmask10_regexp + WHEN 11 THEN v_defmask11_regexp + WHEN 12 THEN v_defmask12_regexp + WHEN 13 THEN v_defmask13_regexp + WHEN 14 THEN v_defmask14_regexp + WHEN 15 THEN v_defmask15_regexp + WHEN 16 THEN v_defmask16_regexp + WHEN 17 THEN v_defmask17_regexp + WHEN 18 THEN v_defmask18_regexp + WHEN 19 THEN v_defmask19_regexp + END, + '$comp_month$', v_compmonth_regexp); + + v_resmask_fi := pg_catalog.replace(CASE v_resmask_cnt + WHEN 10 THEN v_defmask10_fi_regexp + WHEN 11 THEN v_defmask11_fi_regexp + WHEN 12 THEN v_defmask12_fi_regexp + WHEN 13 THEN v_defmask13_fi_regexp + WHEN 14 THEN v_defmask14_fi_regexp + WHEN 15 THEN v_defmask15_fi_regexp + WHEN 16 THEN v_defmask16_fi_regexp + WHEN 17 THEN v_defmask17_fi_regexp + WHEN 18 THEN v_defmask18_fi_regexp + WHEN 19 THEN v_defmask19_fi_regexp + END, + '$comp_month$', v_compmonth_regexp); + + IF ((v_srctimestring ~* v_resmask AND v_culture <> 'FI') OR + (v_srctimestring ~* v_resmask_fi AND v_culture = 'FI')) + THEN + v_found := TRUE; + v_regmatch_groups := regexp_matches(v_srctimestring, CASE v_culture + WHEN 'FI' THEN v_resmask_fi + ELSE v_resmask + END, 'gi'); + v_timestring := CASE + WHEN v_resmask_cnt IN (10, 11, 12, 13) THEN pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[4]) + ELSE pg_catalog.concat(v_regmatch_groups[1], v_regmatch_groups[5]) + END; + + IF (v_resmask_cnt = 10) + THEN + IF (v_regmatch_groups[3] = 'MAR' AND + v_culture IN ('IT-IT', 'IT_IT')) + THEN + RAISE invalid_datetime_format; + END IF; + + IF (v_date_format = 'YMD' AND v_culture NOT IN ('SV-SE', 'SV_SE', 'LV-LV', 'LV_LV')) + THEN + v_day := '01'; + v_year := sys.babelfish_get_full_year(v_regmatch_groups[2], '', 29)::SMALLINT; + ELSE + v_day := v_regmatch_groups[2]; + v_year := to_char(current_date, 'YYYY')::SMALLINT; + END IF; + + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + v_raw_year := to_char(sys.babelfish_conv_greg_to_hijri(current_date + 1), 'YYYY'); + + ELSIF (v_resmask_cnt = 11) + THEN + IF (v_date_format IN ('YMD', 'MDY') AND v_culture NOT IN ('SV-SE', 'SV_SE')) + THEN + v_day := v_regmatch_groups[3]; + v_year := to_char(current_date, 'YYYY')::SMALLINT; + ELSE + v_day := '01'; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN sys.babelfish_get_full_year(v_regmatch_groups[3])::SMALLINT - 43 + ELSE sys.babelfish_get_full_year(v_regmatch_groups[3], '', 29)::SMALLINT + END; + END IF; + + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_raw_year := sys.babelfish_get_full_year(pg_catalog.substring(v_year::TEXT, 3, 2), '14'); + + ELSIF (v_resmask_cnt = 12) + THEN + v_day := '01'; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + v_raw_year := v_regmatch_groups[2]; + + ELSIF (v_resmask_cnt = 13) + THEN + v_day := '01'; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_raw_year := v_regmatch_groups[3]; + + ELSIF (v_resmask_cnt IN (14, 15, 16)) + THEN + IF (v_resmask_cnt = 14) + THEN + v_left_part := v_regmatch_groups[4]; + v_right_part := v_regmatch_groups[3]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + ELSIF (v_resmask_cnt = 15) + THEN + v_left_part := v_regmatch_groups[4]; + v_right_part := v_regmatch_groups[2]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + ELSE + v_left_part := v_regmatch_groups[3]; + v_right_part := v_regmatch_groups[2]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[4], v_lang_metadata_json); + END IF; + + IF (char_length(v_left_part) <= 2) + THEN + IF (v_date_format = 'YMD' AND v_culture NOT IN ('LV-LV', 'LV_LV')) + THEN + v_day := v_left_part; + v_raw_year := sys.babelfish_get_full_year(v_right_part, '14'); + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN sys.babelfish_get_full_year(v_right_part)::SMALLINT - 43 + ELSE sys.babelfish_get_full_year(v_right_part, '', 29)::SMALLINT + END; + BEGIN + v_res_date := make_date(v_year, v_month::SMALLINT, v_day::SMALLINT); + EXCEPTION + WHEN OTHERS THEN + v_day := v_right_part; + v_raw_year := sys.babelfish_get_full_year(v_left_part, '14'); + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN sys.babelfish_get_full_year(v_left_part)::SMALLINT - 43 + ELSE sys.babelfish_get_full_year(v_left_part, '', 29)::SMALLINT + END; + END; + END IF; + + IF (v_date_format IN ('MDY', 'DMY') OR v_culture IN ('LV-LV', 'LV_LV')) + THEN + v_day := v_right_part; + v_raw_year := sys.babelfish_get_full_year(v_left_part, '14'); + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN sys.babelfish_get_full_year(v_left_part)::SMALLINT - 43 + ELSE sys.babelfish_get_full_year(v_left_part, '', 29)::SMALLINT + END; + BEGIN + v_res_date := make_date(v_year, v_month::SMALLINT, v_day::SMALLINT); + EXCEPTION + WHEN OTHERS THEN + v_day := v_left_part; + v_raw_year := sys.babelfish_get_full_year(v_right_part, '14'); + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN sys.babelfish_get_full_year(v_right_part)::SMALLINT - 43 + ELSE sys.babelfish_get_full_year(v_right_part, '', 29)::SMALLINT + END; + END; + END IF; + ELSE + v_day := v_right_part; + v_raw_year := v_left_part; + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_left_part::SMALLINT - 543 + ELSE v_left_part::SMALLINT + END; + END IF; + + ELSIF (v_resmask_cnt = 17) + THEN + v_day := v_regmatch_groups[4]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[3], v_lang_metadata_json); + v_raw_year := v_regmatch_groups[2]; + + ELSIF (v_resmask_cnt = 18) + THEN + v_day := v_regmatch_groups[3]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[4], v_lang_metadata_json); + v_raw_year := v_regmatch_groups[2]; + + ELSIF (v_resmask_cnt = 19) + THEN + v_day := v_regmatch_groups[4]; + v_month := sys.babelfish_get_monthnum_by_name(v_regmatch_groups[2], v_lang_metadata_json); + v_raw_year := v_regmatch_groups[3]; + END IF; + + IF (v_resmask_cnt NOT IN (10, 11, 14, 15, 16)) + THEN + v_year := CASE + WHEN v_culture IN ('TH-TH', 'TH_TH') THEN v_raw_year::SMALLINT - 543 + ELSE v_raw_year::SMALLINT + END; + END IF; + + IF (v_culture IN ('AR', 'AR-SA', 'AR_SA')) + THEN + IF (v_day::SMALLINT > 30 OR + (v_resmask_cnt NOT IN (10, 11, 14, 15, 16) AND v_year NOT BETWEEN 1318 AND 1501) OR + (v_resmask_cnt IN (14, 15, 16) AND v_raw_year::SMALLINT NOT BETWEEN 1318 AND 1501)) + THEN + RAISE invalid_datetime_format; + END IF; + + v_hijridate := sys.babelfish_conv_hijri_to_greg(v_day, v_month, v_raw_year) - 1; + + v_day := to_char(v_hijridate, 'DD'); + v_month := to_char(v_hijridate, 'MM'); + v_year := to_char(v_hijridate, 'YYYY')::SMALLINT; + END IF; + END IF; + + v_resmask_cnt := v_resmask_cnt + 1; + END LOOP; + + IF (NOT v_found) THEN + RAISE invalid_datetime_format; + END IF; + + v_res_date := make_date(v_year, v_month::SMALLINT, v_day::SMALLINT); + + IF (v_weekdaynames[1] IS NOT NULL) THEN + v_weekdaynum := sys.babelfish_get_weekdaynum_by_name(v_weekdaynames[1], v_lang_metadata_json); + + IF (date_part('dow', v_res_date)::SMALLINT <> v_weekdaynum) THEN + RAISE invalid_datetime_format; + END IF; + END IF; + + IF (char_length(v_timestring) > 0 AND v_timestring NOT IN ('AM', 'ص', 'PM', 'م')) + THEN + IF (v_culture = 'FI') THEN + v_timestring := PG_CATALOG.translate(v_timestring, '.,', ': '); + + IF (char_length(split_part(v_timestring, ':', 4)) > 0) THEN + v_timestring := regexp_replace(v_timestring, ':(?=\s*\d+\s*:?\s*(?:[AP]M|ص|م)?\s*$)', '.'); + END IF; + END IF; + + v_timestring := pg_catalog.replace(regexp_replace(v_timestring, '\.?[AP]M|ص|م|\s|\,|\.\D|[\.|:]$', '', 'gi'), ':.', ':'); + + BEGIN + v_hours := coalesce(split_part(v_timestring, ':', 1)::SMALLINT, 0); + + IF ((v_dayparts[1] IN ('AM', 'ص') AND v_hours NOT BETWEEN 0 AND 12) OR + (v_dayparts[1] IN ('PM', 'م') AND v_hours NOT BETWEEN 1 AND 23)) + THEN + RAISE invalid_datetime_format; + ELSIF (v_dayparts[1] = 'PM' AND v_hours < 12) THEN + v_hours := v_hours + 12; + ELSIF (v_dayparts[1] = 'AM' AND v_hours = 12) THEN + v_hours := v_hours - 12; + END IF; + + v_minutes := coalesce(nullif(split_part(v_timestring, ':', 2), '')::SMALLINT, 0); + v_seconds := coalesce(nullif(split_part(v_timestring, ':', 3), ''), '0'); + + IF (v_seconds ~ '\.') THEN + v_fseconds := split_part(v_seconds, '.', 2); + v_seconds := split_part(v_seconds, '.', 1); + END IF; + EXCEPTION + WHEN OTHERS THEN + RAISE invalid_datetime_format; + END; + ELSIF (v_dayparts[1] IN ('PM', 'م')) + THEN + v_hours := 12; + END IF; + + v_fseconds := sys.babelfish_get_microsecs_from_fractsecs_v2(rpad(v_fseconds, 9, '0'), v_scale); + -- Following condition will handle overflow of fractsecs + IF (v_fseconds::INTEGER < 0) THEN + v_fseconds := PG_CATALOG.repeat('0', LEAST(v_scale, 6)); + v_seconds := (v_seconds::INTEGER + 1)::TEXT; + END IF; + + v_seconds := pg_catalog.concat_ws('.', v_seconds, v_fseconds); + + v_res_time := make_time(v_hours, v_minutes, v_seconds::NUMERIC); + + IF (v_res_time > make_time(23, 59, 59.999999)) THEN + -- if rounding of fractional seconds caused the time to go out of range + -- then max time that can be stored for time will be used + v_res_time := make_time(23, 59, pg_catalog.concat_ws('.', '59', PG_CATALOG.repeat('9', LEAST(v_scale, 6)))::NUMERIC); + END IF; + + RETURN v_res_time; +EXCEPTION + WHEN invalid_datetime_format OR datetime_field_overflow THEN + RAISE USING MESSAGE := pg_catalog.format('Error converting string value ''%s'' into data type %s using culture ''%s''.', + p_srctimestring, v_res_datatype, p_culture), + DETAIL := 'Incorrect using of pair of input parameters values during conversion process.', + HINT := 'Check the input parameters values, correct them if needed, and try again.'; + + WHEN datatype_mismatch THEN + RAISE USING MESSAGE := 'Source data type should be ''TIME'' or ''TIME(n)''.', + DETAIL := 'Use of incorrect "datatype" parameter value during conversion process.', + HINT := 'Change "datatype" parameter to the proper value and try again.'; + + WHEN invalid_indicator_parameter_value THEN + RAISE USING MESSAGE := pg_catalog.format('Invalid attributes specified for data type %s.', v_res_datatype), + DETAIL := 'Use of incorrect scale value, which is not corresponding to specified data type.', + HINT := 'Change data type scale component or select different data type and try again.'; + + WHEN interval_field_overflow THEN + RAISE USING MESSAGE := pg_catalog.format('Specified scale %s is invalid.', v_scale), + DETAIL := 'Use of incorrect data type scale value during conversion process.', + HINT := 'Change scale component of data type parameter to be in range [0..7] and try again.'; + + WHEN invalid_parameter_value THEN + RAISE USING MESSAGE := CASE char_length(coalesce(CONVERSION_LANG, '')) + WHEN 0 THEN pg_catalog.format('The culture parameter ''%s'' provided in the function call is not supported.', + p_culture) + ELSE pg_catalog.format('Invalid CONVERSION_LANG constant value - ''%s''. Allowed values are: ''English'', ''Deutsch'', etc.', + CONVERSION_LANG) + END, + DETAIL := 'Passed incorrect value for "p_culture" parameter or compiled incorrect CONVERSION_LANG constant value in function''s body.', + HINT := 'Check "p_culture" input parameter value, correct it if needed, and try again. Also check CONVERSION_LANG constant value.'; + + WHEN invalid_text_representation THEN + GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT; + v_err_message := substring(pg_catalog.lower(v_err_message), 'integer\:\s\"(.*)\"'); + + RAISE USING MESSAGE := pg_catalog.format('Error while trying to convert "%s" value to SMALLINT data type.', + v_err_message), + DETAIL := 'Supplied value contains illegal characters.', + HINT := 'Correct supplied value, remove all illegal characters.'; +END; +$BODY$ +LANGUAGE plpgsql +STABLE +RETURNS NULL ON NULL INPUT; + +CREATE OR REPLACE FUNCTION sys.date_bucket(IN datepart PG_CATALOG.TEXT, IN number INTEGER, IN date ANYELEMENT, IN origin ANYELEMENT default NULL) RETURNS ANYELEMENT +AS +$body$ +DECLARE + required_bucket INT; + years_diff INT; + quarters_diff INT; + months_diff INT; + hours_diff INT; + minutes_diff INT; + seconds_diff INT; + milliseconds_diff INT; + timezone INT; + result_time time; + result_date timestamp; + offset_string PG_CATALOG.text; + date_difference_interval INTERVAL; + millisec_trunc_diff_interval INTERVAL; + date_arg_datatype regtype; + is_valid boolean; +BEGIN + BEGIN + date_arg_datatype := pg_typeof(date); + is_valid := sys.date_bucket_internal_helper(datepart, number, true, true, date); + + -- If optional argument origin's value is not provided by user then set it's default value of valid datatype. + IF origin IS NULL THEN + IF date_arg_datatype = 'sys.datetime'::regtype THEN + origin := CAST('1900-01-01 00:00:00.000' AS sys.datetime); + ELSIF date_arg_datatype = 'sys.datetime2'::regtype THEN + origin := CAST('1900-01-01 00:00:00.000' AS sys.datetime2); + ELSIF date_arg_datatype = 'sys.datetimeoffset'::regtype THEN + origin := CAST('1900-01-01 00:00:00.000' AS sys.datetimeoffset); + ELSIF date_arg_datatype = 'sys.smalldatetime'::regtype THEN + origin := CAST('1900-01-01 00:00:00.000' AS sys.smalldatetime); + ELSIF date_arg_datatype = 'date'::regtype THEN + origin := CAST('1900-01-01 00:00:00.000' AS pg_catalog.date); + ELSIF date_arg_datatype = 'time'::regtype THEN + origin := CAST('00:00:00.000' AS pg_catalog.time); + END IF; + END IF; + END; + + /* support of date_bucket() for different kinds of date datatype starts here */ + -- support of date_bucket() when date is of 'time' datatype + IF date_arg_datatype = 'time'::regtype THEN + -- Find interval between date and origin and extract hour, minute, second, millisecond from the interval + date_difference_interval := date_trunc('millisecond', date) - date_trunc('millisecond', origin); + hours_diff := EXTRACT('hour' from date_difference_interval)::INT; + minutes_diff := EXTRACT('minute' from date_difference_interval)::INT; + seconds_diff := FLOOR(EXTRACT('second' from date_difference_interval))::INT; + milliseconds_diff := FLOOR(EXTRACT('millisecond' from date_difference_interval))::INT; + CASE datepart + WHEN 'hour' THEN + -- Here we are finding how many buckets we have to add in the origin so that we can reach to a bucket in which date belongs. + -- For cases where origin > date, we might end up in a bucket which exceeds date by 1 bucket. + -- For Ex. 'date_bucket(hour, 2, '01:00:00', '08:00:00')' hence check if the result_time is greater then date + -- For comparision we are trunceting the result_time to milliseconds + required_bucket := hours_diff/number; + result_time := origin + make_interval(hours => required_bucket * number); + IF date_trunc('millisecond', result_time) > date THEN + RETURN result_time - make_interval(hours => number); + END IF; + RETURN result_time; + + WHEN 'minute' THEN + required_bucket := (hours_diff * 60 + minutes_diff)/number; + result_time := origin + make_interval(mins => required_bucket * number); + IF date_trunc('millisecond', result_time) > date THEN + RETURN result_time - make_interval(mins => number); + END IF; + RETURN result_time; + + WHEN 'second' THEN + required_bucket := ((hours_diff * 60 + minutes_diff) * 60 + seconds_diff)/number; + result_time := origin + make_interval(secs => required_bucket * number); + IF date_trunc('millisecond', result_time) > date THEN + RETURN result_time - make_interval(secs => number); + END IF; + RETURN result_time; + + WHEN 'millisecond' THEN + required_bucket := (((hours_diff * 60 + minutes_diff) * 60) * 1000 + milliseconds_diff)/number; + result_time := origin + make_interval(secs => ((required_bucket * number)::numeric) * 0.001); + IF date_trunc('millisecond', result_time) > date THEN + RETURN result_time - make_interval(secs => (number::numeric) * 0.001); + END IF; + RETURN result_time; + END CASE; + + -- support of date_bucket() when date is of {'datetime2', 'datetimeoffset'} datatype + -- handling separately because both the datatypes have precision in milliseconds + ELSIF date_arg_datatype IN ('sys.datetime2'::regtype, 'sys.datetimeoffset'::regtype) THEN + -- when datepart is {year, quarter, month} make use of AGE() function to find number of buckets + IF datepart IN ('year', 'quarter', 'month') THEN + date_difference_interval := AGE(date_trunc('day', date::timestamp), date_trunc('day', origin::timestamp)); + years_diff := EXTRACT('Year' from date_difference_interval)::INT; + months_diff := EXTRACT('Month' from date_difference_interval)::INT; + CASE datepart + WHEN 'year' THEN + -- Here we are finding how many buckets we have to add in the origin so that we can reach to a bucket in which date belongs. + -- For cases where origin > date, we might end up in a bucket which exceeds date by 1 bucket. + -- For Ex. date_bucket(year, 2, '2010-01-01', '2019-01-01')) hence check if the result_time is greater then date. + -- For comparision we are trunceting the result_time to milliseconds + required_bucket := years_diff/number; + result_date := origin::timestamp + make_interval(years => required_bucket * number); + IF result_date > date::timestamp THEN + result_date = result_date - make_interval(years => number); + END IF; + + WHEN 'month' THEN + required_bucket := (12 * years_diff + months_diff)/number; + result_date := origin::timestamp + make_interval(months => required_bucket * number); + IF result_date > date::timestamp THEN + result_date = result_date - make_interval(months => number); + END IF; + + WHEN 'quarter' THEN + quarters_diff := (12 * years_diff + months_diff)/3; + required_bucket := quarters_diff/number; + result_date := origin::timestamp + make_interval(months => required_bucket * number * 3); + IF result_date > date::timestamp THEN + result_date = result_date - make_interval(months => number*3); + END IF; + END CASE; + + -- when datepart is {week, day, hour, minute, second, millisecond} make use of built-in date_bin() postgresql function. + ELSE + -- trunceting origin to millisecond before passing it to date_bin() function. + -- store the difference between origin and trunceted origin to add it in the result of date_bin() function + date_difference_interval := concat(number, ' ', datepart)::INTERVAL; + millisec_trunc_diff_interval := (origin::timestamp - date_trunc('millisecond', origin::timestamp))::interval; + result_date = date_bin(date_difference_interval, date::timestamp, date_trunc('millisecond', origin::timestamp)) + millisec_trunc_diff_interval; + + -- Filetering cases where the required bucket ends at date then date_bin() gives start point of this bucket as result. + IF result_date + date_difference_interval <= date::timestamp THEN + result_date = result_date + date_difference_interval; + END IF; + END IF; + + -- All the above operations are performed by converting every date datatype into TIMESTAMPS. + -- datetimeoffset is typecasted into TIMESTAMPS that changes the value. + -- Ex. '2023-02-23 09:19:21.23 +10:12'::sys.datetimeoffset::timestamp => '2023-02-22 23:07:21.23' + -- The output of date_bucket() for datetimeoffset datatype will always be in the same time-zone as of provided date argument. + -- Here, converting TIMESTAMP into datetimeoffset datatype with the same timezone as of date argument. + IF date_arg_datatype = 'sys.datetimeoffset'::regtype THEN + timezone = sys.babelfish_get_datetimeoffset_tzoffset(date)::INTEGER; + offset_string = right(date::PG_CATALOG.TEXT, 6); + result_date = result_date + make_interval(mins => timezone); + RETURN concat(result_date, ' ', offset_string)::sys.datetimeoffset; + ELSE + RETURN result_date; + END IF; + + -- support of date_bucket() when date is of {'date', 'datetime', 'smalldatetime'} datatype + ELSE + -- Round datetime to fixed bins (e.g. .000, .003, .007) + IF date_arg_datatype = 'sys.datetime'::regtype THEN + date := sys.babelfish_conv_string_to_datetime_v2('DATETIME', date::TEXT)::sys.datetime; + origin := sys.babelfish_conv_string_to_datetime_v2('DATETIME', origin::TEXT)::sys.datetime; + END IF; + -- when datepart is {year, quarter, month} make use of AGE() function to find number of buckets + IF datepart IN ('year', 'quarter', 'month') THEN + date_difference_interval := AGE(date_trunc('day', date::timestamp), date_trunc('day', origin::timestamp)); + years_diff := EXTRACT('Year' from date_difference_interval)::INT; + months_diff := EXTRACT('Month' from date_difference_interval)::INT; + CASE datepart + WHEN 'year' THEN + -- Here we are finding how many buckets we have to add in the origin so that we can reach to a bucket in which date belongs. + -- For cases where origin > date, we might end up in a bucket which exceeds date by 1 bucket. + -- For Example. date_bucket(year, 2, '2010-01-01', '2019-01-01') hence check if the result_time is greater then date. + -- For comparision we are trunceting the result_time to milliseconds + required_bucket := years_diff/number; + result_date := origin::timestamp + make_interval(years => required_bucket * number); + IF result_date > date::timestamp THEN + result_date = result_date - make_interval(years => number); + END IF; + + WHEN 'month' THEN + required_bucket := (12 * years_diff + months_diff)/number; + result_date := origin::timestamp + make_interval(months => required_bucket * number); + IF result_date > date::timestamp THEN + result_date = result_date - make_interval(months => number); + END IF; + + WHEN 'quarter' THEN + quarters_diff := (12 * years_diff + months_diff)/3; + required_bucket := quarters_diff/number; + result_date := origin::timestamp + make_interval(months => required_bucket * number * 3); + IF result_date > date::timestamp THEN + result_date = result_date - make_interval(months => number * 3); + END IF; + END CASE; + RETURN result_date; + + -- when datepart is {week, day, hour, minute, second, millisecond} make use of built-in date_bin() postgresql function. + ELSE + -- trunceting origin to millisecond before passing it to date_bin() function. + -- store the difference between origin and trunceted origin to add it in the result of date_bin() function + date_difference_interval := concat(number, ' ', datepart)::INTERVAL; + result_date = date_bin(date_difference_interval, date::TIMESTAMP, origin::TIMESTAMP); + -- Filetering cases where the required bucket ends at date then date_bin() gives start point of this bucket as result. + IF result_date + date_difference_interval <= date::TIMESTAMP THEN + result_date = result_date + date_difference_interval; + END IF; + RETURN result_date; + END IF; + END IF; +END; +$body$ +LANGUAGE plpgsql IMMUTABLE; + +ALTER FUNCTION sys.babelfish_conv_hijri_to_greg(IN p_dateval DATE) IMMUTABLE; +ALTER FUNCTION sys.babelfish_conv_hijri_to_greg(IN p_day NUMERIC, IN p_month NUMERIC, IN p_year NUMERIC) IMMUTABLE; +ALTER FUNCTION sys.babelfish_conv_hijri_to_greg(IN p_day TEXT, IN p_month TEXT, IN p_year TEXT) IMMUTABLE; +ALTER FUNCTION sys.babelfish_conv_hijri_to_greg(IN p_datetimeval TIMESTAMP WITHOUT TIME ZONE) IMMUTABLE; +ALTER FUNCTION sys.babelfish_get_full_year(IN p_short_year TEXT, IN p_base_century TEXT, IN p_year_cutoff NUMERIC) IMMUTABLE; +ALTER FUNCTION sys.babelfish_get_int_part(IN p_srcnumber DOUBLE PRECISION) IMMUTABLE; + +CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_try_conv_string_to_date'); +CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_conv_string_to_date'); + +CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_conv_helper_to_time_with_arg_text_deprecated_in_5_1_0'); +CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_conv_helper_to_time_with_arg_anyelement_deprecated_in_5_1_0'); +DO $$ +BEGIN + IF (NOT EXISTS(SELECT * FROM pg_proc + WHERE proname = 'babelfish_conv_helper_to_time_with_arg_text_deprecated_in_5_1_0' AND + pronamespace = 'sys'::regnamespace::oid)) + THEN + CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_try_conv_string_to_time'); + CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_conv_string_to_time'); + END IF; +END; +$$; + +CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_conv_helper_to_datetime_deprecated_in_5_1_0'); +DO $$ +BEGIN + IF (NOT EXISTS (SELECT * FROM pg_proc + WHERE proname = 'babelfish_conv_helper_to_datetime_deprecated_in_2_3_0_1' AND + pronamespace = 'sys'::regnamespace::oid) AND + NOT EXISTS (SELECT * FROM pg_proc + WHERE proname like 'babelfish_conv_helper_to_datetime_deprecated_in_5_1_0' AND + pronamespace = 'sys'::regnamespace::oid)) + THEN + CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_try_conv_string_to_datetime'); + CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_conv_string_to_datetime'); + END IF; +END; +$$; + +DO $$ +BEGIN + IF (NOT EXISTS(SELECT * FROM pg_proc + WHERE proname = 'babelfish_conv_string_to_datetime' AND + pronamespace = 'sys'::regnamespace::oid) AND + NOT EXISTS(SELECT * FROM pg_proc + WHERE proname = 'babelfish_conv_string_to_time' AND + pronamespace = 'sys'::regnamespace::oid)) + THEN + CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_get_microsecs_from_fractsecs'); + END IF; +END; +$$; + -- After upgrade, always run analyze for all babelfish catalogs. CALL sys.analyze_babelfish_catalogs(); -- Reset search_path to not affect any subsequent scripts diff --git a/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-epilogue.y.c b/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-epilogue.y.c index 1fe565df87..fb21c14d56 100644 --- a/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-epilogue.y.c +++ b/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-epilogue.y.c @@ -196,11 +196,60 @@ TsqlFunctionConvert(TypeName *typename, Node *arg, Node *style, bool try, int lo result = (Node *) makeFuncCall(TsqlSystemFuncName("babelfish_conv_helper_to_date"), args, COERCE_EXPLICIT_CALL, location); else if (type_oid == TIMEOID) - result = (Node *) makeFuncCall(TsqlSystemFuncName("babelfish_conv_helper_to_time"), args, COERCE_EXPLICIT_CALL, location); - + { + Node *helperFuncCall; + helperFuncCall = (Node *) makeFuncCall(TsqlSystemFuncName("babelfish_conv_helper_to_time"), lcons(makeIntConst(typmod, location), args), COERCE_EXPLICIT_CALL, location); + + /* + * add a type cast on top of the CONVERT helper function + * so typmod can be applied + */ + result = makeTypeCast(helperFuncCall, typename, location); + } else if (type_oid == typenameTypeId(NULL, makeTypeName("datetime"))) - result = (Node *) makeFuncCall(TsqlSystemFuncName("babelfish_conv_helper_to_datetime"), args, COERCE_EXPLICIT_CALL, location); - + { + Node *helperFuncCall; + helperFuncCall = (Node *) makeFuncCall(TsqlSystemFuncName("babelfish_conv_helper_to_datetime"), lcons(makeIntConst(typmod, location), args), COERCE_EXPLICIT_CALL, location); + + /* + * add a type cast on top of the CONVERT helper function + * so typmod can be applied + */ + result = makeTypeCast(helperFuncCall, typename, location); + } + else if (type_oid == typenameTypeId(NULL, makeTypeName("datetime2"))) + { + Node *helperFuncCall; + helperFuncCall = (Node *) makeFuncCall(TsqlSystemFuncName("babelfish_conv_helper_to_datetime2"), lcons(makeIntConst(typmod, location), args), COERCE_EXPLICIT_CALL, location); + + /* + * add a type cast on top of the CONVERT helper function + * so typmod can be applied + */ + result = makeTypeCast(helperFuncCall, typename, location); + } + else if (type_oid == typenameTypeId(NULL, makeTypeName("datetimeoffset"))) + { + Node *helperFuncCall; + helperFuncCall = (Node *) makeFuncCall(TsqlSystemFuncName("babelfish_conv_helper_to_datetimeoffset"), lcons(makeIntConst(typmod, location), args), COERCE_EXPLICIT_CALL, location); + + /* + * add a type cast on top of the CONVERT helper function + * so typmod can be applied + */ + result = makeTypeCast(helperFuncCall, typename, location); + } + else if (type_oid == typenameTypeId(NULL, makeTypeName("smalldatetime"))) + { + Node *helperFuncCall; + helperFuncCall = (Node *) makeFuncCall(TsqlSystemFuncName("babelfish_conv_helper_to_smalldatetime"), lcons(makeIntConst(typmod, location), args), COERCE_EXPLICIT_CALL, location); + + /* + * add a type cast on top of the CONVERT helper function + * so typmod can be applied + */ + result = makeTypeCast(helperFuncCall, typename, location); + } else if ((strcmp(typename_string, "varchar") == 0) || (strcmp(typename_string, "nvarchar") == 0) || (strcmp(typename_string, "bpchar") == 0) || (strcmp(typename_string, "nchar") == 0)) { diff --git a/test/JDBC/expected/9809_1.out b/test/JDBC/expected/9809_1.out new file mode 100644 index 0000000000..7bf41f2550 --- /dev/null +++ b/test/JDBC/expected/9809_1.out @@ -0,0 +1,368 @@ + +-- simple batch start +GO + + +SELECT CONVERT(DATE, '10-10-10', 140) +GO +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 140 is not supported for conversions from varchar to date.)~~ + +GO + + +begin transaction +GO +GO + + +SELECT CONVERT(DATE, '10-10-10', 140) +GO +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 140 is not supported for conversions from varchar to date.)~~ + + + +-- Below output is only applicable if query is special case. for example, CREATE/ALTER TRIGGER, CREATE/ALTER FUNCTION, CREATE/ALTER PROC, CREATE/ALTER VIEW etc +if (@@trancount > 0) select cast('compile time error' as text) else select cast('runtime error' as text) +GO +~~START~~ +text +compile time error +~~END~~ + + +if (@@trancount > 0) rollback tran +GO + +GO + + +-- simple batch end +GO + +create schema error_mapping; +GO +-- Next portion is to check if error is being raised during parse analysis phase +GO + +create table error_mapping.temp1 (a int) +GO + +GO + + +create procedure error_mapping.ErrorHandling1 as +begin +insert into error_mapping.temp1 values(1) +SELECT CONVERT(DATE, '10-10-10', 140) +end +GO + +GO + + +create table error_mapping.temp2 (a int) +GO + +GO + + +insert into error_mapping.temp2 values(1) +SELECT CONVERT(DATE, '10-10-10', 140) +GO +~~ROW COUNT: 1~~ + +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 140 is not supported for conversions from varchar to date.)~~ + + +GO + + +-- Here we are assuming that error_mapping.ErrorHandling1 is created with no error +GO + +create table error_mapping.temp3 (a int) +GO + +GO + +insert into error_mapping.temp3 values(1) +exec error_mapping.ErrorHandling1; +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 140 is not supported for conversions from varchar to date.)~~ + + +GO + + +if ((select count(*) from error_mapping.temp1) = 0 and (select count(*) from error_mapping.temp2) = 0 and (select count(*) from error_mapping.temp3) > 0) select cast('parse analysis phase error' as text) +GO + +drop procedure error_mapping.ErrorHandling1; +GO +drop table error_mapping.temp1; +drop table error_mapping.temp2; +drop table error_mapping.temp3; +GO + +-- Parse analysis phase end +GO + + +-- compile time error portion +-- Executing test error_mapping.ErrorHandling1 +GO + + + + +create procedure error_mapping.ErrorHandling1 as +begin +SELECT CONVERT(DATE, '10-10-10', 140) +if @@error > 0 select cast('STATEMENT TERMINATING ERROR' as text); +select @@trancount; +end +GO + +if @@error > 0 select cast('Compile time error' as text); +if @@trancount > 0 rollback transaction; +drop procedure error_mapping.ErrorHandling1; +set xact_abort OFF; +set implicit_transactions OFF; +GO +GO + + + +GO + +begin transaction +GO + + +-- Executing test error_mapping.ErrorHandling1 +create procedure error_mapping.ErrorHandling1 as +begin +SELECT CONVERT(DATE, '10-10-10', 140) +if @@error > 0 select cast('STATEMENT TERMINATING ERROR' as text); +end +GO + +declare @err int = @@error; if (@err > 0 and @@trancount > 0) select cast('BATCH ONLY TERMINATING' as text) else if @err > 0 select cast('BATCH TERMINATING\ txn rolledback' as text); +if @@trancount > 0 rollback transaction; +drop procedure error_mapping.ErrorHandling1; +set xact_abort OFF; +set implicit_transactions OFF; +GO +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: could not find a procedure named "master_error_mapping.errorhandling1")~~ + + +GO +GO + + + +-- Checking xact_abort_flag for compile time error -- +set xact_abort ON; +GO +GO + +begin transaction +GO + + +-- Executing test error_mapping.ErrorHandling1 +create procedure error_mapping.ErrorHandling1 as +begin +SELECT CONVERT(DATE, '10-10-10', 140) +if @@error > 0 select cast('STATEMENT TERMINATING ERROR' as text); +end +GO + +declare @err int = @@error; if (@err > 0 and @@trancount > 0) select cast('BATCH ONLY TERMINATING' as text) else if @err > 0 select cast('BATCH TERMINATING\ txn rolledback' as text); +if @@trancount > 0 rollback transaction; +drop procedure error_mapping.ErrorHandling1; +set xact_abort OFF; +set implicit_transactions OFF; +GO +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: could not find a procedure named "master_error_mapping.errorhandling1")~~ + + +GO +GO + +set xact_abort OFF; +GO + + +-- comiple time error portion end -- +-- Next portion is for runtime error -- +-- Executing test error_mapping.ErrorHandling10000000 +GO + + + + +create procedure error_mapping.ErrorHandling1 as +begin +SELECT CONVERT(DATE, '10-10-10', 140) +if @@error > 0 select cast('STATEMENT TERMINATING ERROR' as text); +select @@trancount; +end +GO + +if @@error > 0 select cast('CURRENT BATCH TERMINATING ERROR' as text); +GO + +create procedure error_mapping.ErrorHandling2 as +begin +exec error_mapping.ErrorHandling1; +if @@error > 0 select cast('CURRENT BATCH TERMINATING ERROR' as text); +end +GO + +begin transaction; +GO +exec error_mapping.ErrorHandling2; +GO +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 140 is not supported for conversions from varchar to date.)~~ + +~~START~~ +text +STATEMENT TERMINATING ERROR +~~END~~ + +~~START~~ +int +1 +~~END~~ + +declare @err int = @@error; if (@err > 0 and @@trancount > 0) select cast('BATCH ONLY TERMINATING' as text) else if @err > 0 select cast('BATCH TERMINATING\ txn rolledback' as text); +if @@trancount > 0 rollback transaction; +drop procedure error_mapping.ErrorHandling1; +drop procedure error_mapping.ErrorHandling2; +set xact_abort OFF; +set implicit_transactions OFF; +GO +GO + + + +set xact_abort ON; +GO +-- Executing test error_mapping.ErrorHandling10000000 +GO + + + + +create procedure error_mapping.ErrorHandling1 as +begin +SELECT CONVERT(DATE, '10-10-10', 140) +if @@error > 0 select cast('STATEMENT TERMINATING ERROR' as text); +select @@trancount; +end +GO + +if @@error > 0 select cast('CURRENT BATCH TERMINATING ERROR' as text); +GO + +create procedure error_mapping.ErrorHandling2 as +begin +exec error_mapping.ErrorHandling1; +if @@error > 0 select cast('CURRENT BATCH TERMINATING ERROR' as text); +end +GO + +begin transaction; +GO +exec error_mapping.ErrorHandling2; +GO +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 140 is not supported for conversions from varchar to date.)~~ + +declare @err int = @@error; if (@err > 0 and @@trancount > 0) select cast('BATCH ONLY TERMINATING' as text) else if @err > 0 select cast('BATCH TERMINATING\ txn rolledback' as text); +if @@trancount > 0 rollback transaction; +drop procedure error_mapping.ErrorHandling1; +drop procedure error_mapping.ErrorHandling2; +set xact_abort OFF; +set implicit_transactions OFF; +GO +~~START~~ +text +BATCH TERMINATING\ txn rolledback +~~END~~ + +GO + + + + +set xact_abort OFF; +GO + + +-- Error classification is done -- +-- Executing test error_mapping.ErrorHandling10000000 +GO + + + + +begin try +select 1 +SELECT CONVERT(DATE, '10-10-10', 140) +end try +begin catch + select xact_state(); +end catch +if @@trancount > 0 rollback transaction; +drop procedure error_mapping.ErrorHandling1; +drop procedure error_mapping.ErrorHandling2; +set xact_abort OFF; +set implicit_transactions OFF; +GO +~~START~~ +int +1 +~~END~~ + +~~START~~ +smallint +0 +~~END~~ + +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: could not find a procedure named "master_error_mapping.errorhandling1")~~ + +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: could not find a procedure named "master_error_mapping.errorhandling2")~~ + +GO + + + + +GO +drop schema error_mapping; +GO diff --git a/test/JDBC/expected/ATTIMEZONE.out b/test/JDBC/expected/ATTIMEZONE.out index 9c18af2ca8..f032b4e8db 100644 --- a/test/JDBC/expected/ATTIMEZONE.out +++ b/test/JDBC/expected/ATTIMEZONE.out @@ -71,8 +71,6 @@ datetimeoffset Select '2022-10-29 20:01:00.000' AT TIME ZONE convert(datetime,'2022-10-29 20:01:00.000') Go -~~START~~ -datetimeoffset ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type varchar is invalid for argument 1 of AT TIME ZONE function.)~~ diff --git a/test/JDBC/expected/BABEL-3486-before-17_3-vu-prepare.out b/test/JDBC/expected/BABEL-3486-before-17_3-vu-prepare.out new file mode 100644 index 0000000000..eb5a55df08 --- /dev/null +++ b/test/JDBC/expected/BABEL-3486-before-17_3-vu-prepare.out @@ -0,0 +1,1230 @@ +-- Convert BIGINT valid operations +CREATE VIEW BABEL_3486_vu_prepare_v13 as (SELECT TRY_CONVERT(bigint, 5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p13 as (SELECT TRY_CONVERT(bigint, 5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f13() +RETURNS BIGINT AS +BEGIN +RETURN (SELECT TRY_CONVERT(bigint, 5)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v14 as (SELECT TRY_CONVERT(bigint, -5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p14 as (SELECT TRY_CONVERT(bigint, -5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f14() +RETURNS BIGINT AS +BEGIN +RETURN (SELECT TRY_CONVERT(bigint, -5)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v15 as (SELECT TRY_CONVERT(bigint, 9223372036854775808)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p15 as (SELECT TRY_CONVERT(bigint, 9223372036854775808)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f15() +RETURNS BIGINT AS +BEGIN +RETURN (SELECT TRY_CONVERT(bigint, 9223372036854775808)); +END +GO + +-- Convert int valid operations +CREATE VIEW BABEL_3486_vu_prepare_v16 as (SELECT TRY_CONVERT(int, 5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p16 as (SELECT TRY_CONVERT(int, 5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f16() +RETURNS INT AS +BEGIN +RETURN (SELECT TRY_CONVERT(int, 5)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v17 as (SELECT TRY_CONVERT(int, -5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p17 as (SELECT TRY_CONVERT(int, -5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f17() +RETURNS int AS +BEGIN +RETURN (SELECT TRY_CONVERT(int, -5)); +END +GO + +-- Convert int invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v18 as (SELECT TRY_CONVERT(int, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p18 as (SELECT TRY_CONVERT(int, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f18() +RETURNS int AS +BEGIN +RETURN (SELECT TRY_CONVERT(int, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v19 as (SELECT TRY_CONVERT(int, 2147483648)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p19 as (SELECT TRY_CONVERT(int, 2147483648)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f19() +RETURNS int AS +BEGIN +RETURN (SELECT TRY_CONVERT(int, 2147483648)); +END +GO + +-- Convert smallint valid operations +CREATE VIEW BABEL_3486_vu_prepare_v20 as (SELECT TRY_CONVERT(smallint, 5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p20 as (SELECT TRY_CONVERT(smallint, 5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f20() +RETURNS smallint AS +BEGIN +RETURN (SELECT TRY_CONVERT(smallint, 5)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v21 as (SELECT TRY_CONVERT(smallint, -5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p21 as (SELECT TRY_CONVERT(smallint, -5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f21() +RETURNS smallint AS +BEGIN +RETURN (SELECT TRY_CONVERT(smallint, -5)); +END +GO + +-- Convert smallint invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v22 as (SELECT TRY_CONVERT(smallint, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p22 as (SELECT TRY_CONVERT(smallint, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f22() +RETURNS smallint AS +BEGIN +RETURN (SELECT TRY_CONVERT(smallint, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v23 as (SELECT TRY_CONVERT(smallint, 32768)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p23 as (SELECT TRY_CONVERT(smallint, 32768)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f23() +RETURNS smallint AS +BEGIN +RETURN (SELECT TRY_CONVERT(smallint, 32768)); +END +GO + +-- Convert bit valid operations +CREATE VIEW BABEL_3486_vu_prepare_v24 as (SELECT TRY_CONVERT(bit, 1)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p24 as (SELECT TRY_CONVERT(bit, 1)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f24() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, 1)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v25 as (SELECT TRY_CONVERT(bit, 0)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p25 as (SELECT TRY_CONVERT(bit, 0)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f25() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, 0)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v26 as (SELECT TRY_CONVERT(bit, 5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p26 as (SELECT TRY_CONVERT(bit, 5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f26() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, 5)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v27 as (SELECT TRY_CONVERT(bit, CAST(5.0 AS decimal))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p27 as (SELECT TRY_CONVERT(bit, CAST(5.0 AS decimal))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f27() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, CAST(5.0 AS decimal))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v28 as (SELECT TRY_CONVERT(bit, null)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p28 as (SELECT TRY_CONVERT(bit, null)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f28() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, null)); +END +GO + +-- Convert bit invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v29 as (SELECT TRY_CONVERT(bit, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p29 as (SELECT TRY_CONVERT(bit, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f29() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v29_2 as (SELECT TRY_CONVERT(bit, CAST('13:01:59' AS time))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p29_2 as (SELECT TRY_CONVERT(bit, CAST('13:01:59' AS time))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f29_2() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, CAST('13:01:59' AS time))); +END +GO + +-- Convert numeric valid +CREATE VIEW BABEL_3486_vu_prepare_v30 as (SELECT TRY_CONVERT(numeric(3,2), 5.33)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p30 as (SELECT TRY_CONVERT(numeric(3,2), 5.33)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f30() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(3,2), 5.33)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v31 as (SELECT TRY_CONVERT(numeric(2,1), -5.34)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p31 as (SELECT TRY_CONVERT(numeric(2,1), -5.34)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f31() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(2,1), -5.34)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v32 as (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p32 as (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f32() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v33 as (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal(2,1)))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p33 as (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal(2,1)))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f33() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal(2,1)))); +END +GO + +-- Convert numeric invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v34 as (SELECT TRY_CONVERT(numeric(2,1), 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p34 as (SELECT TRY_CONVERT(numeric(2,1), 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f34() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(2,1), 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v35 as (SELECT TRY_CONVERT(numeric(2,1), CAST('13:01:59' AS time))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p35 as (SELECT TRY_CONVERT(numeric(2,1), CAST('13:01:59' AS time))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f35() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(2,1), CAST('13:01:59' AS time))); +END +GO + + +CREATE PROCEDURE BABEL_3486_vu_prepare_p35_2 as (SELECT TRY_CONVERT(numeric(1,2), CAST(5.0 AS decimal))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f35_2() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(1,2), CAST(5.0 AS decimal))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v36 as (SELECT TRY_CONVERT(numeric(1,1), CAST(5.0 AS decimal))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p36 as (SELECT TRY_CONVERT(numeric(1,1), CAST(5.0 AS decimal))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f36() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(1,1), CAST(5.0 AS decimal))); +END +GO + +-- Convert decimal valid operations +CREATE VIEW BABEL_3486_vu_prepare_v37 as (SELECT TRY_CONVERT(decimal(3,2), 5.33)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p37 as (SELECT TRY_CONVERT(decimal(3,2), 5.33)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f37() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal(3,2), 5.33)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v38 as (SELECT TRY_CONVERT(decimal(1,0), -5.34)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p38 as (SELECT TRY_CONVERT(decimal(1,0), -5.34)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f38() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal(1,0), -5.34)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v39 as (SELECT TRY_CONVERT(decimal(1,0), CAST(5.0 AS numeric(2,1)))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p39 as (SELECT TRY_CONVERT(decimal(1,0), CAST(5.0 AS numeric(2,1)))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f39() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal(1,0), CAST(5.0 AS numeric(2,1)))); +END +GO + +-- Convert decimal invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v40 as (SELECT TRY_CONVERT(decimal, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p40 as (SELECT TRY_CONVERT(decimal, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f40() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v41 as (SELECT TRY_CONVERT(decimal(1,1), -5.34)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p41 as (SELECT TRY_CONVERT(decimal(1,1), -5.34)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f41() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal(1,1), -5.34)); +END +GO + + +CREATE PROCEDURE BABEL_3486_vu_prepare_p42 as (SELECT TRY_CONVERT(decimal(1,2), CAST(5.0 AS numeric(2,1)))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f42() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal(1,2), CAST(5.0 AS numeric(2,1)))); +END +GO + + +-- Convert money valid operations +CREATE VIEW BABEL_3486_vu_prepare_v43 as (SELECT TRY_CONVERT(MONEY, 5.33)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p43 as (SELECT TRY_CONVERT(MONEY, 5.33)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f43() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, 5.33)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v44 as (SELECT TRY_CONVERT(MONEY, 5.335432)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p44 as (SELECT TRY_CONVERT(MONEY, 5.335432)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f44() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, 5.335432)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v45 as (SELECT TRY_CONVERT(MONEY, -5.33)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p45 as (SELECT TRY_CONVERT(MONEY, -5.33)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f45() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, -5.33)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v46 as (SELECT TRY_CONVERT(MONEY, '-5.33')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p46 as (SELECT TRY_CONVERT(MONEY, '-5.33')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f46() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, '-5.33')); +END +GO + +-- Convert money invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v47 as (SELECT TRY_CONVERT(MONEY, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p47 as (SELECT TRY_CONVERT(MONEY, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f47() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v47_2 as (SELECT TRY_CONVERT(MONEY, CAST('2017-08-25' AS date))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p47_2 as (SELECT TRY_CONVERT(MONEY, CAST('2017-08-25' AS date))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f47_2() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, CAST('2017-08-25' AS date))); +END +GO + +-- Convert float valid operations +CREATE VIEW BABEL_3486_vu_prepare_v48 as (SELECT TRY_CONVERT(float, 5.33)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p48 as (SELECT TRY_CONVERT(float, 5.33)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f48() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, 5.33)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v49 as (SELECT TRY_CONVERT(float, -5.335432)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p49 as (SELECT TRY_CONVERT(float, -5.335432)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f49() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, -5.335432)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v50 as (SELECT TRY_CONVERT(float, CAST(5.0 AS numeric(2,0)))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p50 as (SELECT TRY_CONVERT(float, CAST(5.0 AS numeric(2,0)))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f50() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, CAST(5.0 AS numeric(2,0)))); +END +GO + +-- Convert float invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v51 as (SELECT TRY_CONVERT(float, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p51 as (SELECT TRY_CONVERT(float, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f51() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v52 as (SELECT TRY_CONVERT(float, CAST('2017-08-25' AS date))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p52 as (SELECT TRY_CONVERT(float, CAST('2017-08-25' AS date))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f52() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, CAST('2017-08-25' AS date))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v53 as (SELECT TRY_CONVERT(float, CAST('13:01:59' AS time))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p53 as (SELECT TRY_CONVERT(float, CAST('13:01:59' AS time))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f53() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, CAST('13:01:59' AS time))); +END +GO + +-- Convert varchar valid operations +CREATE VIEW BABEL_3486_vu_prepare_v54 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS MONEY))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p54 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS MONEY))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f54() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5 AS MONEY), 1)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v55 as (SELECT TRY_CONVERT(varchar(30), CAST('13:01:59' AS time), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p55 as (SELECT TRY_CONVERT(varchar(30), CAST('13:01:59' AS time), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f55() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST('13:01:59' AS time), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v56 as (SELECT TRY_CONVERT(varchar(2), CAST('13:01:59' AS time), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p56 as (SELECT TRY_CONVERT(varchar(2), CAST('13:01:59' AS time), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f56() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(2), CAST('13:01:59' AS time), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v57 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS bigint), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p57 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS bigint), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f57() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5 AS bigint), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v58 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS smallint), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p58 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS smallint), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f58() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5 AS smallint), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v59 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS int), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p59 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS int), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f59() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5 AS int), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v60 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS numeric), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p60 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS numeric), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f60() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5 AS numeric), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v61 as (SELECT TRY_CONVERT(varchar(30), CAST(5.0 AS decimal), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p61 as (SELECT TRY_CONVERT(varchar(30), CAST(5.0 AS decimal), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f61() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5.0 AS decimal), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v62 as (SELECT TRY_CONVERT(varchar(30), CAST(1 AS bit), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p62 as (SELECT TRY_CONVERT(varchar(30), CAST(1 AS bit), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f62() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(1 AS bit), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v63 as (SELECT TRY_CONVERT(varchar(30), CAST(1 AS smallmoney), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p63 as ((SELECT TRY_CONVERT(varchar(30), CAST(1 AS smallmoney), 8))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f63() +RETURNS varchar AS +BEGIN +RETURN ((SELECT TRY_CONVERT(varchar(30), CAST(1 AS smallmoney), 8))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v64 as (SELECT TRY_CONVERT(varchar(30), 'test', 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p64 as (SELECT TRY_CONVERT(varchar(30), 'test', 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f64() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), 'test', 8)); +END +GO + +-- Convert Varchar invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v65 as (SELECT TRY_CONVERT(varchar(30), CAST('2017-08-25' AS date), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p65 as (SELECT TRY_CONVERT(varchar(30), CAST('2017-08-25' AS date), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f65() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST('2017-08-25' AS date), 8)); +END +GO + +-- Convert text valid operations +CREATE VIEW BABEL_3486_vu_prepare_v66 as (SELECT TRY_CONVERT(text, CAST(5 AS MONEY), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p66 as (SELECT TRY_CONVERT(text, CAST(5 AS MONEY), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f66() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5 AS MONEY), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v67 as (SELECT TRY_CONVERT(text, CAST('2017-08-25' AS date), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p67 as (SELECT TRY_CONVERT(text, CAST('2017-08-25' AS date), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f67() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST('2017-08-25' AS date), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v68 as (SELECT TRY_CONVERT(text, CAST(5 AS bigint), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p68 as (SELECT TRY_CONVERT(text, CAST(5 AS bigint), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f68() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5 AS bigint), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v69 as (SELECT TRY_CONVERT(text, CAST(5 AS smallint), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p69 as (SELECT TRY_CONVERT(text, CAST(5 AS smallint), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f69() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5 AS smallint), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v70 as (SELECT TRY_CONVERT(text, CAST(5 AS int), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p70 as (SELECT TRY_CONVERT(text, CAST(5 AS int), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f70() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5 AS int), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v71 as (SELECT TRY_CONVERT(text, CAST(5 AS numeric), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p71 as (SELECT TRY_CONVERT(text, CAST(5 AS numeric), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f71() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5 AS numeric), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v72 as (SELECT TRY_CONVERT(text, CAST(5.0 AS decimal), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p72 as (SELECT TRY_CONVERT(text, CAST(5.0 AS decimal), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f72() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5.0 AS decimal), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v73 as (SELECT TRY_CONVERT(text, CAST(1 AS bit), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p73 as (SELECT TRY_CONVERT(text, CAST(1 AS bit), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f73() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(1 AS bit), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v74 as (SELECT TRY_CONVERT(text, CAST(1 AS smallmoney), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p74 as (SELECT TRY_CONVERT(text, CAST(1 AS smallmoney), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f74() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(1 AS smallmoney), 8)); +END +GO + +create table test(col varchar(10)) +GO +insert into test values ('1'),('2'),('3'),('4') +GO +~~ROW COUNT: 4~~ + + +-- Convert text invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v75 as (SELECT TRY_CONVERT(text, (select * from test), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p75 as (SELECT TRY_CONVERT(text, (select * from test), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f75() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, (select * from test), 8)); +END +GO + +-- Convert date valid +CREATE VIEW BABEL_3486_vu_prepare_v76 as (SELECT TRY_CONVERT(date, '2017-08-25')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p76 as (SELECT TRY_CONVERT(date, '2017-08-25')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f76() +RETURNS date AS +BEGIN +RETURN (SELECT TRY_CONVERT(date, '2017-08-25')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v77 as (SELECT TRY_CONVERT(date, '9999-08-25')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p77 as (SELECT TRY_CONVERT(date, '9999-08-25')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f77() +RETURNS date AS +BEGIN +RETURN (SELECT TRY_CONVERT(date, '9999-08-25')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v78 as (SELECT TRY_CONVERT(date, '13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p78 as (SELECT TRY_CONVERT(date, '13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f78() +RETURNS date AS +BEGIN +RETURN (SELECT TRY_CONVERT(date, '13:01:59')); +END +GO + +-- Convert date invalid +CREATE VIEW BABEL_3486_vu_prepare_v79 as (SELECT TRY_CONVERT(date, '10000-08-25')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p79 as (SELECT TRY_CONVERT(date, '10000-08-25')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f79() +RETURNS date AS +BEGIN +RETURN (SELECT TRY_CONVERT(date, '10000-08-25')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v80 as (SELECT TRY_CONVERT(date, '5000-082-253')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p80 as (SELECT TRY_CONVERT(date, '5000-082-253')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f80() +RETURNS date AS +BEGIN +RETURN (SELECT TRY_CONVERT(date, '5000-082-253')); +END +GO + +-- Convert time valid +CREATE VIEW BABEL_3486_vu_prepare_v81 as (SELECT TRY_CONVERT(time, '13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p81 as (SELECT TRY_CONVERT(time, '13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f81() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '13:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v82 as (SELECT TRY_CONVERT(time, '00:00:00')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p82 as (SELECT TRY_CONVERT(time, '00:00:00')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f82() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '00:00:00')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v83 as (SELECT TRY_CONVERT(time, '1:1:1')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p83 as (SELECT TRY_CONVERT(time, '1:1:1')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f83() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '1:1:1')); +END +GO + +-- Convert time invalid +CREATE VIEW BABEL_3486_vu_prepare_v84 as (SELECT TRY_CONVERT(time, '9999-08-25')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p84 as (SELECT TRY_CONVERT(time, '9999-08-25')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f84() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '9999-08-25')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v85 as (SELECT TRY_CONVERT(time, '28:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p85 as (SELECT TRY_CONVERT(time, '28:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f85() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '28:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v86 as (SELECT TRY_CONVERT(time, '::59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p86 as (SELECT TRY_CONVERT(time, '::59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f86() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '::59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v87 as (SELECT TRY_CONVERT(time, '20:013:593')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p87 as (SELECT TRY_CONVERT(time, '20:013:593')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f87() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '20:013:593')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v88 as (SELECT TRY_CONVERT(time, 'abc')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p88 as (SELECT TRY_CONVERT(time, 'abc')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f88() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, 'abc')); +END +GO + +-- Convert smalldatetime valid +CREATE VIEW BABEL_3486_vu_prepare_v89 as (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p89 as (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f89() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v90 as (SELECT TRY_CONVERT(smalldatetime, '13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p90 as (SELECT TRY_CONVERT(smalldatetime, '13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f90() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(smalldatetime, '13:01:59')); +END +GO + +-- Convert smalldatetime invalid +CREATE VIEW BABEL_3486_vu_prepare_v91 as (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 26:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p91 as (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 26:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f91() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 26:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v92 as (SELECT TRY_CONVERT(smalldatetime, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p92 as (SELECT TRY_CONVERT(smalldatetime, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f92() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(smalldatetime, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v93 as (SELECT TRY_CONVERT(smalldatetime, '1')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p93 as (SELECT TRY_CONVERT(smalldatetime, '1')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f93() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(smalldatetime, '1')); +END +GO + +-- Convert datetime valid +CREATE VIEW BABEL_3486_vu_prepare_v94 as (SELECT TRY_CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p94 as (SELECT TRY_CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f94() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v95 as (SELECT TRY_CONVERT(datetime, '13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p95 as (SELECT TRY_CONVERT(datetime, '13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f95() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, '13:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v96 as (SELECT TRY_CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p96 as (SELECT TRY_CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f96() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, '1753-01-01 0:01:59')); +END +GO + +-- Convert datetime invalid +CREATE VIEW BABEL_3486_vu_prepare_v97 as (SELECT TRY_CONVERT(datetime, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p97 as (SELECT TRY_CONVERT(datetime, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f97() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v98 as (SELECT TRY_CONVERT(datetime, '1752-01-01 0:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p98 as (SELECT TRY_CONVERT(datetime, '1752-01-01 0:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f98() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, '1752-01-01 0:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v99 as (SELECT TRY_CONVERT(datetime, '0001-01-01 0:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p99 as (SELECT TRY_CONVERT(datetime, '0001-01-01 0:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f99() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, '0001-01-01 0:01:59')); +END +GO + +-- Convert datetime2 valid +CREATE VIEW BABEL_3486_vu_prepare_v100 as (SELECT TRY_CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p100 as (SELECT TRY_CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f100() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v101 as (SELECT TRY_CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p101 as (SELECT TRY_CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f101() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v102 as (SELECT TRY_CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p102 as (SELECT TRY_CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f102() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime2, '13:01:59')); +END +GO + +CREATE PROCEDURE BABEL_3486_vu_prepare_p102_2 as (SELECT TRY_CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f102_2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +END +GO + +-- Convert datetime2 invalid +CREATE VIEW BABEL_3486_vu_prepare_v103 as (SELECT TRY_CONVERT(datetime2, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p103 as (SELECT TRY_CONVERT(datetime2, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f103() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime2, 'a')); +END +GO + +-- Convert datetimeoffset valid +CREATE VIEW BABEL_3486_vu_prepare_v104 as (SELECT TRY_CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p104 as (SELECT TRY_CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f104() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v105 as (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p105 as (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f105() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +12:15')); +END +GO + +-- Convert datetimeoffset invalid +CREATE VIEW BABEL_3486_vu_prepare_v106 as (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +25')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p106 as (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +25')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f106() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +25')); +END +GO + +-- Convert sql_variant valid +CREATE VIEW BABEL_3486_vu_prepare_v107 as (SELECT TRY_CONVERT(sql_variant, 1)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p107 as (SELECT TRY_CONVERT(sql_variant, 1)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f107() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, 1)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v108 as (SELECT TRY_CONVERT(sql_variant, 'test')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p108 as (SELECT TRY_CONVERT(sql_variant, 'test')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f108() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, 'test')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v109 as (SELECT TRY_CONVERT(sql_variant, CAST(1 as MONEY))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p109 as (SELECT TRY_CONVERT(sql_variant, CAST(1 as MONEY))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f109() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, CAST(1 as MONEY))); +END +GO + +-- This test case returns 2017-08-25 13:01:59.0 where SQL Server JDBC returns 2017-08-25 13:01:59 +CREATE VIEW BABEL_3486_vu_prepare_v110 as (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p110 as (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f110() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59' AS datetime))); +END +GO + +-- Results in error due to outdated JDBC version +-- Change when BABEL-2871 is resolved +CREATE VIEW BABEL_3486_vu_prepare_v111 as (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59 +12:15' AS datetimeoffset))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p111 as (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59 +12:15' AS datetimeoffset))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f111() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59 +12:15' AS datetimeoffset))); +END +GO + + +-- Convert sql_variant invalid +CREATE VIEW BABEL_3486_vu_prepare_v113 as (SELECT TRY_CONVERT(sql_variant, CAST('test' AS text))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p113 as (SELECT TRY_CONVERT(sql_variant, CAST('test' AS text))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f113() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, CAST('test' AS text))); +END +GO + +-- Valid uniqueidentifier +CREATE VIEW BABEL_3486_vu_prepare_v114 as (SELECT TRY_CONVERT(uniqueidentifier, '6F9619FF-8B86-D011-B42D-00C04FC964FF')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p114 as (SELECT TRY_CONVERT(uniqueidentifier, '6F9619FF-8B86-D011-B42D-00C04FC964FF')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f114() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(uniqueidentifier, '6F9619FF-8B86-D011-B42D-00C04FC964FF')); +END +GO + +-- Invalid uniqueidentifier +CREATE VIEW BABEL_3486_vu_prepare_v116 as (SELECT TRY_CONVERT(uniqueidentifier, 'unique')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p116 as (SELECT TRY_CONVERT(uniqueidentifier, 'unique')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f116() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(uniqueidentifier, 'unique')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v117 as (SELECT TRY_CAST(TRY_CAST (TRY_CONVERT(XML, '1990-01-01') as text) as date)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p117 as (SELECT TRY_CAST(TRY_CAST (TRY_CONVERT(XML, '1990-01-01') as text) as date)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f117() +RETURNS DATE AS +BEGIN +RETURN (SELECT TRY_CAST(TRY_CAST (TRY_CONVERT(XML, '1990-01-01') as text) as date)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v118 as (SELECT TRY_CAST(TRY_CONVERT(DATETIME, CAST('1990-01-01' AS DATE)) AS TIME)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p118 as (SELECT TRY_CAST(TRY_CONVERT(DATETIME, CAST('1990-01-01' AS DATE)) AS TIME)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f118() +RETURNS TIME AS +BEGIN +RETURN (SELECT TRY_CAST(TRY_CONVERT(DATETIME, CAST('1990-01-01' AS DATE)) AS TIME)); +END +GO diff --git a/test/JDBC/expected/BABEL-3486-before-17_3-vu-verify.out b/test/JDBC/expected/BABEL-3486-before-17_3-vu-verify.out new file mode 100644 index 0000000000..d2de0277ef --- /dev/null +++ b/test/JDBC/expected/BABEL-3486-before-17_3-vu-verify.out @@ -0,0 +1,3232 @@ +SELECT * FROM BABEL_3486_vu_prepare_v13 +GO +~~START~~ +bigint +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v13 +GO + +EXEC BABEL_3486_vu_prepare_p13 +GO +~~START~~ +bigint +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p13 +GO + +SELECT BABEL_3486_vu_prepare_f13() +GO +~~START~~ +bigint +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f13() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v14 +GO +~~START~~ +bigint +-5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v14 +GO + +EXEC BABEL_3486_vu_prepare_p14 +GO +~~START~~ +bigint +-5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p14 +GO + +SELECT BABEL_3486_vu_prepare_f14() +GO +~~START~~ +bigint +-5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f14() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v15 +GO +~~START~~ +bigint + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v15 +GO + +EXEC BABEL_3486_vu_prepare_p15 +GO +~~START~~ +bigint + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p15 +GO + +SELECT BABEL_3486_vu_prepare_f15() +GO +~~START~~ +bigint + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f15() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v16 +GO +~~START~~ +int +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v16 +GO + +EXEC BABEL_3486_vu_prepare_p16 +GO +~~START~~ +int +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p16 +GO + +SELECT BABEL_3486_vu_prepare_f16() +GO +~~START~~ +int +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f16() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v17 +GO +~~START~~ +int +-5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v17 +GO + +EXEC BABEL_3486_vu_prepare_p17 +GO +~~START~~ +int +-5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p17 +GO + +SELECT BABEL_3486_vu_prepare_f17() +GO +~~START~~ +int +-5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f17() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v18 +GO +~~START~~ +int + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v18 +GO + +EXEC BABEL_3486_vu_prepare_p18 +GO +~~START~~ +int + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p18 +GO + +SELECT BABEL_3486_vu_prepare_f18() +GO +~~START~~ +int + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f18() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v19 +GO +~~START~~ +int + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v19 +GO + +EXEC BABEL_3486_vu_prepare_p19 +GO +~~START~~ +int + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p19 +GO + +SELECT BABEL_3486_vu_prepare_f19() +GO +~~START~~ +int + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f19() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v20 +GO +~~START~~ +smallint +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v20 +GO + +EXEC BABEL_3486_vu_prepare_p20 +GO +~~START~~ +smallint +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p20 +GO + +SELECT BABEL_3486_vu_prepare_f20() +GO +~~START~~ +smallint +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f20() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v21 +GO +~~START~~ +smallint +-5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v21 +GO + +EXEC BABEL_3486_vu_prepare_p21 +GO +~~START~~ +smallint +-5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p21 +GO + +SELECT BABEL_3486_vu_prepare_f21() +GO +~~START~~ +smallint +-5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f21() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v22 +GO +~~START~~ +smallint + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v22 +GO + +EXEC BABEL_3486_vu_prepare_p22 +GO +~~START~~ +smallint + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p22 +GO + +SELECT BABEL_3486_vu_prepare_f22() +GO +~~START~~ +smallint + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f22() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v23 +GO +~~START~~ +smallint + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v23 +GO + +EXEC BABEL_3486_vu_prepare_p23 +GO +~~START~~ +smallint + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p23 +GO + +SELECT BABEL_3486_vu_prepare_f23() +GO +~~START~~ +smallint + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f23() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v24 +GO +~~START~~ +bit +1 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v24 +GO + +EXEC BABEL_3486_vu_prepare_p24 +GO +~~START~~ +bit +1 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p24 +GO + +SELECT BABEL_3486_vu_prepare_f24() +GO +~~START~~ +bit +1 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f24() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v25 +GO +~~START~~ +bit +0 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v25 +GO + +EXEC BABEL_3486_vu_prepare_p25 +GO +~~START~~ +bit +0 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p25 +GO + +SELECT BABEL_3486_vu_prepare_f25() +GO +~~START~~ +bit +0 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f25() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v26 +GO +~~START~~ +bit +1 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v26 +GO + +EXEC BABEL_3486_vu_prepare_p26 +GO +~~START~~ +bit +1 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p26 +GO + +SELECT BABEL_3486_vu_prepare_f26() +GO +~~START~~ +bit +1 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f26() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v27 +GO +~~START~~ +bit +1 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v27 +GO + +EXEC BABEL_3486_vu_prepare_p27 +GO +~~START~~ +bit +1 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p27 +GO + +SELECT BABEL_3486_vu_prepare_f27() +GO +~~START~~ +bit +1 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f27() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v28 +GO +~~START~~ +bit + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v28 +GO + +EXEC BABEL_3486_vu_prepare_p28 +GO +~~START~~ +bit + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p28 +GO + +SELECT BABEL_3486_vu_prepare_f28() +GO +~~START~~ +bit + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f28() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v29 +GO +~~START~~ +bit + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v29 +GO + +EXEC BABEL_3486_vu_prepare_p29 +GO +~~START~~ +bit + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p29 +GO + +SELECT BABEL_3486_vu_prepare_f29() +GO +~~START~~ +bit + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f29() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v29_2 +GO +~~START~~ +bit +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type time without time zone to "bit".)~~ + +DROP VIEW BABEL_3486_vu_prepare_v29_2 +GO + +EXEC BABEL_3486_vu_prepare_p29_2 +GO +~~START~~ +bit +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type time without time zone to "bit".)~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p29_2 +GO + +SELECT BABEL_3486_vu_prepare_f29_2() +GO +~~START~~ +bit +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type time without time zone to "bit".)~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f29_2() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v30 +GO +~~START~~ +numeric +5.33000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v30 +GO + +EXEC BABEL_3486_vu_prepare_p30 +GO +~~START~~ +numeric +5.33000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p30 +GO + +SELECT BABEL_3486_vu_prepare_f30() +GO +~~START~~ +numeric +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f30() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v31 +GO +~~START~~ +numeric +-5.30000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v31 +GO + +EXEC BABEL_3486_vu_prepare_p31 +GO +~~START~~ +numeric +-5.30000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p31 +GO + +SELECT BABEL_3486_vu_prepare_f31() +GO +~~START~~ +numeric +-5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f31() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v32 +GO +~~START~~ +numeric +5.00000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v32 +GO + +EXEC BABEL_3486_vu_prepare_p32 +GO +~~START~~ +numeric +5.00000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p32 +GO + +SELECT BABEL_3486_vu_prepare_f32() +GO +~~START~~ +numeric +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f32() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v33 +GO +~~START~~ +numeric +5.00000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v33 +GO + +EXEC BABEL_3486_vu_prepare_p33 +GO +~~START~~ +numeric +5.00000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p33 +GO + +SELECT BABEL_3486_vu_prepare_f33() +GO +~~START~~ +numeric +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f33() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v34 +GO +~~START~~ +numeric + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v34 +GO + +EXEC BABEL_3486_vu_prepare_p34 +GO +~~START~~ +numeric + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p34 +GO + +SELECT BABEL_3486_vu_prepare_f34() +GO +~~START~~ +numeric + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f34() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v35 +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type time without time zone to numeric.)~~ + +DROP VIEW BABEL_3486_vu_prepare_v35 +GO + +EXEC BABEL_3486_vu_prepare_p35 +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type time without time zone to numeric.)~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p35 +GO + +SELECT BABEL_3486_vu_prepare_f35() +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type time without time zone to numeric.)~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f35() +GO + +EXEC BABEL_3486_vu_prepare_p35_2 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The scale 2 for 'numeric' datatype must be within the range 0 to precision 1)~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p35_2 +GO + +SELECT BABEL_3486_vu_prepare_f35_2() +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The scale 2 for 'numeric' datatype must be within the range 0 to precision 1)~~ + + +DROP FUNCTION BABEL_3486_vu_prepare_f35_2() +SELECT * FROM BABEL_3486_vu_prepare_v36 +GO +~~START~~ +numeric + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v36 +GO + +EXEC BABEL_3486_vu_prepare_p36 +GO +~~START~~ +numeric + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p36 +GO + +SELECT BABEL_3486_vu_prepare_f36() +GO +~~START~~ +numeric + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f36() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v37 +GO +~~START~~ +numeric +5.33000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v37 +GO + +EXEC BABEL_3486_vu_prepare_p37 +GO +~~START~~ +numeric +5.33000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p37 +GO + +SELECT BABEL_3486_vu_prepare_f37() +GO +~~START~~ +numeric +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f37() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v38 +GO +~~START~~ +numeric +-5.00000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v38 +GO + +EXEC BABEL_3486_vu_prepare_p38 +GO +~~START~~ +numeric +-5.00000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p38 +GO + +SELECT BABEL_3486_vu_prepare_f38() +GO +~~START~~ +numeric +-5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f38() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v39 +GO +~~START~~ +numeric +5.00000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v39 +GO + +EXEC BABEL_3486_vu_prepare_p39 +GO +~~START~~ +numeric +5.00000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p39 +GO + +SELECT BABEL_3486_vu_prepare_f39() +GO +~~START~~ +numeric +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f39() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v40 +GO +~~START~~ +numeric + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v40 +GO + +EXEC BABEL_3486_vu_prepare_p40 +GO +~~START~~ +numeric + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p40 +GO + +SELECT BABEL_3486_vu_prepare_f40() +GO +~~START~~ +numeric + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f40() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v41 +GO +~~START~~ +numeric + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v41 +GO + +EXEC BABEL_3486_vu_prepare_p41 +GO +~~START~~ +numeric + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p41 +GO + +SELECT BABEL_3486_vu_prepare_f41() +GO +~~START~~ +numeric + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f41() +GO + +EXEC BABEL_3486_vu_prepare_p42 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The scale 2 for 'decimal' datatype must be within the range 0 to precision 1)~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p42 +GO + +SELECT BABEL_3486_vu_prepare_f42() +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The scale 2 for 'decimal' datatype must be within the range 0 to precision 1)~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f42() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v43 +GO +~~START~~ +money +5.3300 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v43 +GO + +EXEC BABEL_3486_vu_prepare_p43 +GO +~~START~~ +money +5.3300 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p43 +GO + +SELECT BABEL_3486_vu_prepare_f43() +GO +~~START~~ +money +5.3300 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f43() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v44 +GO +~~START~~ +money +5.3354 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v44 +GO + +EXEC BABEL_3486_vu_prepare_p44 +GO +~~START~~ +money +5.3354 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p44 +GO + +SELECT BABEL_3486_vu_prepare_f44() +GO +~~START~~ +money +5.3354 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f44() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v45 +GO +~~START~~ +money +-5.3300 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v45 +GO + +EXEC BABEL_3486_vu_prepare_p45 +GO +~~START~~ +money +-5.3300 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p45 +GO + +SELECT BABEL_3486_vu_prepare_f45() +GO +~~START~~ +money +-5.3300 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f45() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v46 +GO +~~START~~ +money +-5.3300 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v46 +GO + +EXEC BABEL_3486_vu_prepare_p46 +GO +~~START~~ +money +-5.3300 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p46 +GO + +SELECT BABEL_3486_vu_prepare_f46() +GO +~~START~~ +money +-5.3300 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f46() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v47 +GO +~~START~~ +money + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v47 +GO + +EXEC BABEL_3486_vu_prepare_p47 +GO +~~START~~ +money + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p47 +GO + +SELECT BABEL_3486_vu_prepare_f47() +GO +~~START~~ +money + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f47() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v47_2 +GO +~~START~~ +money +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type date to money.)~~ + +DROP VIEW BABEL_3486_vu_prepare_v47_2 +GO + +EXEC BABEL_3486_vu_prepare_p47_2 +GO +~~START~~ +money +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type date to money.)~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p47_2 +GO + +SELECT BABEL_3486_vu_prepare_f47_2() +GO +~~START~~ +money +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type date to money.)~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f47_2() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v48 +GO +~~START~~ +float +5.33 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v48 +GO + +EXEC BABEL_3486_vu_prepare_p48 +GO +~~START~~ +float +5.33 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p48 +GO + +SELECT BABEL_3486_vu_prepare_f48() +GO +~~START~~ +float +5.33 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f48() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v49 +GO +~~START~~ +float +-5.335432 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v49 +GO + +EXEC BABEL_3486_vu_prepare_p49 +GO +~~START~~ +float +-5.335432 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p49 +GO + +SELECT BABEL_3486_vu_prepare_f49() +GO +~~START~~ +float +-5.335432 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f49() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v50 +GO +~~START~~ +float +5.0 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v50 +GO + +EXEC BABEL_3486_vu_prepare_p50 +GO +~~START~~ +float +5.0 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p50 +GO + +SELECT BABEL_3486_vu_prepare_f50() +GO +~~START~~ +float +5.0 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f50() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v51 +GO +~~START~~ +float + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v51 +GO + +EXEC BABEL_3486_vu_prepare_p51 +GO +~~START~~ +float + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p51 +GO + +SELECT BABEL_3486_vu_prepare_f51() +GO +~~START~~ +float + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f51() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v52 +GO +~~START~~ +float +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type date to double precision.)~~ + +DROP VIEW BABEL_3486_vu_prepare_v52 +GO + +EXEC BABEL_3486_vu_prepare_p52 +GO +~~START~~ +float +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type date to double precision.)~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p52 +GO + +SELECT BABEL_3486_vu_prepare_f52() +GO +~~START~~ +float +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type date to double precision.)~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f52() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v53 +GO +~~START~~ +float +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type time without time zone to double precision.)~~ + +DROP VIEW BABEL_3486_vu_prepare_v53 +GO + +EXEC BABEL_3486_vu_prepare_p53 +GO +~~START~~ +float +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type time without time zone to double precision.)~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p53 +GO + +SELECT BABEL_3486_vu_prepare_f53() +GO +~~START~~ +float +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type time without time zone to double precision.)~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f53() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v54 +GO +~~START~~ +varchar + 5.00 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v54 +GO + +EXEC BABEL_3486_vu_prepare_p54 +GO +~~START~~ +varchar + 5.00 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p54 +GO + +SELECT BABEL_3486_vu_prepare_f54() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f54() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v55 +GO +~~START~~ +varchar +13:01:59 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v55 +GO + +EXEC BABEL_3486_vu_prepare_p55 +GO +~~START~~ +varchar +13:01:59 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p55 +GO + +SELECT BABEL_3486_vu_prepare_f55() +GO +~~START~~ +varchar +1 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f55() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v56 +GO +~~START~~ +varchar +13 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v56 +GO + +EXEC BABEL_3486_vu_prepare_p56 +GO +~~START~~ +varchar +13 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p56 +GO + +SELECT BABEL_3486_vu_prepare_f56() +GO +~~START~~ +varchar +1 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f56() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v57 +GO +~~START~~ +varchar +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v57 +GO + +EXEC BABEL_3486_vu_prepare_p57 +GO +~~START~~ +varchar +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p57 +GO + +SELECT BABEL_3486_vu_prepare_f57() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f57() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v58 +GO +~~START~~ +varchar +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v58 +GO + +EXEC BABEL_3486_vu_prepare_p58 +GO +~~START~~ +varchar +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p58 +GO + +SELECT BABEL_3486_vu_prepare_f58() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f58() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v59 +GO +~~START~~ +varchar +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v59 +GO + +EXEC BABEL_3486_vu_prepare_p59 +GO +~~START~~ +varchar +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p59 +GO + +SELECT BABEL_3486_vu_prepare_f59() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f59() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v60 +GO +~~START~~ +varchar +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v60 +GO + +EXEC BABEL_3486_vu_prepare_p60 +GO +~~START~~ +varchar +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p60 +GO + +SELECT BABEL_3486_vu_prepare_f60() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f60() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v61 +GO +~~START~~ +varchar +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v61 +GO + +EXEC BABEL_3486_vu_prepare_p61 +GO +~~START~~ +varchar +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p61 +GO + +SELECT BABEL_3486_vu_prepare_f61() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f61() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v62 +GO +~~START~~ +varchar +1 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v62 +GO + +EXEC BABEL_3486_vu_prepare_p62 +GO +~~START~~ +varchar +1 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p62 +GO + +SELECT BABEL_3486_vu_prepare_f62() +GO +~~START~~ +varchar +1 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f62() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v63 +GO +~~START~~ +varchar +1.0000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v63 +GO + +EXEC BABEL_3486_vu_prepare_p63 +GO +~~START~~ +varchar +1.0000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p63 +GO + +SELECT BABEL_3486_vu_prepare_f63() +GO +~~START~~ +varchar +1 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f63() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v64 +GO +~~START~~ +varchar +test +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v64 +GO + +EXEC BABEL_3486_vu_prepare_p64 +GO +~~START~~ +varchar +test +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p64 +GO + +SELECT BABEL_3486_vu_prepare_f64() +GO +~~START~~ +varchar +t +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f64() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v65 +GO +~~START~~ +varchar + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v65 +GO + +EXEC BABEL_3486_vu_prepare_p65 +GO +~~START~~ +varchar + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p65 +GO + +SELECT BABEL_3486_vu_prepare_f65() +GO +~~START~~ +varchar + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f65() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v66 +GO +~~START~~ +text +5.0000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v66 +GO + +EXEC BABEL_3486_vu_prepare_p66 +GO +~~START~~ +text +5.0000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p66 +GO + +SELECT BABEL_3486_vu_prepare_f66() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f66() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v67 +GO +~~START~~ +text +2017-08-25 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v67 +GO + +EXEC BABEL_3486_vu_prepare_p67 +GO +~~START~~ +text +2017-08-25 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p67 +GO + +SELECT BABEL_3486_vu_prepare_f67() +GO +~~START~~ +varchar +2 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f67() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v68 +GO +~~START~~ +text +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v68 +GO + +EXEC BABEL_3486_vu_prepare_p68 +GO +~~START~~ +text +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p68 +GO + +SELECT BABEL_3486_vu_prepare_f68() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f68() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v69 +GO +~~START~~ +text +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v69 +GO + +EXEC BABEL_3486_vu_prepare_p69 +GO +~~START~~ +text +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p69 +GO + +SELECT BABEL_3486_vu_prepare_f69() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f69() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v70 +GO +~~START~~ +text +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v70 +GO + +EXEC BABEL_3486_vu_prepare_p70 +GO +~~START~~ +text +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p70 +GO + +SELECT BABEL_3486_vu_prepare_f70() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f70() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v71 +GO +~~START~~ +text +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v71 +GO + +EXEC BABEL_3486_vu_prepare_p71 +GO +~~START~~ +text +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p71 +GO + +SELECT BABEL_3486_vu_prepare_f71() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f71() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v72 +GO +~~START~~ +text +5 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v72 +GO + +EXEC BABEL_3486_vu_prepare_p72 +GO +~~START~~ +text +5 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p72 +GO + +SELECT BABEL_3486_vu_prepare_f72() +GO +~~START~~ +varchar +5 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f72() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v73 +GO +~~START~~ +text +1 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v73 +GO + +EXEC BABEL_3486_vu_prepare_p73 +GO +~~START~~ +text +1 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p73 +GO + +SELECT BABEL_3486_vu_prepare_f73() +GO +~~START~~ +varchar +1 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f73() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v74 +GO +~~START~~ +text +1.0000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v74 +GO + +EXEC BABEL_3486_vu_prepare_p74 +GO +~~START~~ +text +1.0000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p74 +GO + +SELECT BABEL_3486_vu_prepare_f74() +GO +~~START~~ +varchar +1 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f74() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v75 +GO +~~START~~ +text +~~ERROR (Code: 512)~~ + +~~ERROR (Message: more than one row returned by a subquery used as an expression)~~ + +DROP VIEW BABEL_3486_vu_prepare_v75 +GO + +EXEC BABEL_3486_vu_prepare_p75 +GO +~~START~~ +text +~~ERROR (Code: 512)~~ + +~~ERROR (Message: more than one row returned by a subquery used as an expression)~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p75 +GO + +SELECT BABEL_3486_vu_prepare_f75() +GO +~~START~~ +varchar +~~ERROR (Code: 512)~~ + +~~ERROR (Message: more than one row returned by a subquery used as an expression)~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f75() +GO + +drop table test +GO + +SELECT * FROM BABEL_3486_vu_prepare_v76 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v76 +GO + +EXEC BABEL_3486_vu_prepare_p76 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p76 +GO + +SELECT BABEL_3486_vu_prepare_f76() +GO +~~START~~ +date +2017-08-25 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f76() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v77 +GO +~~START~~ +date +9999-08-25 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v77 +GO + +EXEC BABEL_3486_vu_prepare_p77 +GO +~~START~~ +date +9999-08-25 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p77 +GO + +SELECT BABEL_3486_vu_prepare_f77() +GO +~~START~~ +date +9999-08-25 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f77() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v78 +GO +~~START~~ +date +1900-01-01 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v78 +GO + +EXEC BABEL_3486_vu_prepare_p78 +GO +~~START~~ +date +1900-01-01 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p78 +GO + +SELECT BABEL_3486_vu_prepare_f78() +GO +~~START~~ +date +1900-01-01 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f78() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v79 +GO +~~START~~ +date + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v79 +GO + +EXEC BABEL_3486_vu_prepare_p79 +GO +~~START~~ +date + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p79 +GO + +SELECT BABEL_3486_vu_prepare_f79() +GO +~~START~~ +date + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f79() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v80 +GO +~~START~~ +date + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v80 +GO + +EXEC BABEL_3486_vu_prepare_p80 +GO +~~START~~ +date + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p80 +GO + +SELECT BABEL_3486_vu_prepare_f80() +GO +~~START~~ +date + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f80() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v81 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v81 +GO + +EXEC BABEL_3486_vu_prepare_p81 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p81 +GO + +SELECT BABEL_3486_vu_prepare_f81() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f81() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v82 +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v82 +GO + +EXEC BABEL_3486_vu_prepare_p82 +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p82 +GO + +SELECT BABEL_3486_vu_prepare_f82() +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f82() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v83 +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v83 +GO + +EXEC BABEL_3486_vu_prepare_p83 +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p83 +GO + +SELECT BABEL_3486_vu_prepare_f83() +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f83() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v84 +GO +~~START~~ +time + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v84 +GO + +EXEC BABEL_3486_vu_prepare_p84 +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p84 +GO + +SELECT BABEL_3486_vu_prepare_f84() +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f84() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v85 +GO +~~START~~ +time + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v85 +GO + +EXEC BABEL_3486_vu_prepare_p85 +GO +~~START~~ +time + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p85 +GO + +SELECT BABEL_3486_vu_prepare_f85() +GO +~~START~~ +time + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f85() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v86 +GO +~~START~~ +time + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v86 +GO + +EXEC BABEL_3486_vu_prepare_p86 +GO +~~START~~ +time + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p86 +GO + +SELECT BABEL_3486_vu_prepare_f86() +GO +~~START~~ +time + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f86() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v87 +GO +~~START~~ +time + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v87 +GO + +EXEC BABEL_3486_vu_prepare_p87 +GO +~~START~~ +time + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p87 +GO + +SELECT BABEL_3486_vu_prepare_f87() +GO +~~START~~ +time + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f87() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v88 +GO +~~START~~ +time + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v88 +GO + +EXEC BABEL_3486_vu_prepare_p88 +GO +~~START~~ +time + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p88 +GO + +SELECT BABEL_3486_vu_prepare_f88() +GO +~~START~~ +time + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f88() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v89 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v89 +GO + +EXEC BABEL_3486_vu_prepare_p89 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p89 +GO + +SELECT BABEL_3486_vu_prepare_f89() +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f89() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v90 +GO +~~START~~ +smalldatetime +1900-01-01 13:02:00.0 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v90 +GO + +EXEC BABEL_3486_vu_prepare_p90 +GO +~~START~~ +smalldatetime +1900-01-01 13:02:00.0 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p90 +GO + +SELECT BABEL_3486_vu_prepare_f90() +GO +~~START~~ +smalldatetime +1900-01-01 13:02:00.0 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f90() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v91 +GO +~~START~~ +smalldatetime + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v91 +GO + +EXEC BABEL_3486_vu_prepare_p91 +GO +~~START~~ +smalldatetime + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p91 +GO + +SELECT BABEL_3486_vu_prepare_f91() +GO +~~START~~ +smalldatetime + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f91() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v92 +GO +~~START~~ +smalldatetime + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v92 +GO + +EXEC BABEL_3486_vu_prepare_p92 +GO +~~START~~ +smalldatetime + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p92 +GO + +SELECT BABEL_3486_vu_prepare_f92() +GO +~~START~~ +smalldatetime + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f92() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v93 +GO +~~START~~ +smalldatetime + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v93 +GO + +EXEC BABEL_3486_vu_prepare_p93 +GO +~~START~~ +smalldatetime + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p93 +GO + +SELECT BABEL_3486_vu_prepare_f93() +GO +~~START~~ +smalldatetime + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f93() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v94 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v94 +GO + +EXEC BABEL_3486_vu_prepare_p94 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p94 +GO + +SELECT BABEL_3486_vu_prepare_f94() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f94() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v95 +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v95 +GO + +EXEC BABEL_3486_vu_prepare_p95 +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p95 +GO + +SELECT BABEL_3486_vu_prepare_f95() +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f95() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v96 +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v96 +GO + +EXEC BABEL_3486_vu_prepare_p96 +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p96 +GO + +SELECT BABEL_3486_vu_prepare_f96() +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f96() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v97 +GO +~~START~~ +datetime + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v97 +GO + +EXEC BABEL_3486_vu_prepare_p97 +GO +~~START~~ +datetime + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p97 +GO + +SELECT BABEL_3486_vu_prepare_f97() +GO +~~START~~ +datetime + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f97() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v98 +GO +~~START~~ +datetime + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v98 +GO + +EXEC BABEL_3486_vu_prepare_p98 +GO +~~START~~ +datetime + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p98 +GO + +SELECT BABEL_3486_vu_prepare_f98() +GO +~~START~~ +datetime + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f98() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v99 +GO +~~START~~ +datetime + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v99 +GO + +EXEC BABEL_3486_vu_prepare_p99 +GO +~~START~~ +datetime + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p99 +GO + +SELECT BABEL_3486_vu_prepare_f99() +GO +~~START~~ +datetime + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f99() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v100 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234600 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v100 +GO + +EXEC BABEL_3486_vu_prepare_p100 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.12346 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p100 +GO + +SELECT BABEL_3486_vu_prepare_f100() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234600 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f100() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v101 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v101 +GO + +EXEC BABEL_3486_vu_prepare_p101 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p101 +GO + +SELECT BABEL_3486_vu_prepare_f101() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0000000 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f101() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v102 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v102 +GO + +EXEC BABEL_3486_vu_prepare_p102 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p102 +GO + +SELECT BABEL_3486_vu_prepare_f102() +GO +~~START~~ +datetime2 +1900-01-01 13:01:59.0000000 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f102() +GO + +EXEC BABEL_3486_vu_prepare_p102_2 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Specified scale 10 is invalid. 'datetime2' datatype must have scale between 0 and 7)~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p102_2 +GO + +SELECT BABEL_3486_vu_prepare_f102_2() +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Specified scale 10 is invalid. 'datetime2' datatype must have scale between 0 and 7)~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f102_2() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v103 +GO +~~START~~ +datetime2 + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v103 +GO + +EXEC BABEL_3486_vu_prepare_p103 +GO +~~START~~ +datetime2 + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p103 +GO + +SELECT BABEL_3486_vu_prepare_f103() +GO +~~START~~ +datetime2 + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f103() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v104 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v104 +GO + +EXEC BABEL_3486_vu_prepare_p104 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p104 +GO + +SELECT BABEL_3486_vu_prepare_f104() +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f104() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v105 +GO +~~START~~ +datetimeoffset +1900-01-01 13:01:59.0000000 +12:15 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v105 +GO + +EXEC BABEL_3486_vu_prepare_p105 +GO +~~START~~ +datetimeoffset +1900-01-01 13:01:59.0000000 +12:15 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p105 +GO + +SELECT BABEL_3486_vu_prepare_f105() +GO +~~START~~ +datetimeoffset +1900-01-01 13:01:59.0000000 +12:15 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f105() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v106 +GO +~~START~~ +datetimeoffset + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v106 +GO + +EXEC BABEL_3486_vu_prepare_p106 +GO +~~START~~ +datetimeoffset + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p106 +GO + +SELECT BABEL_3486_vu_prepare_f106() +GO +~~START~~ +datetimeoffset + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f106() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v107 +GO +~~START~~ +sql_variant +1 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v107 +GO + +EXEC BABEL_3486_vu_prepare_p107 +GO +~~START~~ +sql_variant +1 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p107 +GO + +SELECT BABEL_3486_vu_prepare_f107() +GO +~~START~~ +sql_variant +1 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f107() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v108 +GO +~~START~~ +sql_variant +test +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v108 +GO + +EXEC BABEL_3486_vu_prepare_p108 +GO +~~START~~ +sql_variant +test +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p108 +GO + +SELECT BABEL_3486_vu_prepare_f108() +GO +~~START~~ +sql_variant +test +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f108() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v109 +GO +~~START~~ +sql_variant +1.0000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v109 +GO + +EXEC BABEL_3486_vu_prepare_p109 +GO +~~START~~ +sql_variant +1.0000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p109 +GO + +SELECT BABEL_3486_vu_prepare_f109() +GO +~~START~~ +sql_variant +1.0000 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f109() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v110 +GO +~~START~~ +sql_variant +2017-08-25 13:01:59.0 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v110 +GO + +EXEC BABEL_3486_vu_prepare_p110 +GO +~~START~~ +sql_variant +2017-08-25 13:01:59.0 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p110 +GO + +SELECT BABEL_3486_vu_prepare_f110() +GO +~~START~~ +sql_variant +2017-08-25 13:01:59.0 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f110() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v111 +GO +~~START~~ +sql_variant +~~ERROR (Code: 0)~~ + +~~ERROR (Message: Unexpected TDS type DATETIMEOFFSETN in SQL_VARIANT.)~~ + +DROP VIEW BABEL_3486_vu_prepare_v111 +GO + +EXEC BABEL_3486_vu_prepare_p111 +GO +~~START~~ +sql_variant +~~ERROR (Code: 0)~~ + +~~ERROR (Message: Unexpected TDS type DATETIMEOFFSETN in SQL_VARIANT.)~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p111 +GO + +SELECT BABEL_3486_vu_prepare_f111() +GO +~~START~~ +sql_variant +~~ERROR (Code: 0)~~ + +~~ERROR (Message: Unexpected TDS type DATETIMEOFFSETN in SQL_VARIANT.)~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f111() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v113 +GO +~~START~~ +sql_variant +test +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v113 +GO + +EXEC BABEL_3486_vu_prepare_p113 +GO +~~START~~ +sql_variant +test +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p113 +GO + +SELECT BABEL_3486_vu_prepare_f113() +GO +~~START~~ +sql_variant +test +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f113() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v114 +GO +~~START~~ +uniqueidentifier +6F9619FF-8B86-D011-B42D-00C04FC964FF +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v114 +GO + +EXEC BABEL_3486_vu_prepare_p114 +GO +~~START~~ +uniqueidentifier +6F9619FF-8B86-D011-B42D-00C04FC964FF +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p114 +GO + +SELECT BABEL_3486_vu_prepare_f114() +GO +~~START~~ +sql_variant +6F9619FF-8B86-D011-B42D-00C04FC964FF +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f114() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v116 +GO +~~START~~ +uniqueidentifier + +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v116 +GO + +EXEC BABEL_3486_vu_prepare_p116 +GO +~~START~~ +uniqueidentifier + +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p116 +GO + +SELECT BABEL_3486_vu_prepare_f116() +GO +~~START~~ +sql_variant + +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f116() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v117 +GO +~~START~~ +date +1990-01-01 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v117 +GO + +EXEC BABEL_3486_vu_prepare_p117 +GO +~~START~~ +date +1990-01-01 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p117 +GO + +SELECT BABEL_3486_vu_prepare_f117() +GO +~~START~~ +date +1990-01-01 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f117() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v118 +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +DROP VIEW BABEL_3486_vu_prepare_v118 +GO + +EXEC BABEL_3486_vu_prepare_p118 +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +DROP PROCEDURE BABEL_3486_vu_prepare_p118 +GO + +SELECT BABEL_3486_vu_prepare_f118() +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +DROP FUNCTION BABEL_3486_vu_prepare_f118() +GO diff --git a/test/JDBC/expected/BABEL-3486-vu-verify.out b/test/JDBC/expected/BABEL-3486-vu-verify.out index 6039b8e898..b69df27b51 100644 --- a/test/JDBC/expected/BABEL-3486-vu-verify.out +++ b/test/JDBC/expected/BABEL-3486-vu-verify.out @@ -2222,7 +2222,7 @@ SELECT * FROM BABEL_3486_vu_prepare_v84 GO ~~START~~ time - +00:00:00.0000000 ~~END~~ DROP VIEW BABEL_3486_vu_prepare_v84 @@ -2232,7 +2232,7 @@ EXEC BABEL_3486_vu_prepare_p84 GO ~~START~~ time - +00:00:00.0000000 ~~END~~ DROP PROCEDURE BABEL_3486_vu_prepare_p84 @@ -2242,7 +2242,7 @@ SELECT BABEL_3486_vu_prepare_f84() GO ~~START~~ time - +00:00:00.0000000 ~~END~~ DROP FUNCTION BABEL_3486_vu_prepare_f84() @@ -2702,7 +2702,7 @@ SELECT * FROM BABEL_3486_vu_prepare_v100 GO ~~START~~ datetime2 -2017-08-25 13:01:59.1234600 +2017-08-25 13:01:59.12346 ~~END~~ DROP VIEW BABEL_3486_vu_prepare_v100 @@ -2712,7 +2712,7 @@ EXEC BABEL_3486_vu_prepare_p100 GO ~~START~~ datetime2 -2017-08-25 13:01:59.1234600 +2017-08-25 13:01:59.12346 ~~END~~ DROP PROCEDURE BABEL_3486_vu_prepare_p100 @@ -2732,7 +2732,7 @@ SELECT * FROM BABEL_3486_vu_prepare_v101 GO ~~START~~ datetime2 -2017-08-25 13:01:59.0000000 +2017-08-25 13:01:59.0 ~~END~~ DROP VIEW BABEL_3486_vu_prepare_v101 @@ -2742,7 +2742,7 @@ EXEC BABEL_3486_vu_prepare_p101 GO ~~START~~ datetime2 -2017-08-25 13:01:59.0000000 +2017-08-25 13:01:59.0 ~~END~~ DROP PROCEDURE BABEL_3486_vu_prepare_p101 diff --git a/test/JDBC/expected/BABEL-3614-before-17_3-vu-prepare.out b/test/JDBC/expected/BABEL-3614-before-17_3-vu-prepare.out new file mode 100644 index 0000000000..93547a6b62 --- /dev/null +++ b/test/JDBC/expected/BABEL-3614-before-17_3-vu-prepare.out @@ -0,0 +1,184 @@ +CREATE VIEW BABEL_3614_vu_prepare_v1 as (SELECT TRY_CONVERT(DATETIME2(5), '2017-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p1 as (SELECT TRY_CONVERT(DATETIME2(5), '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f1() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(5), '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v2 as (SELECT TRY_CONVERT(DATETIME2(3), '2017-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p2 as (SELECT TRY_CONVERT(DATETIME2(3), '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(3), '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v3 as (SELECT TRY_CONVERT(DATETIME2(1), '2017-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p3 as (SELECT TRY_CONVERT(DATETIME2(1), '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f3() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(1), '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v4 as (SELECT TRY_CONVERT(DATETIME2(7), '2017-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p4 as (SELECT TRY_CONVERT(DATETIME2(7), '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f4() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(7), '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE PROCEDURE BABEL_3614_vu_prepare_p5 as (SELECT TRY_CONVERT(DATETIME2(80), '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f5() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(80), '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v6 as (SELECT TRY_CONVERT(DATETIME2, '2017-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p6 as (SELECT TRY_CONVERT(DATETIME2, '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f6() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v7 as (SELECT TRY_CONVERT(DATETIME2, CAST(5.0 AS decimal))); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p7 as (SELECT TRY_CONVERT(DATETIME2, CAST(5.0 AS decimal))); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f7() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, CAST(5.0 AS decimal))); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v8 as (SELECT TRY_CONVERT(DATETIME2, CAST('2017-08-25' AS DATE))); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p8 as (SELECT TRY_CONVERT(DATETIME2, CAST('2017-08-25' AS DATE))); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f8() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, CAST('2017-08-25' AS DATE))); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v9 as (SELECT sys.datetime2scale(CAST('2017-08-25 13:01:10.1234567' AS DATETIME2(5)), 2)); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p9 as (SELECT sys.datetime2scale(CAST('2017-08-25 13:01:10.1234567' AS DATETIME2(5)), 2)); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f9() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT sys.datetime2scale(CAST('2017-08-25 13:01:10.1234567' AS DATETIME2(5)), 2)); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v10 as (SELECT TRY_CONVERT(datetime2(7), '9999-12-31 23:59:59.9999999')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p10 as (SELECT TRY_CONVERT(DATETIME2(7), '9999-12-31 23:59:59.9999999')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f10() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(7), '9999-12-31 23:59:59.9999999')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v11 as (SELECT TRY_CONVERT(DATETIME2, '0001-01-01')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p11 as (SELECT TRY_CONVERT(DATETIME2, '0001-01-01')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f11() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, '0001-01-01')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v12 as (SELECT TRY_CONVERT(DATETIME2, '1600-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p12 as (SELECT TRY_CONVERT(DATETIME2, '1600-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f12() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, '1600-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v13 as (SELECT TRY_CONVERT(DATETIME2, '13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p13 as (SELECT TRY_CONVERT(DATETIME2, '13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f13() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, '13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v14 as (SELECT TRY_CONVERT(DATETIME2(2), '13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p14 as (SELECT TRY_CONVERT(DATETIME2(2), '13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f14() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(2), '13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v15 as (SELECT TRY_CONVERT(DATETIME2(0), '13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p15 as (SELECT TRY_CONVERT(DATETIME2(0), '13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f15() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(0), '13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v16 as (SELECT babelfish_try_cast_to_datetime2(CAST ('1900-01-01' as xml), CAST(2 as INTEGER))); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p16 as (SELECT babelfish_try_cast_to_datetime2(CAST ('1900-01-01' as xml), CAST(2 as INTEGER))); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f16() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT babelfish_try_cast_to_datetime2(CAST ('1900-01-01' as xml), CAST(2 as INTEGER))); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v17 as (SELECT babelfish_try_cast_to_datetime2('1900-01-01', CAST(2 as INTEGER))); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p17 as (SELECT babelfish_try_cast_to_datetime2('1900-01-01', CAST(2 as INTEGER))); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f17() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT babelfish_try_cast_to_datetime2('1900-01-01', CAST(2 as INTEGER))); +END +GO diff --git a/test/JDBC/expected/BABEL-3614-before-17_3-vu-verify.out b/test/JDBC/expected/BABEL-3614-before-17_3-vu-verify.out new file mode 100644 index 0000000000..8a6fc60bb3 --- /dev/null +++ b/test/JDBC/expected/BABEL-3614-before-17_3-vu-verify.out @@ -0,0 +1,503 @@ +SELECT * FROM BABEL_3614_vu_prepare_v1 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1234600 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v1 +GO + +EXEC BABEL_3614_vu_prepare_p1 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.12346 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p1 +GO + +SELECT BABEL_3614_vu_prepare_f1() +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1234600 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f1() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v2 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1230000 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v2 +GO + +EXEC BABEL_3614_vu_prepare_p2 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.123 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p2 +GO + +SELECT BABEL_3614_vu_prepare_f2() +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1230000 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f2() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v3 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1000000 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v3 +GO + +EXEC BABEL_3614_vu_prepare_p3 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p3 +GO + +SELECT BABEL_3614_vu_prepare_f3() +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1000000 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f3() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v4 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1234570 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v4 +GO + +EXEC BABEL_3614_vu_prepare_p4 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.123457 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p4 +GO + +SELECT BABEL_3614_vu_prepare_f4() +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1234570 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f4() +GO + +EXEC BABEL_3614_vu_prepare_p5 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Specified scale 80 is invalid. 'datetime2' datatype must have scale between 0 and 7)~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p5 +GO + +SELECT BABEL_3614_vu_prepare_f5() +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Specified scale 80 is invalid. 'datetime2' datatype must have scale between 0 and 7)~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f5() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v6 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1234570 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v6 +GO + +EXEC BABEL_3614_vu_prepare_p6 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1234570 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p6 +GO + +SELECT BABEL_3614_vu_prepare_f6() +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1234570 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f6() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v7 +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type "decimal" to datetime2.)~~ + +DROP VIEW BABEL_3614_vu_prepare_v7 +GO + +EXEC BABEL_3614_vu_prepare_p7 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type "decimal" to datetime2 is not allowed.)~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p7 +GO + +SELECT BABEL_3614_vu_prepare_f7() +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type "decimal" to datetime2 is not allowed.)~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f7() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v8 +GO +~~START~~ +datetime2 +2017-08-25 00:00:00.0000000 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v8 +GO + +EXEC BABEL_3614_vu_prepare_p8 +GO +~~START~~ +datetime2 +2017-08-25 00:00:00.0000000 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p8 +GO + +SELECT BABEL_3614_vu_prepare_f8() +GO +~~START~~ +datetime2 +2017-08-25 00:00:00.0000000 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f8() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v9 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1200000 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v9 +GO + +EXEC BABEL_3614_vu_prepare_p9 +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1200000 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p9 +GO + +SELECT BABEL_3614_vu_prepare_f9() +GO +~~START~~ +datetime2 +2017-08-25 13:01:10.1200000 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f9() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v10 +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.9999990 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v10 +GO + +EXEC BABEL_3614_vu_prepare_p10 +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.999999 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p10 +GO + +SELECT BABEL_3614_vu_prepare_f10() +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.9999990 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f10() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v11 +GO +~~START~~ +datetime2 +0001-01-01 00:00:00.0000000 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v11 +GO + +EXEC BABEL_3614_vu_prepare_p11 +GO +~~START~~ +datetime2 +0001-01-01 00:00:00.0000000 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p11 +GO + +SELECT BABEL_3614_vu_prepare_f11() +GO +~~START~~ +datetime2 +0001-01-01 00:00:00.0000000 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f11() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v12 +GO +~~START~~ +datetime2 +1600-08-25 13:01:10.1234570 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v12 +GO + +EXEC BABEL_3614_vu_prepare_p12 +GO +~~START~~ +datetime2 +1600-08-25 13:01:10.1234570 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p12 +GO + +SELECT BABEL_3614_vu_prepare_f12() +GO +~~START~~ +datetime2 +1600-08-25 13:01:10.1234570 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f12() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v13 +GO +~~START~~ +datetime2 +1900-01-01 13:01:10.1234570 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v13 +GO + +EXEC BABEL_3614_vu_prepare_p13 +GO +~~START~~ +datetime2 +1900-01-01 13:01:10.1234570 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p13 +GO + +SELECT BABEL_3614_vu_prepare_f13() +GO +~~START~~ +datetime2 +1900-01-01 13:01:10.1234570 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f13() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v14 +GO +~~START~~ +datetime2 +1900-01-01 13:01:10.1200000 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v14 +GO + +EXEC BABEL_3614_vu_prepare_p14 +GO +~~START~~ +datetime2 +1900-01-01 13:01:10.12 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p14 +GO + +SELECT BABEL_3614_vu_prepare_f14() +GO +~~START~~ +datetime2 +1900-01-01 13:01:10.1200000 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f14() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v15 +GO +~~START~~ +datetime2 +1900-01-01 13:01:10.0000000 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v15 +GO + +EXEC BABEL_3614_vu_prepare_p15 +GO +~~START~~ +datetime2 +1900-01-01 13:01:10 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p15 +GO + +SELECT BABEL_3614_vu_prepare_f15() +GO +~~START~~ +datetime2 +1900-01-01 13:01:10.0000000 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f15() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v16 +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type xml to datetime2.)~~ + +DROP VIEW BABEL_3614_vu_prepare_v16 +GO + +EXEC BABEL_3614_vu_prepare_p16 +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type xml to datetime2.)~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p16 +GO + +SELECT BABEL_3614_vu_prepare_f16() +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type xml to datetime2.)~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f16() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v17 +GO +~~START~~ +datetime2 +1900-01-01 00:00:00.0000000 +~~END~~ + +DROP VIEW BABEL_3614_vu_prepare_v17 +GO + +EXEC BABEL_3614_vu_prepare_p17 +GO +~~START~~ +datetime2 +1900-01-01 00:00:00.0000000 +~~END~~ + +DROP PROCEDURE BABEL_3614_vu_prepare_p17 +GO + +SELECT BABEL_3614_vu_prepare_f17() +GO +~~START~~ +datetime2 +1900-01-01 00:00:00.0000000 +~~END~~ + +DROP FUNCTION BABEL_3614_vu_prepare_f17() +GO diff --git a/test/JDBC/expected/BABEL-3614-vu-verify.out b/test/JDBC/expected/BABEL-3614-vu-verify.out index 70dc1c8fbd..34fdcdace3 100644 --- a/test/JDBC/expected/BABEL-3614-vu-verify.out +++ b/test/JDBC/expected/BABEL-3614-vu-verify.out @@ -2,7 +2,7 @@ SELECT * FROM BABEL_3614_vu_prepare_v1 GO ~~START~~ datetime2 -2017-08-25 13:01:10.1234600 +2017-08-25 13:01:10.12346 ~~END~~ DROP VIEW BABEL_3614_vu_prepare_v1 @@ -12,7 +12,7 @@ EXEC BABEL_3614_vu_prepare_p1 GO ~~START~~ datetime2 -2017-08-25 13:01:10.1234600 +2017-08-25 13:01:10.12346 ~~END~~ DROP PROCEDURE BABEL_3614_vu_prepare_p1 @@ -32,7 +32,7 @@ SELECT * FROM BABEL_3614_vu_prepare_v2 GO ~~START~~ datetime2 -2017-08-25 13:01:10.1230000 +2017-08-25 13:01:10.123 ~~END~~ DROP VIEW BABEL_3614_vu_prepare_v2 @@ -42,7 +42,7 @@ EXEC BABEL_3614_vu_prepare_p2 GO ~~START~~ datetime2 -2017-08-25 13:01:10.1230000 +2017-08-25 13:01:10.123 ~~END~~ DROP PROCEDURE BABEL_3614_vu_prepare_p2 @@ -62,7 +62,7 @@ SELECT * FROM BABEL_3614_vu_prepare_v3 GO ~~START~~ datetime2 -2017-08-25 13:01:10.1000000 +2017-08-25 13:01:10.1 ~~END~~ DROP VIEW BABEL_3614_vu_prepare_v3 @@ -72,7 +72,7 @@ EXEC BABEL_3614_vu_prepare_p3 GO ~~START~~ datetime2 -2017-08-25 13:01:10.1000000 +2017-08-25 13:01:10.1 ~~END~~ DROP PROCEDURE BABEL_3614_vu_prepare_p3 @@ -92,7 +92,7 @@ SELECT * FROM BABEL_3614_vu_prepare_v4 GO ~~START~~ datetime2 -2017-08-25 13:01:10.1234570 +2017-08-25 13:01:10.123457 ~~END~~ DROP VIEW BABEL_3614_vu_prepare_v4 @@ -102,7 +102,7 @@ EXEC BABEL_3614_vu_prepare_p4 GO ~~START~~ datetime2 -2017-08-25 13:01:10.1234570 +2017-08-25 13:01:10.123457 ~~END~~ DROP PROCEDURE BABEL_3614_vu_prepare_p4 @@ -170,22 +170,18 @@ GO SELECT * FROM BABEL_3614_vu_prepare_v7 GO -~~START~~ -datetime2 ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type "decimal" to datetime2.)~~ +~~ERROR (Message: Explicit conversion from data type "decimal" to datetime2 is not allowed.)~~ DROP VIEW BABEL_3614_vu_prepare_v7 GO EXEC BABEL_3614_vu_prepare_p7 GO -~~START~~ -datetime2 ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type "decimal" to datetime2.)~~ +~~ERROR (Message: Explicit conversion from data type "decimal" to datetime2 is not allowed.)~~ DROP PROCEDURE BABEL_3614_vu_prepare_p7 GO @@ -196,7 +192,7 @@ GO datetime2 ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type "decimal" to datetime2.)~~ +~~ERROR (Message: Explicit conversion from data type "decimal" to datetime2 is not allowed.)~~ DROP FUNCTION BABEL_3614_vu_prepare_f7() GO @@ -265,7 +261,7 @@ SELECT * FROM BABEL_3614_vu_prepare_v10 GO ~~START~~ datetime2 -9999-12-31 23:59:59.9999990 +9999-12-31 23:59:59.999999 ~~END~~ DROP VIEW BABEL_3614_vu_prepare_v10 @@ -275,7 +271,7 @@ EXEC BABEL_3614_vu_prepare_p10 GO ~~START~~ datetime2 -9999-12-31 23:59:59.9999990 +9999-12-31 23:59:59.999999 ~~END~~ DROP PROCEDURE BABEL_3614_vu_prepare_p10 @@ -385,7 +381,7 @@ SELECT * FROM BABEL_3614_vu_prepare_v14 GO ~~START~~ datetime2 -1900-01-01 13:01:10.1200000 +1900-01-01 13:01:10.12 ~~END~~ DROP VIEW BABEL_3614_vu_prepare_v14 @@ -395,7 +391,7 @@ EXEC BABEL_3614_vu_prepare_p14 GO ~~START~~ datetime2 -1900-01-01 13:01:10.1200000 +1900-01-01 13:01:10.12 ~~END~~ DROP PROCEDURE BABEL_3614_vu_prepare_p14 @@ -415,7 +411,7 @@ SELECT * FROM BABEL_3614_vu_prepare_v15 GO ~~START~~ datetime2 -1900-01-01 13:01:10.0000000 +1900-01-01 13:01:10 ~~END~~ DROP VIEW BABEL_3614_vu_prepare_v15 @@ -425,7 +421,7 @@ EXEC BABEL_3614_vu_prepare_p15 GO ~~START~~ datetime2 -1900-01-01 13:01:10.0000000 +1900-01-01 13:01:10 ~~END~~ DROP PROCEDURE BABEL_3614_vu_prepare_p15 diff --git a/test/JDBC/expected/BABEL-5031-vu-verify.out b/test/JDBC/expected/BABEL-5031-vu-verify.out new file mode 100644 index 0000000000..85637efc98 --- /dev/null +++ b/test/JDBC/expected/BABEL-5031-vu-verify.out @@ -0,0 +1,106 @@ +-- Customer case +CREATE TABLE [dbo].[babel_5031_MemberValues]( + [Id] [uniqueidentifier] NOT NULL, + [PanelId] [uniqueidentifier] NOT NULL, + [EndEffectiveDate] [datetime2](7) NOT NULL +); +GO + +CREATE NONCLUSTERED INDEX [babel_5031_IDX_MBRVAL_SHARED_LATEST_FILT] ON [dbo].[babel_5031_MemberValues] ([PanelId] ASC) +WHERE ([EndEffectiveDate]=CONVERT([datetime2](7),'9999-12-31 23:59:59.9999999')); +GO + +DROP TABLE babel_5031_MemberValues +GO + +-- Using convert function for converting from string to date/datetime/datetime2/datetimeoffset/smalldatetime/time +-- in computed column of table +CREATE TABLE babel_5031_t1(col_string VARCHAR(100), + col_date AS CONVERT(date, col_string), + col_datetime AS CONVERT(datetime, col_string), + col_datetime2 AS CONVERT(datetime2, col_string), + col_dateoffset AS CONVERT(datetimeoffset, col_string), + col_smalldatetime AS CONVERT(smalldatetime, col_string), + col_time AS CONVERT(time, col_string)); +GO + +INSERT INTO babel_5031_t1 VALUES('2026-12-31 23:59:59.99'); +GO +~~ROW COUNT: 1~~ + + +INSERT INTO babel_5031_t1 VALUES('11.12.2024'); +GO +~~ROW COUNT: 1~~ + + +INSERT INTO babel_5031_t1 VALUES('2022-10-30T03:00:00.123'); +GO +~~ROW COUNT: 1~~ + + +INSERT INTO babel_5031_t1 VALUES('20240129 03:00:00'); +GO +~~ROW COUNT: 1~~ + + +SELECT * FROM babel_5031_t1 +GO +~~START~~ +varchar#!#date#!#datetime#!#datetime2#!#datetimeoffset#!#smalldatetime#!#time +2026-12-31 23:59:59.99#!#2026-12-31#!#2026-12-31 23:59:59.99#!#2026-12-31 23:59:59.9900000#!#2026-12-31 23:59:59.9900000 +00:00#!#2027-01-01 00:00:00.0#!#23:59:59.9900000 +11.12.2024#!#2024-11-12#!#2024-11-12 00:00:00.0#!#2024-11-12 00:00:00.0000000#!#2024-11-12 00:00:00.0000000 +00:00#!#2024-11-12 00:00:00.0#!#00:00:00.0000000 +2022-10-30T03:00:00.123#!#2022-10-30#!#2022-10-30 03:00:00.123#!#2022-10-30 03:00:00.1230000#!#2022-10-30 03:00:00.1230000 +00:00#!#2022-10-30 03:00:00.0#!#03:00:00.1230000 +20240129 03:00:00#!#2024-01-29#!#2024-01-29 03:00:00.0#!#2024-01-29 03:00:00.0000000#!#2024-01-29 03:00:00.0000000 +00:00#!#2024-01-29 03:00:00.0#!#03:00:00.0000000 +~~END~~ + + +DROP TABLE babel_5031_t1 +GO + +-- Using convert function for converting from string to date/datetime/datetime2/datetimeoffset/smalldatetime/time +-- in check constraint of table +CREATE TABLE babel_5031_t2(col_string VARCHAR(100), + CHECK (CONVERT(date, col_string) > CONVERT(date, '03-05-2023')), + CHECK (CONVERT(datetime, col_string) > CONVERT(datetime, '03-05-2023')), + CHECK (CONVERT(datetime2, col_string) > CONVERT(datetime2, '03-05-2023')), + CHECK (CONVERT(datetimeoffset, col_string) > CONVERT(datetimeoffset, '03-05-2023')), + CHECK (CONVERT(smalldatetime, col_string) > CONVERT(smalldatetime, '03-05-2023')), + CHECK (CONVERT(time, col_string) > CONVERT(time, '03-05-2023'))); +GO + +INSERT INTO babel_5031_t2 VALUES('2026-12-31 23:59:59.99'); +GO +~~ROW COUNT: 1~~ + + +INSERT INTO babel_5031_t2 VALUES('11.12.2024'); +GO +~~ERROR (Code: 547)~~ + +~~ERROR (Message: new row for relation "babel_5031_t2" violates check constraint "babel_5031_t2_col_string_check5")~~ + + +INSERT INTO babel_5031_t2 VALUES('2022-10-30T03:00:00.123'); +GO +~~ERROR (Code: 547)~~ + +~~ERROR (Message: new row for relation "babel_5031_t2" violates check constraint "babel_5031_t2_col_string_check")~~ + + +INSERT INTO babel_5031_t2 VALUES('20240129 03:00:00'); +GO +~~ROW COUNT: 1~~ + + +SELECT * FROM babel_5031_t2 +GO +~~START~~ +varchar +2026-12-31 23:59:59.99 +20240129 03:00:00 +~~END~~ + + +DROP TABLE babel_5031_t2 +GO diff --git a/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-prepare.out b/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-prepare.out new file mode 100644 index 0000000000..6a9a9d3e22 --- /dev/null +++ b/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-prepare.out @@ -0,0 +1,632 @@ +CREATE VIEW Datetime_view3 +AS( + SELECT + CONVERT(DATETIME, CAST(2.5 as BIT)) as re1, + CONVERT(DATETIME, CAST(2.5 as DECIMAL))as re2, + CONVERT(DATETIME, CAST(2.5 as NUMERIC(30,8)))as re3, + CONVERT(DATETIME, CAST(2.5 as FLOAT))as re4, + CONVERT(DATETIME, CAST(2.5 as REAL))as re5, + CONVERT(DATETIME, CAST(2.5 as INT))as re6, + CONVERT(DATETIME, CAST(2.5 as BIGINT))as re7, + CONVERT(DATETIME, CAST(2.5 as SMALLINT))as re8, + CONVERT(DATETIME, CAST(2.5 as TINYINT))as re9, + CONVERT(DATETIME, CAST(2.5 as MONEY))as re10, + CONVERT(DATETIME, CAST(2.5 as SMALLMONEY))as re11, + CONVERT(DATETIME, CAST(-2.5 as BIT)) as re12, + CONVERT(DATETIME, CAST(-2.5 as DECIMAL))as re13, + CONVERT(DATETIME, CAST(-2.5 as NUMERIC(30,8)))as re14, + CONVERT(DATETIME, CAST(-2.5 as FLOAT))as re15, + CONVERT(DATETIME, CAST(-2.5 as REAL))as re16, + CONVERT(DATETIME, CAST(-2.5 as INT))as re17, + CONVERT(DATETIME, CAST(-2.5 as BIGINT))as re18, + CONVERT(DATETIME, CAST(-2.5 as SMALLINT))as re19, + CONVERT(DATETIME, CAST(-2.5 as MONEY))as re20, + CONVERT(DATETIME, CAST(-2.5 as SMALLMONEY))as re21, + CONVERT(DATETIME, NULL)as res22 +); +GO + +CREATE VIEW Datetime_view4 +AS( + SELECT + CONVERT(SMALLDATETIME, CAST(2.5 as BIT)) as re1, + CONVERT(SMALLDATETIME, CAST(2.5 as DECIMAL)) as re2, + CONVERT(SMALLDATETIME, CAST(2.5 as NUMERIC(30,8))) as re3, + CONVERT(SMALLDATETIME, CAST(2.5 as FLOAT)) as re4, + CONVERT(SMALLDATETIME, CAST(2.5 as REAL)) as re5, + CONVERT(SMALLDATETIME, CAST(2.5 as INT)) as re6, + CONVERT(SMALLDATETIME, CAST(2.5 as BIGINT)) as re7, + CONVERT(SMALLDATETIME, CAST(2.5 as SMALLINT)) as re8, + CONVERT(SMALLDATETIME, CAST(2.5 as TINYINT)) as re9, + CONVERT(SMALLDATETIME, CAST(2.5 as MONEY)) as re10, + CONVERT(SMALLDATETIME, CAST(2.5 as SMALLMONEY)) as re11, + CONVERT(SMALLDATETIME, CAST(-2.5 as BIT)) as re12, + CONVERT(SMALLDATETIME, NULL) as res13 +); +GO + +-- Should all fail +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as DECIMAL)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: data out of range for smalldatetime)~~ + +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as NUMERIC(30,8))) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: data out of range for smalldatetime)~~ + +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as FLOAT)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: data out of range for smalldatetime)~~ + +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as REAL)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: data out of range for smalldatetime)~~ + +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as INT)) +GO +~~START~~ +smalldatetime +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: data out of range for smalldatetime)~~ + +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as BIGINT)) +GO +~~START~~ +smalldatetime +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: data out of range for smalldatetime)~~ + +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as SMALLINT)) +GO +~~START~~ +smalldatetime +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: data out of range for smalldatetime)~~ + +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as MONEY)) +GO +~~START~~ +smalldatetime +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: data out of range for smalldatetime)~~ + +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as SMALLMONEY)) +GO +~~START~~ +smalldatetime +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: data out of range for smalldatetime)~~ + + +-- Should all fail +SELECT CONVERT(DATETIME2, CAST(-2.5 as DECIMAL)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type "decimal" to datetime2)~~ + +SELECT CONVERT(DATETIME2, CAST(-2.5 as NUMERIC(30,8))) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type numeric to datetime2)~~ + +SELECT CONVERT(DATETIME2, CAST(-2.5 as FLOAT)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type double precision to datetime2)~~ + +SELECT CONVERT(DATETIME2, CAST(-2.5 as REAL)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type real to datetime2)~~ + +SELECT CONVERT(DATETIME2, CAST(-2.5 as INT)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to datetime2)~~ + +SELECT CONVERT(DATETIME2, CAST(-2.5 as BIGINT)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type bigint to datetime2)~~ + +SELECT CONVERT(DATETIME2, CAST(-2.5 as SMALLINT)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type smallint to datetime2)~~ + +SELECT CONVERT(DATETIME2, CAST(-2.5 as MONEY)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type money to datetime2)~~ + +SELECT CONVERT(DATETIME2, CAST(-2.5 as SMALLMONEY)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type smallmoney to datetime2)~~ + + +-- Should all fail +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as DECIMAL)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type "decimal" to datetimeoffset)~~ + +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as NUMERIC(30,8))) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type numeric to datetimeoffset)~~ + +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as FLOAT)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type double precision to datetimeoffset)~~ + +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as REAL)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type real to datetimeoffset)~~ + +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as INT)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to datetimeoffset)~~ + +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as BIGINT)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type bigint to datetimeoffset)~~ + +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as SMALLINT)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type smallint to datetimeoffset)~~ + +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as MONEY)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type money to datetimeoffset)~~ + +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as SMALLMONEY)) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type smallmoney to datetimeoffset)~~ + + +-- Should all fail +SELECT CONVERT(DATE, CAST(-2.5 as DECIMAL)) +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type "decimal" to date)~~ + +SELECT CONVERT(DATE, CAST(-2.5 as NUMERIC(30,8))) +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type numeric to date)~~ + +SELECT CONVERT(DATE, CAST(-2.5 as FLOAT)) +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type double precision to date)~~ + +SELECT CONVERT(DATE, CAST(-2.5 as REAL)) +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type real to date)~~ + +SELECT CONVERT(DATE, CAST(-2.5 as INT)) +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to date)~~ + +SELECT CONVERT(DATE, CAST(-2.5 as BIGINT)) +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type bigint to date)~~ + +SELECT CONVERT(DATE, CAST(-2.5 as SMALLINT)) +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type smallint to date)~~ + +SELECT CONVERT(DATE, CAST(-2.5 as MONEY)) +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type money to date)~~ + +SELECT CONVERT(DATE, CAST(-2.5 as SMALLMONEY)) +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type smallmoney to date)~~ + + +-- Should all fail +SELECT CONVERT(TIME, CAST(-2.5 as DECIMAL)) +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type "decimal" to time without time zone)~~ + +SELECT CONVERT(TIME, CAST(-2.5 as NUMERIC(30,8))) +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type numeric to time without time zone)~~ + +SELECT CONVERT(TIME, CAST(-2.5 as FLOAT)) +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type double precision to time without time zone)~~ + +SELECT CONVERT(TIME, CAST(-2.5 as REAL)) +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type real to time without time zone)~~ + +SELECT CONVERT(TIME, CAST(-2.5 as INT)) +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to time without time zone)~~ + +SELECT CONVERT(TIME, CAST(-2.5 as BIGINT)) +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type bigint to time without time zone)~~ + +SELECT CONVERT(TIME, CAST(-2.5 as SMALLINT)) +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type smallint to time without time zone)~~ + +SELECT CONVERT(TIME, CAST(-2.5 as MONEY)) +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type money to time without time zone)~~ + +SELECT CONVERT(TIME, CAST(-2.5 as SMALLMONEY)) +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type smallmoney to time without time zone)~~ + + +CREATE VIEW Datetime_view5 as ( + SELECT + DATEADD(minute, 1, CAST(2.5 as DECIMAL)) as re1, + DATEADD(minute, 1, CAST(2.5 as NUMERIC(30,8))) as re2, + DATEADD(minute, 1, CAST(2.5 as FLOAT)) as re3, + DATEADD(minute, 1, CAST(2.5 as REAL)) as re4, + DATEADD(minute, 1, CAST(2.5 as INT)) as re5, + DATEADD(minute, 1, CAST(2.5 as BIGINT)) as re6, + DATEADD(minute, 1, CAST(2.5 as SMALLINT)) as re7, + DATEADD(minute, 1, CAST(2.5 as TINYINT)) as re8, + DATEADD(minute, 1, CAST(2.5 as MONEY)) as re9, + DATEADD(minute, 1, CAST(2.5 as SMALLMONEY)) as re10, + DATEADD(minute, 1, CAST(-2.5 as BIT)) as re11, + DATEADD(minute, 1, CAST(-2.5 as DECIMAL)) as re12, + DATEADD(minute, 1, CAST(-2.5 as NUMERIC(30,8))) as re13, + DATEADD(minute, 1, CAST(-2.5 as FLOAT)) as re14, + DATEADD(minute, 1, CAST(-2.5 as REAL)) as re15, + DATEADD(minute, 1, CAST(-2.5 as INT)) as re16, + DATEADD(minute, 1, CAST(-2.5 as BIGINT)) as re17, + DATEADD(minute, 1, CAST(-2.5 as SMALLINT)) as re18, + DATEADD(minute, 1, CAST(-2.5 as MONEY)) as re19, + DATEADD(minute, 1, CAST(-2.5 as SMALLMONEY)) as re20, + DATEADD(minute, 1, CAST(-2.5 as BIT)) as re21 +); +GO + +CREATE VIEW Datetime_view7 as ( + SELECT + DATENAME(day, CAST(2.5 as DECIMAL)) as re1, + DATENAME(day, CAST(2.5 as NUMERIC(30,8))) as re2, + DATENAME(day, CAST(2.5 as FLOAT)) as re3, + DATENAME(day, CAST(2.5 as REAL)) as re4, + DATENAME(day, CAST(2.5 as INT)) as re5, + DATENAME(day, CAST(2.5 as BIGINT)) as re6, + DATENAME(day, CAST(2.5 as SMALLINT)) as re7, + DATENAME(day, CAST(2.5 as TINYINT)) as re8, + DATENAME(day, CAST(2.5 as MONEY)) as re9, + DATENAME(day, CAST(2.5 as SMALLMONEY)) as re10, + DATENAME(day, CAST(2.5 as BIT)) as re11, + DATENAME(day, CAST(-2.5 as DECIMAL)) as re12, + DATENAME(day, CAST(-2.5 as NUMERIC(30,8))) as re13, + DATENAME(day, CAST(-2.5 as FLOAT)) as re14, + DATENAME(day, CAST(-2.5 as REAL)) as re15, + DATENAME(day, CAST(-2.5 as INT)) as re16, + DATENAME(day, CAST(-2.5 as BIGINT)) as re17, + DATENAME(day, CAST(-2.5 as SMALLINT)) as re18, + DATENAME(day, CAST(-2.5 as MONEY)) as re19, + DATENAME(day, CAST(-2.5 as SMALLMONEY)) as re20, + DATENAME(day, CAST(-2.5 as BIT)) as re21 +); +GO + +CREATE VIEW Datetime_view8 as ( + SELECT + DATEPART(day, CAST(2.5 as DECIMAL)) as re1, + DATEPART(day, CAST(2.5 as NUMERIC(30,8))) as re2, + DATEPART(day, CAST(2.5 as FLOAT)) as re3, + DATEPART(day, CAST(2.5 as REAL)) as re4, + DATEPART(day, CAST(2.5 as INT)) as re5, + DATEPART(day, CAST(2.5 as BIGINT)) as re6, + DATEPART(day, CAST(2.5 as SMALLINT)) as re7, + DATEPART(day, CAST(2.5 as TINYINT)) as re8, + DATEPART(day, CAST(2.5 as MONEY)) as re9, + DATEPART(day, CAST(2.5 as SMALLMONEY)) as re10, + DATEPART(day, CAST(2.5 as BIT)) as re11, + DATEPART(day, CAST(-2.5 as DECIMAL)) as re12, + DATEPART(day, CAST(-2.5 as NUMERIC(30,8))) as re13, + DATEPART(day, CAST(-2.5 as FLOAT)) as re14, + DATEPART(day, CAST(-2.5 as REAL)) as re15, + DATEPART(day, CAST(-2.5 as INT)) as re16, + DATEPART(day, CAST(-2.5 as BIGINT)) as re17, + DATEPART(day, CAST(-2.5 as SMALLINT)) as re18, + DATEPART(day, CAST(-2.5 as MONEY)) as re19, + DATEPART(day, CAST(-2.5 as SMALLMONEY)) as re20, + DATEPART(day, CAST(-2.5 as BIT)) as re21 +); +GO + +CREATE PROCEDURE Datetime_proc1 (@a DATETIME, @b BIT) AS +BEGIN + DECLARE @c DATETIME = @b; + SELECT (CASE WHEN @a = @c THEN 'pass' ELSE 'fail' END) as result; +END +GO + +CREATE PROCEDURE SMALLDatetime_proc1 (@a SMALLDATETIME, @b BIT) AS +BEGIN + DECLARE @c SMALLDATETIME = @b; + SELECT (CASE WHEN @a = @c THEN 'pass' ELSE 'fail' END) as result; +END +GO + +CREATE VIEW dateadd_numeric_representation_helper_year_view AS +SELECT +dateadd_numeric_representation_helper('year',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('year',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('year',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('year',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('year',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('year',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('year',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('year',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('year',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_quarter_view AS +SELECT +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_month_view AS +SELECT +dateadd_numeric_representation_helper('month',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('month',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('month',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('month',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('month',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('month',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('month',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('month',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('month',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_dayofyear_view AS +SELECT +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_day_view AS +SELECT +dateadd_numeric_representation_helper('day',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('day',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('day',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('day',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('day',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('day',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('day',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('day',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('day',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_week_view AS +SELECT +dateadd_numeric_representation_helper('week',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('week',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('week',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('week',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('week',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('week',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('week',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('week',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('week',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_weekday_view AS +SELECT +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_hour_view AS +SELECT +dateadd_numeric_representation_helper('hour',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_minute_view AS +SELECT +dateadd_numeric_representation_helper('minute',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_second_view AS +SELECT +dateadd_numeric_representation_helper('second',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('second',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('second',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('second',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('second',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('second',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('second',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('second',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('second',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_millisecond_view AS +SELECT +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + + +CREATE VIEW dateadd_view_1 AS +SELECT * FROM sys.dateadd('year',1,cast(1.5 as REAL)) +GO + +CREATE VIEW dateadd_view_2 AS +SELECT * FROM sys.dateadd('year',1,cast(1.5 as NUMERIC(30,8))) +GO + +CREATE VIEW dateadd_view_3 AS +SELECT * FROM sys.dateadd('year',1,cast(1.5 as DECIMAL)) +GO + +CREATE VIEW dateadd_view_4 AS +SELECT * FROM sys.dateadd('year',1,cast(1 as BIT)) +GO + +CREATE VIEW dateadd_view_5 AS +SELECT * FROM sys.dateadd('year',1,cast(1.5 as FLOAT)) +GO + +CREATE VIEW dateadd_view_6 AS +SELECT * FROM sys.dateadd('year',1,cast(1.5 as FLOAT)) +GO diff --git a/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.out b/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.out new file mode 100644 index 0000000000..56817beab8 --- /dev/null +++ b/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.out @@ -0,0 +1,309 @@ +-- output from SQL Server : +-- 1900-01-02 00:00:00.000 1900-01-04 00:00:00.000 1900-01-03 12:00:00.000 1900-01-03 12:00:00.000 1900-01-03 12:00:00.000 1900-01-03 00:00:00.000 1900-01-03 00:00:00.000 1900-01-03 00:00:00.000 1900-01-03 00:00:00.000 1900-01-03 12:00:00.000 1900-01-03 12:00:00.000 1900-01-02 00:00:00.000 1899-12-29 00:00:00.000 1899-12-29 12:00:00.000 1899-12-29 12:00:00.000 1899-12-29 12:00:00.000 1899-12-30 00:00:00.000 1899-12-30 00:00:00.000 1899-12-30 00:00:00.000 1899-12-29 12:00:00.000 1899-12-29 12:00:00.000 null +SELECT * FROM Datetime_view3 +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-01-02 00:00:00.0#!#1900-01-04 00:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-02 00:00:00.0#!#1899-12-29 00:00:00.0#!#1899-12-29 12:00:00.0#!#1899-12-29 12:00:00.0#!#1899-12-29 12:00:00.0#!#1899-12-30 00:00:00.0#!#1899-12-30 00:00:00.0#!#1899-12-30 00:00:00.0#!#1899-12-29 12:00:00.0#!#1899-12-29 12:00:00.0#!# +~~END~~ + +DROP VIEW Datetime_view3 +GO + +-- output from SQL Server : +-- 1900-01-02 00:00 1900-01-04 00:00 1900-01-03 12:00 1900-01-03 12:00 1900-01-03 12:00 1900-01-03 00:00 1900-01-03 00:00 1900-01-03 00:00 1900-01-03 00:00 1900-01-03 12:00 1900-01-03 12:00 1900-01-02 00:00 null +SELECT * FROM Datetime_view4 +GO +~~START~~ +smalldatetime#!#smalldatetime#!#smalldatetime#!#smalldatetime#!#smalldatetime#!#smalldatetime#!#smalldatetime#!#smalldatetime#!#smalldatetime#!#smalldatetime#!#smalldatetime#!#smalldatetime#!#smalldatetime +1900-01-02 00:00:00.0#!#1900-01-04 00:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-02 00:00:00.0#!# +~~END~~ + +DROP VIEW Datetime_view4 +GO + +-- output from SQL Server : +-- 1900-01-04 00:01:00.000 1900-01-03 12:01:00.000 1900-01-03 12:01:00.000 1900-01-03 12:01:00.000 1900-01-03 00:01:00.000 1900-01-03 00:01:00.000 1900-01-03 00:01:00.000 1900-01-03 00:01:00.000 1900-01-03 12:01:00.000 1900-01-03 12:01:00.000 1899-12-28 23:59:00.000 1899-12-29 11:59:00.000 1899-12-29 11:59:00.000 1899-12-29 11:59:00.000 1899-12-29 23:59:00.000 1899-12-29 23:59:00.000 1899-12-29 23:59:00.000 1899-12-29 11:59:00.000 1899-12-29 11:59:00.000 +SELECT * FROM Datetime_view5 +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-01-04 00:01:00.0#!#1900-01-03 12:01:00.0#!#1900-01-03 12:01:00.0#!#1900-01-03 12:01:00.0#!#1900-01-03 00:01:00.0#!#1900-01-03 00:01:00.0#!#1900-01-03 00:01:00.0#!#1900-01-03 00:01:00.0#!#1900-01-03 12:01:00.0#!#1900-01-03 12:01:00.0#!#1900-01-02 00:01:00.0#!#1899-12-29 00:01:00.0#!#1899-12-29 12:01:00.0#!#1899-12-29 12:01:00.0#!#1899-12-29 12:01:00.0#!#1899-12-30 00:01:00.0#!#1899-12-30 00:01:00.0#!#1899-12-30 00:01:00.0#!#1899-12-29 12:01:00.0#!#1899-12-29 12:01:00.0#!#1900-01-02 00:01:00.0 +~~END~~ + +DROP VIEW Datetime_view5 +GO + +-- output from SQL Server : +-- 4 3 3 3 3 3 3 3 3 3 2 29 29 29 29 30 30 30 29 29 2 +SELECT * FROM Datetime_view7 +GO +~~START~~ +text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text#!#text +4#!#3#!#3#!#3#!#3#!#3#!#3#!#3#!#3#!#3#!#2#!#29#!#29#!#29#!#29#!#30#!#30#!#30#!#29#!#29#!#2 +~~END~~ + +DROP VIEW Datetime_view7 +GO + +-- output from SQL Server : +-- 4 3 3 3 3 3 3 3 3 3 2 29 29 29 29 30 30 30 29 29 2 +SELECT * FROM Datetime_view8 +GO +~~START~~ +int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int +4#!#3#!#3#!#3#!#3#!#3#!#3#!#3#!#3#!#3#!#2#!#29#!#29#!#29#!#29#!#30#!#30#!#30#!#29#!#29#!#2 +~~END~~ + +DROP VIEW Datetime_view8 +GO + +-- Procedures +EXEC Datetime_proc1 '1900-01-02 00:00:00', 3.1 +GO +~~START~~ +text +pass +~~END~~ + +EXEC Datetime_proc1 '1900-01-02 00:00:00', 2 +GO +~~START~~ +text +pass +~~END~~ + +EXEC Datetime_proc1 '1900-01-01 00:00:00', 0 +GO +~~START~~ +text +pass +~~END~~ + +EXEC Datetime_proc1 '1900-01-02 00:00:00', -3.1 +GO +~~START~~ +text +pass +~~END~~ + +DROP PROCEDURE Datetime_proc1 +GO + +EXEC SMALLDatetime_proc1 '1900-01-02 00:00:00', 3.1 +GO +~~START~~ +text +pass +~~END~~ + +EXEC SMALLDatetime_proc1 '1900-01-02 00:00:00', 2 +GO +~~START~~ +text +pass +~~END~~ + +EXEC SMALLDatetime_proc1 '1900-01-01 00:00:00', 0 +GO +~~START~~ +text +pass +~~END~~ + +EXEC SMALLDatetime_proc1 '1900-01-02 00:00:00', -3.1 +GO +~~START~~ +text +pass +~~END~~ + +DROP PROCEDURE SMALLDatetime_proc1 +GO + +SELECT * FROM dateadd_numeric_representation_helper_year_view +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1901-01-02 00:00:00.0#!#1901-01-02 00:00:00.0#!#1901-01-02 00:00:00.0#!#1901-01-02 00:00:00.0#!#1901-01-03 00:00:00.0#!#1901-01-02 12:00:00.0#!#1901-01-02 12:00:00.0#!#1901-01-02 12:00:00.0#!#1901-01-02 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_numeric_representation_helper_year_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_quarter_view +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-04-02 00:00:00.0#!#1900-04-02 00:00:00.0#!#1900-04-02 00:00:00.0#!#1900-04-02 00:00:00.0#!#1900-04-03 00:00:00.0#!#1900-04-02 12:00:00.0#!#1900-04-02 12:00:00.0#!#1900-04-02 12:00:00.0#!#1900-04-02 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_numeric_representation_helper_quarter_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_month_view +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-02-02 00:00:00.0#!#1900-02-02 00:00:00.0#!#1900-02-02 00:00:00.0#!#1900-02-02 00:00:00.0#!#1900-02-03 00:00:00.0#!#1900-02-02 12:00:00.0#!#1900-02-02 12:00:00.0#!#1900-02-02 12:00:00.0#!#1900-02-02 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_numeric_representation_helper_month_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_dayofyear_view +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-04 00:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_numeric_representation_helper_dayofyear_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_day_view +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-04 00:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_numeric_representation_helper_day_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_week_view +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-01-09 00:00:00.0#!#1900-01-09 00:00:00.0#!#1900-01-09 00:00:00.0#!#1900-01-09 00:00:00.0#!#1900-01-10 00:00:00.0#!#1900-01-09 12:00:00.0#!#1900-01-09 12:00:00.0#!#1900-01-09 12:00:00.0#!#1900-01-09 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_numeric_representation_helper_week_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_weekday_view +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-04 00:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0#!#1900-01-03 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_numeric_representation_helper_weekday_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_hour_view +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-01-02 01:00:00.0#!#1900-01-02 01:00:00.0#!#1900-01-02 01:00:00.0#!#1900-01-02 01:00:00.0#!#1900-01-03 01:00:00.0#!#1900-01-02 13:00:00.0#!#1900-01-02 13:00:00.0#!#1900-01-02 13:00:00.0#!#1900-01-02 13:00:00.0 +~~END~~ + + +DROP VIEW dateadd_numeric_representation_helper_hour_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_minute_view +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-01-02 00:01:00.0#!#1900-01-02 00:01:00.0#!#1900-01-02 00:01:00.0#!#1900-01-02 00:01:00.0#!#1900-01-03 00:01:00.0#!#1900-01-02 12:01:00.0#!#1900-01-02 12:01:00.0#!#1900-01-02 12:01:00.0#!#1900-01-02 12:01:00.0 +~~END~~ + + +DROP VIEW dateadd_numeric_representation_helper_minute_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_second_view +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-01-02 00:00:01.0#!#1900-01-02 00:00:01.0#!#1900-01-02 00:00:01.0#!#1900-01-02 00:00:01.0#!#1900-01-03 00:00:01.0#!#1900-01-02 12:00:01.0#!#1900-01-02 12:00:01.0#!#1900-01-02 12:00:01.0#!#1900-01-02 12:00:01.0 +~~END~~ + + +DROP VIEW dateadd_numeric_representation_helper_second_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_millisecond_view +GO +~~START~~ +datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime#!#datetime +1900-01-02 00:00:00.0#!#1900-01-02 00:00:00.0#!#1900-01-02 00:00:00.0#!#1900-01-02 00:00:00.0#!#1900-01-03 00:00:00.0#!#1900-01-02 12:00:00.0#!#1900-01-02 12:00:00.0#!#1900-01-02 12:00:00.0#!#1900-01-02 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_numeric_representation_helper_millisecond_view +GO + +SELECT * FROM dateadd_view_1 +GO +~~START~~ +datetime +1901-01-02 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_view_1 +GO + +SELECT * FROM dateadd_view_2 +GO +~~START~~ +datetime +1901-01-02 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_view_2 +GO + +SELECT * FROM dateadd_view_3 +GO +~~START~~ +datetime +1901-01-03 00:00:00.0 +~~END~~ + + +DROP VIEW dateadd_view_3 +GO + +SELECT * FROM dateadd_view_4 +GO +~~START~~ +datetime +1901-01-02 00:00:00.0 +~~END~~ + + +DROP VIEW dateadd_view_4 +GO + +SELECT * FROM dateadd_view_5 +GO +~~START~~ +datetime +1901-01-02 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_view_5 +GO + +SELECT * FROM dateadd_view_6 +GO +~~START~~ +datetime +1901-01-02 12:00:00.0 +~~END~~ + + +DROP VIEW dateadd_view_6 +GO diff --git a/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-vu-prepare.out b/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-vu-prepare.out index 6a9a9d3e22..bed83b1f44 100644 --- a/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-vu-prepare.out +++ b/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-vu-prepare.out @@ -50,25 +50,25 @@ SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as DECIMAL)) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: data out of range for smalldatetime)~~ +~~ERROR (Message: Arithmetic overflow error converting expression to data type smalldatetime.)~~ SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as NUMERIC(30,8))) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: data out of range for smalldatetime)~~ +~~ERROR (Message: Arithmetic overflow error converting expression to data type smalldatetime.)~~ SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as FLOAT)) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: data out of range for smalldatetime)~~ +~~ERROR (Message: Arithmetic overflow error converting expression to data type smalldatetime.)~~ SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as REAL)) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: data out of range for smalldatetime)~~ +~~ERROR (Message: Arithmetic overflow error converting expression to data type smalldatetime.)~~ SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as INT)) GO @@ -76,7 +76,7 @@ GO smalldatetime ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: data out of range for smalldatetime)~~ +~~ERROR (Message: Arithmetic overflow error converting expression to data type smalldatetime.)~~ SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as BIGINT)) GO @@ -84,7 +84,7 @@ GO smalldatetime ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: data out of range for smalldatetime)~~ +~~ERROR (Message: Arithmetic overflow error converting expression to data type smalldatetime.)~~ SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as SMALLINT)) GO @@ -92,7 +92,7 @@ GO smalldatetime ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: data out of range for smalldatetime)~~ +~~ERROR (Message: Arithmetic overflow error converting expression to data type smalldatetime.)~~ SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as MONEY)) GO @@ -100,7 +100,7 @@ GO smalldatetime ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: data out of range for smalldatetime)~~ +~~ERROR (Message: Arithmetic overflow error converting expression to data type smalldatetime.)~~ SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as SMALLMONEY)) GO @@ -108,7 +108,7 @@ GO smalldatetime ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: data out of range for smalldatetime)~~ +~~ERROR (Message: Arithmetic overflow error converting expression to data type smalldatetime.)~~ -- Should all fail @@ -116,55 +116,65 @@ SELECT CONVERT(DATETIME2, CAST(-2.5 as DECIMAL)) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type "decimal" to datetime2)~~ +~~ERROR (Message: Explicit conversion from data type "decimal" to datetime2 is not allowed.)~~ SELECT CONVERT(DATETIME2, CAST(-2.5 as NUMERIC(30,8))) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type numeric to datetime2)~~ +~~ERROR (Message: Explicit conversion from data type numeric to datetime2 is not allowed.)~~ SELECT CONVERT(DATETIME2, CAST(-2.5 as FLOAT)) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type double precision to datetime2)~~ +~~ERROR (Message: Explicit conversion from data type double precision to datetime2 is not allowed.)~~ SELECT CONVERT(DATETIME2, CAST(-2.5 as REAL)) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type real to datetime2)~~ +~~ERROR (Message: Explicit conversion from data type real to datetime2 is not allowed.)~~ SELECT CONVERT(DATETIME2, CAST(-2.5 as INT)) GO +~~START~~ +datetime2 ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type integer to datetime2)~~ +~~ERROR (Message: Explicit conversion from data type integer to datetime2 is not allowed.)~~ SELECT CONVERT(DATETIME2, CAST(-2.5 as BIGINT)) GO +~~START~~ +datetime2 ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type bigint to datetime2)~~ +~~ERROR (Message: Explicit conversion from data type bigint to datetime2 is not allowed.)~~ SELECT CONVERT(DATETIME2, CAST(-2.5 as SMALLINT)) GO +~~START~~ +datetime2 ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type smallint to datetime2)~~ +~~ERROR (Message: Explicit conversion from data type smallint to datetime2 is not allowed.)~~ SELECT CONVERT(DATETIME2, CAST(-2.5 as MONEY)) GO +~~START~~ +datetime2 ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type money to datetime2)~~ +~~ERROR (Message: Explicit conversion from data type money to datetime2 is not allowed.)~~ SELECT CONVERT(DATETIME2, CAST(-2.5 as SMALLMONEY)) GO +~~START~~ +datetime2 ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type smallmoney to datetime2)~~ +~~ERROR (Message: Explicit conversion from data type smallmoney to datetime2 is not allowed.)~~ -- Should all fail @@ -172,89 +182,91 @@ SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as DECIMAL)) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type "decimal" to datetimeoffset)~~ +~~ERROR (Message: Explicit conversion from data type "decimal" to datetimeoffset is not allowed.)~~ SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as NUMERIC(30,8))) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type numeric to datetimeoffset)~~ +~~ERROR (Message: Explicit conversion from data type numeric to datetimeoffset is not allowed.)~~ SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as FLOAT)) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type double precision to datetimeoffset)~~ +~~ERROR (Message: Explicit conversion from data type double precision to datetimeoffset is not allowed.)~~ SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as REAL)) GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type real to datetimeoffset)~~ +~~ERROR (Message: Explicit conversion from data type real to datetimeoffset is not allowed.)~~ SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as INT)) GO +~~START~~ +datetimeoffset ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type integer to datetimeoffset)~~ +~~ERROR (Message: Explicit conversion from data type integer to datetimeoffset is not allowed.)~~ SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as BIGINT)) GO +~~START~~ +datetimeoffset ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type bigint to datetimeoffset)~~ +~~ERROR (Message: Explicit conversion from data type bigint to datetimeoffset is not allowed.)~~ SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as SMALLINT)) GO +~~START~~ +datetimeoffset ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type smallint to datetimeoffset)~~ +~~ERROR (Message: Explicit conversion from data type smallint to datetimeoffset is not allowed.)~~ SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as MONEY)) GO +~~START~~ +datetimeoffset ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type money to datetimeoffset)~~ +~~ERROR (Message: Explicit conversion from data type money to datetimeoffset is not allowed.)~~ SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as SMALLMONEY)) GO +~~START~~ +datetimeoffset ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type smallmoney to datetimeoffset)~~ +~~ERROR (Message: Explicit conversion from data type smallmoney to datetimeoffset is not allowed.)~~ -- Should all fail SELECT CONVERT(DATE, CAST(-2.5 as DECIMAL)) GO -~~START~~ -date ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type "decimal" to date)~~ +~~ERROR (Message: Explicit conversion from data type "decimal" to date is not allowed.)~~ SELECT CONVERT(DATE, CAST(-2.5 as NUMERIC(30,8))) GO -~~START~~ -date ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type numeric to date)~~ +~~ERROR (Message: Explicit conversion from data type numeric to date is not allowed.)~~ SELECT CONVERT(DATE, CAST(-2.5 as FLOAT)) GO -~~START~~ -date ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type double precision to date)~~ +~~ERROR (Message: Explicit conversion from data type double precision to date is not allowed.)~~ SELECT CONVERT(DATE, CAST(-2.5 as REAL)) GO -~~START~~ -date ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type real to date)~~ +~~ERROR (Message: Explicit conversion from data type real to date is not allowed.)~~ SELECT CONVERT(DATE, CAST(-2.5 as INT)) GO @@ -262,7 +274,7 @@ GO date ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type integer to date)~~ +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ SELECT CONVERT(DATE, CAST(-2.5 as BIGINT)) GO @@ -270,7 +282,7 @@ GO date ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type bigint to date)~~ +~~ERROR (Message: Explicit conversion from data type bigint to date is not allowed.)~~ SELECT CONVERT(DATE, CAST(-2.5 as SMALLINT)) GO @@ -278,7 +290,7 @@ GO date ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type smallint to date)~~ +~~ERROR (Message: Explicit conversion from data type smallint to date is not allowed.)~~ SELECT CONVERT(DATE, CAST(-2.5 as MONEY)) GO @@ -286,7 +298,7 @@ GO date ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type money to date)~~ +~~ERROR (Message: Explicit conversion from data type money to date is not allowed.)~~ SELECT CONVERT(DATE, CAST(-2.5 as SMALLMONEY)) GO @@ -294,41 +306,33 @@ GO date ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type smallmoney to date)~~ +~~ERROR (Message: Explicit conversion from data type smallmoney to date is not allowed.)~~ -- Should all fail SELECT CONVERT(TIME, CAST(-2.5 as DECIMAL)) GO -~~START~~ -time ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type "decimal" to time without time zone)~~ +~~ERROR (Message: Explicit conversion from data type "decimal" to time is not allowed.)~~ SELECT CONVERT(TIME, CAST(-2.5 as NUMERIC(30,8))) GO -~~START~~ -time ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type numeric to time without time zone)~~ +~~ERROR (Message: Explicit conversion from data type numeric to time is not allowed.)~~ SELECT CONVERT(TIME, CAST(-2.5 as FLOAT)) GO -~~START~~ -time ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type double precision to time without time zone)~~ +~~ERROR (Message: Explicit conversion from data type double precision to time is not allowed.)~~ SELECT CONVERT(TIME, CAST(-2.5 as REAL)) GO -~~START~~ -time ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type real to time without time zone)~~ +~~ERROR (Message: Explicit conversion from data type real to time is not allowed.)~~ SELECT CONVERT(TIME, CAST(-2.5 as INT)) GO @@ -336,7 +340,7 @@ GO time ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type integer to time without time zone)~~ +~~ERROR (Message: Explicit conversion from data type integer to time is not allowed.)~~ SELECT CONVERT(TIME, CAST(-2.5 as BIGINT)) GO @@ -344,7 +348,7 @@ GO time ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type bigint to time without time zone)~~ +~~ERROR (Message: Explicit conversion from data type bigint to time is not allowed.)~~ SELECT CONVERT(TIME, CAST(-2.5 as SMALLINT)) GO @@ -352,7 +356,7 @@ GO time ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type smallint to time without time zone)~~ +~~ERROR (Message: Explicit conversion from data type smallint to time is not allowed.)~~ SELECT CONVERT(TIME, CAST(-2.5 as MONEY)) GO @@ -360,7 +364,7 @@ GO time ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type money to time without time zone)~~ +~~ERROR (Message: Explicit conversion from data type money to time is not allowed.)~~ SELECT CONVERT(TIME, CAST(-2.5 as SMALLMONEY)) GO @@ -368,7 +372,7 @@ GO time ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: cannot cast type smallmoney to time without time zone)~~ +~~ERROR (Message: Explicit conversion from data type smallmoney to time is not allowed.)~~ CREATE VIEW Datetime_view5 as ( diff --git a/test/JDBC/expected/TestDatetime-vu-verify.out b/test/JDBC/expected/TestDatetime-vu-verify.out index a54b90e89e..a0af15b583 100644 --- a/test/JDBC/expected/TestDatetime-vu-verify.out +++ b/test/JDBC/expected/TestDatetime-vu-verify.out @@ -250,25 +250,19 @@ datetime ~~END~~ select convert(datetime, '9999-12-31 23:59:59.999'); -~~START~~ -datetime -~~ERROR (Code: 517)~~ +~~ERROR (Code: 33557097)~~ -~~ERROR (Message: data out of range for datetime)~~ +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ select convert(datetime, '1752-12-31 23:59:59.997'); -~~START~~ -datetime ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: The conversion of a VARCHAR data type to a DATETIME data type resulted in an out-of-range value.)~~ +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ select convert(datetime, '0000-00-00 00:00:00.000'); -~~START~~ -datetime ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: The conversion of a VARCHAR data type to a DATETIME data type resulted in an out-of-range value.)~~ +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ select convert(datetime, NULL); ~~START~~ diff --git a/test/JDBC/expected/TestDatetime.out b/test/JDBC/expected/TestDatetime.out index 0c213d5928..e733468be8 100644 --- a/test/JDBC/expected/TestDatetime.out +++ b/test/JDBC/expected/TestDatetime.out @@ -369,25 +369,19 @@ datetime ~~END~~ select convert(datetime, '9999-12-31 23:59:59.999'); -~~START~~ -datetime -~~ERROR (Code: 517)~~ +~~ERROR (Code: 33557097)~~ -~~ERROR (Message: data out of range for datetime)~~ +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ select convert(datetime, '1752-12-31 23:59:59.997'); -~~START~~ -datetime ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: The conversion of a VARCHAR data type to a DATETIME data type resulted in an out-of-range value.)~~ +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ select convert(datetime, '0000-00-00 00:00:00.000'); -~~START~~ -datetime ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: The conversion of a VARCHAR data type to a DATETIME data type resulted in an out-of-range value.)~~ +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ select convert(datetime, NULL); ~~START~~ diff --git a/test/JDBC/expected/babel_function.out b/test/JDBC/expected/babel_function.out index 7fc4b20e46..324f7e0d11 100644 --- a/test/JDBC/expected/babel_function.out +++ b/test/JDBC/expected/babel_function.out @@ -318,17 +318,15 @@ varchar -- Wrong conversions that return NULL select TRY_CONVERT(date, 123); GO -~~START~~ -date - -~~END~~ +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ select TRY_CONVERT(time, 123); GO -~~START~~ -time - -~~END~~ +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to time is not allowed.)~~ select TRY_CONVERT(datetime, 123); GO diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_function.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_function.out index 31870b6ade..d093dfe53a 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_function.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_function.out @@ -318,17 +318,15 @@ varchar -- Wrong conversions that return NULL select TRY_CONVERT(date, 123); GO -~~START~~ -date - -~~END~~ +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ select TRY_CONVERT(time, 123); GO -~~START~~ -time - -~~END~~ +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to time is not allowed.)~~ select TRY_CONVERT(datetime, 123); GO diff --git a/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-cleanup.out new file mode 100644 index 0000000000..886da40797 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-cleanup.out @@ -0,0 +1,71 @@ +DROP VIEW test_conv_string_to_date_v1 +GO +DROP PROCEDURE test_conv_string_to_date_p1 +GO +DROP FUNCTION test_conv_string_to_date_f1() +GO + +DROP VIEW test_conv_string_to_date_v2 +GO +DROP PROCEDURE test_conv_string_to_date_p2 +GO +DROP FUNCTION test_conv_string_to_date_f2() +GO + +DROP VIEW test_conv_string_to_date_v3 +GO +DROP PROCEDURE test_conv_string_to_date_p3 +GO +DROP FUNCTION test_conv_string_to_date_f3() +GO + +DROP VIEW test_conv_string_to_date_v4 +GO +DROP PROCEDURE test_conv_string_to_date_p4 +GO +DROP FUNCTION test_conv_string_to_date_f4() +GO + +DROP VIEW test_conv_string_to_date_v5 +GO +DROP PROCEDURE test_conv_string_to_date_p5 +GO +DROP FUNCTION test_conv_string_to_date_f5() +GO + +DROP VIEW test_conv_string_to_date_v6 +GO +DROP PROCEDURE test_conv_string_to_date_p6 +GO +DROP FUNCTION test_conv_string_to_date_f6() +GO + +DROP VIEW test_conv_string_to_date_v7 +GO +DROP PROCEDURE test_conv_string_to_date_p7 +GO +DROP FUNCTION test_conv_string_to_date_f7() +GO + +DROP VIEW test_conv_string_to_date_v8 +GO +DROP PROCEDURE test_conv_string_to_date_p8 +GO +DROP FUNCTION test_conv_string_to_date_f8() +GO + +DROP VIEW test_conv_string_to_date_v9 +GO +DROP PROCEDURE test_conv_string_to_date_p9 +GO +DROP FUNCTION test_conv_string_to_date_f9() +GO + +DROP VIEW test_conv_string_to_date_v10 +GO + +DROP VIEW test_conv_string_to_date_v11 +GO + +DROP VIEW test_conv_string_to_date_v12 +GO diff --git a/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-prepare.out new file mode 100644 index 0000000000..b6ba0b7f72 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-prepare.out @@ -0,0 +1,107 @@ +CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f1() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '2017-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f2() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '9999-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_date_f3() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE FUNCTION test_conv_string_to_date_f4() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f5() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f6() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f7() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_date_f8() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f9() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +GO + +CREATE VIEW test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); +GO + +CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +GO diff --git a/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out new file mode 100644 index 0000000000..71d20a06c1 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out @@ -0,0 +1,3741 @@ +-- Only DATE string +-- Empty string, should return default values +SELECT CONVERT(DATE, '') +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '', 130) +GO +~~START~~ +date +2464-12-29 +~~END~~ + + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATE, '3-2-4') +GO +~~START~~ +date +2004-03-02 +~~END~~ + + +SELECT CONVERT(DATE, '3-12-4') +GO +~~START~~ +date +2004-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3-12-24') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3-12-2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '11-12-2024') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '3 - 12 - 2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3.2.4') +GO +~~START~~ +date +2004-03-02 +~~END~~ + + +SELECT CONVERT(DATE, '3.12.4') +GO +~~START~~ +date +2004-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3.12.24') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3.12.2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '11.12.2024') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '3 . 12 . 2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3/2/4') +GO +~~START~~ +date +2004-03-02 +~~END~~ + + +SELECT CONVERT(DATE, '3/12/4') +GO +~~START~~ +date +2004-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3/12/24') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3/12/2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '11/12/2024') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '3 / 12 / 2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATE, '3-4-2') +GO +~~START~~ +date +2002-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3-4-12') +GO +~~START~~ +date +2012-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3-24-12') +GO +~~START~~ +date +2012-03-24 +~~END~~ + + +SELECT CONVERT(DATE, '3-2024-12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11-2024-12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3 - 2024 - 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3.4.2') +GO +~~START~~ +date +2002-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3.4.12') +GO +~~START~~ +date +2012-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3.24.12') +GO +~~START~~ +date +2012-03-24 +~~END~~ + + +SELECT CONVERT(DATE, '3.2024.12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11.2024.12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3 . 2024 . 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3/4/2') +GO +~~START~~ +date +2002-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3/4/12') +GO +~~START~~ +date +2012-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3/24/12') +GO +~~START~~ +date +2012-03-24 +~~END~~ + + +SELECT CONVERT(DATE, '3/2024/12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11/2024/12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3 / 2024 / 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-3-4') +GO +~~START~~ +date +2004-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-3-24') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-3-2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-11-2024') +GO +~~START~~ +date +2024-12-11 +~~END~~ + + +SELECT CONVERT(DATE, '12 - 3 - 2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '2.3.4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.3.4') +GO +~~START~~ +date +2004-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.3.24') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.3.2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.11.2024') +GO +~~START~~ +date +2024-12-11 +~~END~~ + + +SELECT CONVERT(DATE, '12 . 3 . 2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '2/3/4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/3/4') +GO +~~START~~ +date +2004-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/3/24') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/3/2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/11/2024') +GO +~~START~~ +date +2024-12-11 +~~END~~ + + +SELECT CONVERT(DATE, '12 / 3 / 2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATE, '2-4-3') +GO +~~START~~ +date +2003-02-04 +~~END~~ + + +SELECT CONVERT(DATE, '12-4-3') +GO +~~START~~ +date +2003-12-04 +~~END~~ + + +SELECT CONVERT(DATE, '12-24-3') +GO +~~START~~ +date +2003-12-24 +~~END~~ + + +SELECT CONVERT(DATE, '12-2024-3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12-2024-11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 - 2024 - 3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2.4.3') +GO +~~START~~ +date +2003-02-04 +~~END~~ + + +SELECT CONVERT(DATE, '12.4.3') +GO +~~START~~ +date +2003-12-04 +~~END~~ + + +SELECT CONVERT(DATE, '12.24.3') +GO +~~START~~ +date +2003-12-24 +~~END~~ + + +SELECT CONVERT(DATE, '12.2024.3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12.2024.11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 . 2024 . 3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2/4/3') +GO +~~START~~ +date +2003-02-04 +~~END~~ + + +SELECT CONVERT(DATE, '12/4/3') +GO +~~START~~ +date +2003-12-04 +~~END~~ + + +SELECT CONVERT(DATE, '12/24/3') +GO +~~START~~ +date +2003-12-24 +~~END~~ + + +SELECT CONVERT(DATE, '12/2024/3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12/2024/11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 / 2024 / 3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATE, '4-3-2') +GO +~~START~~ +date +2002-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '4-3-12') +GO +~~START~~ +date +2012-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '24-3-12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2024-3-12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024-11-12') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 - 3 - 12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '4.3.2') +GO +~~START~~ +date +2002-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '4.3.12') +GO +~~START~~ +date +2012-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '24.3.12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2024.3.12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024.11.12') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 . 3 . 12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '4/3/2') +GO +~~START~~ +date +2002-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '4/3/12') +GO +~~START~~ +date +2012-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '24/3/12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2024/3/12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024/11/12') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 / 3 / 12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(DATE, '3 12 2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3#12#2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3/12.2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- cut off year +SELECT CONVERT(DATE, '11-12-49') +GO +~~START~~ +date +2049-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '11-12-50') +GO +~~START~~ +date +1950-11-12 +~~END~~ + + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '03-22-2024') +GO +~~START~~ +date +2024-03-22 +~~END~~ + + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '22-03-2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '2024-03-22') +GO +~~START~~ +date +2024-03-22 +~~END~~ + + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '03-2024-22') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '22-2024-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATE, Hence following query should throw error +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATE, '2024-22-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- -- Boundary values +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999') +GO +~~START~~ +date +9999-12-30 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.99999999') +GO +~~START~~ +date +9999-12-30 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.999999999') +GO +~~START~~ +date +9999-12-30 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999') +GO +~~START~~ +date +9999-12-31 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.99999999') +GO +~~START~~ +date +9999-12-31 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.999999999') +GO +~~START~~ +date +9999-12-31 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE,'2022-10-00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'0000-10-01') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'2023-00-01') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'0000-00-00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'1752-01-01') +GO +~~START~~ +date +1752-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'1753-01-01') +GO +~~START~~ +date +1753-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'1899-01-01') +GO +~~START~~ +date +1899-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'1900-01-01') +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'2079-06-06') +GO +~~START~~ +date +2079-06-06 +~~END~~ + + +SELECT CONVERT(DATE,'2079-06-07') +GO +~~START~~ +date +2079-06-07 +~~END~~ + + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATE, 'Apr 12,2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1 2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12,2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12 2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1 2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATE, 'Apr 12, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr 1, 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1, 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr 1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr12, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr1, 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1, 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم 12', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم 1, 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1, 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم 1', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم12, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم12', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم1, 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1, 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم1', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- mon yyyy [dd] +SELECT CONVERT(DATE, 'Apr 2024 22') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2024 2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024 22') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024 2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 2024 22', 130) +GO +~~START~~ +date +2585-05-12 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2024 2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024 22', 130) +GO +~~START~~ +date +2585-05-12 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024 2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATE, '24 Apr, 2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '24 Apr 2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '4 Apr, 2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, '4 Apr 2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr, 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '24Apr, 2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '24Apr2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '4Apr, 2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, '4Apr2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr, 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATE, N'24 محرم, 2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'24 محرم 2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'4 محرم, 2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'4 محرم 2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'24محرم, 2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'24محرم2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'4محرم, 2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'4محرم2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- dd mon[,][yy]yy +SELECT CONVERT(DATE, '12 Apr, 2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 Apr') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12Apr, 2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12Apr') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATE, N'12 محرم, 2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم 2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'12 محرم', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'12محرم, 2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'12محرم', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- dd [yy]yy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 24 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 2024Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 24Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 24 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 24محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +--- [dd] yyyy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2 2024 Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '12 2024Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2 2024Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2 2024 محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2 2024محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- yyyy mon [dd] +SELECT CONVERT(DATE, '2024 Apr 12') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr 2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr12') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 محرم 12', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم 2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم12', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- yyyy [dd] mon +SELECT CONVERT(DATE, '2024 12 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 2 Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '2024 12Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 2Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 12 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 2 محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 12محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 2محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +-- ISO 8601 +SELECT CONVERT(DATE, '2023-11-27') +GO +~~START~~ +date +2023-11-27 +~~END~~ + + +SELECT CONVERT(DATE, '2023-2-29') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-1-22T13:34:12.123') +GO +~~START~~ +date +2022-01-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-2T13:34:12.123') +GO +~~START~~ +date +2022-10-02 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T3:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:4:12.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:1.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345678') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456789') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567891') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.15') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123-11:11') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123Z') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATE, '2022-10-22T13 :34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10 -22T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22 T 13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 -11:11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- -- rounding +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999995') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999994') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +-- DATE with typmod +SELECT CONVERT(DATE(1), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: type modifier is not allowed for type "date")~~ + + +SELECT CONVERT(DATE(2), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: type modifier is not allowed for type "date")~~ + + +SELECT CONVERT(DATE(3), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: type modifier is not allowed for type "date")~~ + + +-- Unseparated +SELECT CONVERT(DATE, '20240129') +GO +~~START~~ +date +2024-01-29 +~~END~~ + + +SELECT CONVERT(DATE, '20790606') +GO +~~START~~ +date +2079-06-06 +~~END~~ + + +SELECT CONVERT(DATE, '20790607') +GO +~~START~~ +date +2079-06-07 +~~END~~ + + +SELECT CONVERT(DATE, '240129') +GO +~~START~~ +date +2024-01-29 +~~END~~ + + +SELECT CONVERT(DATE, '241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2001') +GO +~~START~~ +date +2001-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '0001') +GO +~~START~~ +date +0001-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '1753') +GO +~~START~~ +date +1753-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '1900') +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +-- for styles 130 and 131, the DATE ranges (for example, number of days in a month) are different compared to other styles +SELECT CONVERT(DATE, '20231229', 130) +GO +~~START~~ +date +2585-04-19 +~~END~~ + + +SELECT CONVERT(DATE, '20231230', 130) +GO +~~START~~ +date +2585-04-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231129', 130) +GO +~~START~~ +date +2585-03-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231130', 130) +GO +~~START~~ +date +2585-03-21 +~~END~~ + + +SELECT CONVERT(DATE, '20231229', 131) +GO +~~START~~ +date +2585-04-19 +~~END~~ + + +SELECT CONVERT(DATE, '20231230', 131) +GO +~~START~~ +date +2585-04-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231129', 131) +GO +~~START~~ +date +2585-03-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231130', 131) +GO +~~START~~ +date +2585-03-21 +~~END~~ + + +-- -- hijri leap year only contains 29 days in 12th month (for style 130 and 131) +SELECT CONVERT(DATE, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '20241230', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '20241229', 130) +GO +~~START~~ +date +2586-04-09 +~~END~~ + + +SELECT CONVERT(DATE, '20241229', 131) +GO +~~START~~ +date +2586-04-09 +~~END~~ + + +-- -- invalid syntax +SELECT CONVERT(DATE, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- W3C XML format +SELECT CONVERT(DATE, '2024-04-22-05:12') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22+05:12') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22-14:00') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22+14:00') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22-14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2024-04-22+14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2024-04-22Z') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '24-04-22Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2024-4-22Z') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-2Z') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +-- hijri +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +date +2018-10-02 +~~END~~ + + +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +date +2018-10-02 +~~END~~ + + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +date +2019-08-23 +~~END~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +date +2021-04-10 +~~END~~ + + +SELECT CONVERT(DATE, '02/12/21', 1) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '21.02.12', 2) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12/02/21', 3) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12.02.21', 4) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12-02-21', 5) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 21', 6) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12, 21', 7) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '10:13:14', 8) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '10:13:14', 24) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '02-12-21', 10) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '21/02/12', 11) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '210212', 12) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '15:13:14:123', 14) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 20) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '02/12/21 15:13:14 PM', 22) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12', 23) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 25) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +date +2021-04-10 +~~END~~ + + +SELECT CONVERT(DATE, '02/12/2021', 101) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021.02.12', 102) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12/02/2021', 103) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12.02.2021', 104) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12-02-2021', 105) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2021', 106) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12, 2021', 107) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '10:13:14', 108) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '02-12-2021', 110) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021/02/12', 111) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '20210212', 112) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '15:13:14:123', 114) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 120) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +date +2018-10-02 +~~END~~ + + +SELECT CONVERT(DATE, N'22 April 1440 1:39:17.090', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +date +2582-07-04 +~~END~~ + + +-- -- misc +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO +~~START~~ +date +2022-10-29 +~~END~~ + + +SELECT CONVERT(DATE, '2020') +GO +~~START~~ +date +2020-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(DATE, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(DATE, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '1900-05-06 13:59:29.050 -8:00') +GO +~~START~~ +date +1900-05-06 +~~END~~ + + +SELECT CONVERT(DATE, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO +~~START~~ +date +2022-10-29 +~~END~~ + + +SELECT CONVERT(DATE, '2020') +GO +~~START~~ +date +2020-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-30T03:00:00') +GO +~~START~~ +date +2022-10-30 +~~END~~ + + +SELECT CONVERT(DATE, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +date +2021-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATE, @TM_ICLO) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type time without time zone to date is not allowed.)~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_date_v1 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p1 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f1() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v2 +GO +~~START~~ +date +9999-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p2 +GO +~~START~~ +date +9999-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f2() +GO +~~START~~ +date +9999-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v3 +GO +~~START~~ +date +1900-01-01 +~~END~~ + +EXEC test_conv_string_to_date_p3 +GO +~~START~~ +date +1900-01-01 +~~END~~ + +SELECT test_conv_string_to_date_f3() +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v4 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p4 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f4() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v5 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p5 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f5() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v6 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p6 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f6() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v7 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p7 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f7() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + +EXEC test_conv_string_to_date_p8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + +SELECT test_conv_string_to_date_f8() +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + + +SELECT * FROM test_conv_string_to_date_v9 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p9 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f9() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v10 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT * FROM test_conv_string_to_date_v11 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT * FROM test_conv_string_to_date_v12 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + diff --git a/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-cleanup.out new file mode 100644 index 0000000000..9b75accd45 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-cleanup.out @@ -0,0 +1,68 @@ +DROP VIEW test_conv_string_to_date_v1 +GO +DROP PROCEDURE test_conv_string_to_date_p1 +GO +DROP FUNCTION test_conv_string_to_date_f1() +GO + +DROP VIEW test_conv_string_to_date_v2 +GO +DROP PROCEDURE test_conv_string_to_date_p2 +GO +DROP FUNCTION test_conv_string_to_date_f2() +GO + +DROP VIEW test_conv_string_to_date_v3 +GO +DROP PROCEDURE test_conv_string_to_date_p3 +GO +DROP FUNCTION test_conv_string_to_date_f3() +GO + +DROP VIEW test_conv_string_to_date_v4 +GO +DROP PROCEDURE test_conv_string_to_date_p4 +GO +DROP FUNCTION test_conv_string_to_date_f4() +GO + +DROP VIEW test_conv_string_to_date_v5 +GO +DROP PROCEDURE test_conv_string_to_date_p5 +GO +DROP FUNCTION test_conv_string_to_date_f5() +GO + +DROP VIEW test_conv_string_to_date_v6 +GO +DROP PROCEDURE test_conv_string_to_date_p6 +GO +DROP FUNCTION test_conv_string_to_date_f6() +GO + +DROP VIEW test_conv_string_to_date_v7 +GO +DROP PROCEDURE test_conv_string_to_date_p7 +GO +DROP FUNCTION test_conv_string_to_date_f7() +GO + +DROP VIEW test_conv_string_to_date_v8 +GO +DROP PROCEDURE test_conv_string_to_date_p8 +GO +DROP FUNCTION test_conv_string_to_date_f8() +GO + +DROP VIEW test_conv_string_to_date_v9 +GO +DROP PROCEDURE test_conv_string_to_date_p9 +GO +DROP FUNCTION test_conv_string_to_date_f9() +GO + +DROP VIEW test_conv_string_to_date_v10 +GO + +DROP VIEW test_conv_string_to_date_v12 +GO diff --git a/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-prepare.out new file mode 100644 index 0000000000..fa4fbdf743 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-prepare.out @@ -0,0 +1,104 @@ +CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f1() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '2017-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f2() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '9999-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_date_f3() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE FUNCTION test_conv_string_to_date_f4() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f5() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f6() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f7() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_date_f8() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f9() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +GO + +CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +GO diff --git a/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out new file mode 100644 index 0000000000..96501e2f62 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out @@ -0,0 +1,3734 @@ +-- Only DATE string +-- Empty string, should return default values +SELECT CONVERT(DATE, '') +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '', 130) +GO +~~START~~ +date +2464-12-29 +~~END~~ + + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATE, '3-2-4') +GO +~~START~~ +date +2004-03-02 +~~END~~ + + +SELECT CONVERT(DATE, '3-12-4') +GO +~~START~~ +date +2004-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3-12-24') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3-12-2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '11-12-2024') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '3 - 12 - 2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3.2.4') +GO +~~START~~ +date +2004-03-02 +~~END~~ + + +SELECT CONVERT(DATE, '3.12.4') +GO +~~START~~ +date +2004-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3.12.24') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3.12.2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '11.12.2024') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '3 . 12 . 2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3/2/4') +GO +~~START~~ +date +2004-03-02 +~~END~~ + + +SELECT CONVERT(DATE, '3/12/4') +GO +~~START~~ +date +2004-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3/12/24') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3/12/2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '11/12/2024') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '3 / 12 / 2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATE, '3-4-2') +GO +~~START~~ +date +2002-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3-4-12') +GO +~~START~~ +date +2012-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3-24-12') +GO +~~START~~ +date +2012-03-24 +~~END~~ + + +SELECT CONVERT(DATE, '3-2024-12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11-2024-12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3 - 2024 - 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3.4.2') +GO +~~START~~ +date +2002-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3.4.12') +GO +~~START~~ +date +2012-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3.24.12') +GO +~~START~~ +date +2012-03-24 +~~END~~ + + +SELECT CONVERT(DATE, '3.2024.12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11.2024.12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3 . 2024 . 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3/4/2') +GO +~~START~~ +date +2002-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3/4/12') +GO +~~START~~ +date +2012-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3/24/12') +GO +~~START~~ +date +2012-03-24 +~~END~~ + + +SELECT CONVERT(DATE, '3/2024/12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11/2024/12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3 / 2024 / 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-3-4') +GO +~~START~~ +date +2004-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-3-24') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-3-2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-11-2024') +GO +~~START~~ +date +2024-12-11 +~~END~~ + + +SELECT CONVERT(DATE, '12 - 3 - 2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '2.3.4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.3.4') +GO +~~START~~ +date +2004-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.3.24') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.3.2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.11.2024') +GO +~~START~~ +date +2024-12-11 +~~END~~ + + +SELECT CONVERT(DATE, '12 . 3 . 2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '2/3/4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/3/4') +GO +~~START~~ +date +2004-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/3/24') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/3/2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/11/2024') +GO +~~START~~ +date +2024-12-11 +~~END~~ + + +SELECT CONVERT(DATE, '12 / 3 / 2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATE, '2-4-3') +GO +~~START~~ +date +2003-02-04 +~~END~~ + + +SELECT CONVERT(DATE, '12-4-3') +GO +~~START~~ +date +2003-12-04 +~~END~~ + + +SELECT CONVERT(DATE, '12-24-3') +GO +~~START~~ +date +2003-12-24 +~~END~~ + + +SELECT CONVERT(DATE, '12-2024-3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12-2024-11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 - 2024 - 3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2.4.3') +GO +~~START~~ +date +2003-02-04 +~~END~~ + + +SELECT CONVERT(DATE, '12.4.3') +GO +~~START~~ +date +2003-12-04 +~~END~~ + + +SELECT CONVERT(DATE, '12.24.3') +GO +~~START~~ +date +2003-12-24 +~~END~~ + + +SELECT CONVERT(DATE, '12.2024.3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12.2024.11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 . 2024 . 3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2/4/3') +GO +~~START~~ +date +2003-02-04 +~~END~~ + + +SELECT CONVERT(DATE, '12/4/3') +GO +~~START~~ +date +2003-12-04 +~~END~~ + + +SELECT CONVERT(DATE, '12/24/3') +GO +~~START~~ +date +2003-12-24 +~~END~~ + + +SELECT CONVERT(DATE, '12/2024/3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12/2024/11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 / 2024 / 3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATE, '4-3-2') +GO +~~START~~ +date +2002-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '4-3-12') +GO +~~START~~ +date +2012-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '24-3-12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2024-3-12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024-11-12') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 - 3 - 12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '4.3.2') +GO +~~START~~ +date +2002-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '4.3.12') +GO +~~START~~ +date +2012-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '24.3.12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2024.3.12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024.11.12') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 . 3 . 12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '4/3/2') +GO +~~START~~ +date +2002-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '4/3/12') +GO +~~START~~ +date +2012-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '24/3/12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2024/3/12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024/11/12') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 / 3 / 12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(DATE, '3 12 2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3#12#2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3/12.2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- cut off year +SELECT CONVERT(DATE, '11-12-49') +GO +~~START~~ +date +2049-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '11-12-50') +GO +~~START~~ +date +1950-11-12 +~~END~~ + + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '03-22-2024') +GO +~~START~~ +date +2024-03-22 +~~END~~ + + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '22-03-2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '2024-03-22') +GO +~~START~~ +date +2024-03-22 +~~END~~ + + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '03-2024-22') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '22-2024-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATE, Hence following query should throw error +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATE, '2024-22-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- -- Boundary values +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999') +GO +~~START~~ +date +9999-12-30 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.99999999') +GO +~~START~~ +date +9999-12-30 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.999999999') +GO +~~START~~ +date +9999-12-30 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999') +GO +~~START~~ +date +9999-12-31 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.99999999') +GO +~~START~~ +date +9999-12-31 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.999999999') +GO +~~START~~ +date +9999-12-31 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE,'2022-10-00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'0000-10-01') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'2023-00-01') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'0000-00-00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'1752-01-01') +GO +~~START~~ +date +1752-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'1753-01-01') +GO +~~START~~ +date +1753-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'1899-01-01') +GO +~~START~~ +date +1899-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'1900-01-01') +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'2079-06-06') +GO +~~START~~ +date +2079-06-06 +~~END~~ + + +SELECT CONVERT(DATE,'2079-06-07') +GO +~~START~~ +date +2079-06-07 +~~END~~ + + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATE, 'Apr 12,2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1 2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12,2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12 2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1 2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATE, 'Apr 12, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr 1, 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1, 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr 1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr12, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr1, 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1, 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم 12', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم 1, 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1, 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم 1', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم12, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم12', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم1, 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1, 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم1', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- mon yyyy [dd] +SELECT CONVERT(DATE, 'Apr 2024 22') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2024 2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024 22') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024 2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 2024 22', 130) +GO +~~START~~ +date +2585-05-12 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2024 2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024 22', 130) +GO +~~START~~ +date +2585-05-12 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024 2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATE, '24 Apr, 2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '24 Apr 2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '4 Apr, 2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, '4 Apr 2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr, 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '24Apr, 2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '24Apr2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '4Apr, 2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, '4Apr2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr, 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATE, N'24 محرم, 2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'24 محرم 2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'4 محرم, 2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'4 محرم 2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'24محرم, 2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'24محرم2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'4محرم, 2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'4محرم2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- dd mon[,][yy]yy +SELECT CONVERT(DATE, '12 Apr, 2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 Apr') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12Apr, 2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12Apr') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATE, N'12 محرم, 2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم 2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'12 محرم', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'12محرم, 2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'12محرم', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- dd [yy]yy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 24 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 2024Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 24Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 24 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 24محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +--- [dd] yyyy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2 2024 Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '12 2024Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2 2024Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2 2024 محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2 2024محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- yyyy mon [dd] +SELECT CONVERT(DATE, '2024 Apr 12') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr 2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr12') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 محرم 12', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم 2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم12', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- yyyy [dd] mon +SELECT CONVERT(DATE, '2024 12 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 2 Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '2024 12Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 2Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 12 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 2 محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 12محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 2محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +-- ISO 8601 +SELECT CONVERT(DATE, '2023-11-27') +GO +~~START~~ +date +2023-11-27 +~~END~~ + + +SELECT CONVERT(DATE, '2023-2-29') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-1-22T13:34:12.123') +GO +~~START~~ +date +2022-01-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-2T13:34:12.123') +GO +~~START~~ +date +2022-10-02 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T3:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:4:12.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:1.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345678') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456789') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567891') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.15') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123-11:11') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123Z') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATE, '2022-10-22T13 :34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10 -22T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22 T 13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 -11:11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- -- rounding +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999995') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999994') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +-- DATE with typmod +SELECT CONVERT(DATE(1), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: type modifier is not allowed for type "date")~~ + + +SELECT CONVERT(DATE(2), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: type modifier is not allowed for type "date")~~ + + +SELECT CONVERT(DATE(3), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: type modifier is not allowed for type "date")~~ + + +-- Unseparated +SELECT CONVERT(DATE, '20240129') +GO +~~START~~ +date +2024-01-29 +~~END~~ + + +SELECT CONVERT(DATE, '20790606') +GO +~~START~~ +date +2079-06-06 +~~END~~ + + +SELECT CONVERT(DATE, '20790607') +GO +~~START~~ +date +2079-06-07 +~~END~~ + + +SELECT CONVERT(DATE, '240129') +GO +~~START~~ +date +2024-01-29 +~~END~~ + + +SELECT CONVERT(DATE, '241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2001') +GO +~~START~~ +date +2001-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '0001') +GO +~~START~~ +date +0001-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '1753') +GO +~~START~~ +date +1753-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '1900') +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +-- for styles 130 and 131, the DATE ranges (for example, number of days in a month) are different compared to other styles +SELECT CONVERT(DATE, '20231229', 130) +GO +~~START~~ +date +2585-04-19 +~~END~~ + + +SELECT CONVERT(DATE, '20231230', 130) +GO +~~START~~ +date +2585-04-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231129', 130) +GO +~~START~~ +date +2585-03-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231130', 130) +GO +~~START~~ +date +2585-03-21 +~~END~~ + + +SELECT CONVERT(DATE, '20231229', 131) +GO +~~START~~ +date +2585-04-19 +~~END~~ + + +SELECT CONVERT(DATE, '20231230', 131) +GO +~~START~~ +date +2585-04-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231129', 131) +GO +~~START~~ +date +2585-03-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231130', 131) +GO +~~START~~ +date +2585-03-21 +~~END~~ + + +-- -- hijri leap year only contains 29 days in 12th month (for style 130 and 131) +SELECT CONVERT(DATE, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '20241230', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '20241229', 130) +GO +~~START~~ +date +2586-04-09 +~~END~~ + + +SELECT CONVERT(DATE, '20241229', 131) +GO +~~START~~ +date +2586-04-09 +~~END~~ + + +-- -- invalid syntax +SELECT CONVERT(DATE, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- W3C XML format +SELECT CONVERT(DATE, '2024-04-22-05:12') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22+05:12') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22-14:00') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22+14:00') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22-14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2024-04-22+14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2024-04-22Z') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '24-04-22Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2024-4-22Z') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-2Z') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +-- hijri +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +date +2018-10-02 +~~END~~ + + +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +date +2018-10-02 +~~END~~ + + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +date +2019-08-23 +~~END~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +date +2021-04-10 +~~END~~ + + +SELECT CONVERT(DATE, '02/12/21', 1) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '21.02.12', 2) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12/02/21', 3) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12.02.21', 4) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12-02-21', 5) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 21', 6) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12, 21', 7) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '10:13:14', 8) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '10:13:14', 24) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '02-12-21', 10) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '21/02/12', 11) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '210212', 12) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '15:13:14:123', 14) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 20) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '02/12/21 15:13:14 PM', 22) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12', 23) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 25) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +date +2021-04-10 +~~END~~ + + +SELECT CONVERT(DATE, '02/12/2021', 101) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021.02.12', 102) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12/02/2021', 103) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12.02.2021', 104) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12-02-2021', 105) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2021', 106) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12, 2021', 107) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '10:13:14', 108) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '02-12-2021', 110) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021/02/12', 111) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '20210212', 112) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '15:13:14:123', 114) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 120) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +date +2018-10-02 +~~END~~ + + +SELECT CONVERT(DATE, N'22 April 1440 1:39:17.090', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +date +2582-07-04 +~~END~~ + + +-- -- misc +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO +~~START~~ +date +2022-10-29 +~~END~~ + + +SELECT CONVERT(DATE, '2020') +GO +~~START~~ +date +2020-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(DATE, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(DATE, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '1900-05-06 13:59:29.050 -8:00') +GO +~~START~~ +date +1900-05-06 +~~END~~ + + +SELECT CONVERT(DATE, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO +~~START~~ +date +2022-10-29 +~~END~~ + + +SELECT CONVERT(DATE, '2020') +GO +~~START~~ +date +2020-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-30T03:00:00') +GO +~~START~~ +date +2022-10-30 +~~END~~ + + +SELECT CONVERT(DATE, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +date +2021-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATE, @TM_ICLO) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type time without time zone to date is not allowed.)~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_date_v1 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p1 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f1() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v2 +GO +~~START~~ +date +9999-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p2 +GO +~~START~~ +date +9999-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f2() +GO +~~START~~ +date +9999-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v3 +GO +~~START~~ +date +1900-01-01 +~~END~~ + +EXEC test_conv_string_to_date_p3 +GO +~~START~~ +date +1900-01-01 +~~END~~ + +SELECT test_conv_string_to_date_f3() +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v4 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p4 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f4() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v5 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p5 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f5() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v6 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p6 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f6() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v7 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p7 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f7() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + +EXEC test_conv_string_to_date_p8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + +SELECT test_conv_string_to_date_f8() +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + + +SELECT * FROM test_conv_string_to_date_v9 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p9 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f9() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v10 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT * FROM test_conv_string_to_date_v12 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + diff --git a/test/JDBC/expected/test_conv_string_to_date-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_date-vu-cleanup.out new file mode 100644 index 0000000000..886da40797 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_date-vu-cleanup.out @@ -0,0 +1,71 @@ +DROP VIEW test_conv_string_to_date_v1 +GO +DROP PROCEDURE test_conv_string_to_date_p1 +GO +DROP FUNCTION test_conv_string_to_date_f1() +GO + +DROP VIEW test_conv_string_to_date_v2 +GO +DROP PROCEDURE test_conv_string_to_date_p2 +GO +DROP FUNCTION test_conv_string_to_date_f2() +GO + +DROP VIEW test_conv_string_to_date_v3 +GO +DROP PROCEDURE test_conv_string_to_date_p3 +GO +DROP FUNCTION test_conv_string_to_date_f3() +GO + +DROP VIEW test_conv_string_to_date_v4 +GO +DROP PROCEDURE test_conv_string_to_date_p4 +GO +DROP FUNCTION test_conv_string_to_date_f4() +GO + +DROP VIEW test_conv_string_to_date_v5 +GO +DROP PROCEDURE test_conv_string_to_date_p5 +GO +DROP FUNCTION test_conv_string_to_date_f5() +GO + +DROP VIEW test_conv_string_to_date_v6 +GO +DROP PROCEDURE test_conv_string_to_date_p6 +GO +DROP FUNCTION test_conv_string_to_date_f6() +GO + +DROP VIEW test_conv_string_to_date_v7 +GO +DROP PROCEDURE test_conv_string_to_date_p7 +GO +DROP FUNCTION test_conv_string_to_date_f7() +GO + +DROP VIEW test_conv_string_to_date_v8 +GO +DROP PROCEDURE test_conv_string_to_date_p8 +GO +DROP FUNCTION test_conv_string_to_date_f8() +GO + +DROP VIEW test_conv_string_to_date_v9 +GO +DROP PROCEDURE test_conv_string_to_date_p9 +GO +DROP FUNCTION test_conv_string_to_date_f9() +GO + +DROP VIEW test_conv_string_to_date_v10 +GO + +DROP VIEW test_conv_string_to_date_v11 +GO + +DROP VIEW test_conv_string_to_date_v12 +GO diff --git a/test/JDBC/expected/test_conv_string_to_date-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_date-vu-prepare.out new file mode 100644 index 0000000000..b6ba0b7f72 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_date-vu-prepare.out @@ -0,0 +1,107 @@ +CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f1() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '2017-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f2() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '9999-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_date_f3() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE FUNCTION test_conv_string_to_date_f4() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f5() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f6() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f7() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_date_f8() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f9() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +GO + +CREATE VIEW test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); +GO + +CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +GO diff --git a/test/JDBC/expected/test_conv_string_to_date-vu-verify.out b/test/JDBC/expected/test_conv_string_to_date-vu-verify.out new file mode 100644 index 0000000000..b9fa5eb983 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_date-vu-verify.out @@ -0,0 +1,3743 @@ +-- Only DATE string +-- Empty string, should return default values +SELECT CONVERT(DATE, '') +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '', 130) +GO +~~START~~ +date +2464-12-29 +~~END~~ + + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATE, '3-2-4') +GO +~~START~~ +date +2004-03-02 +~~END~~ + + +SELECT CONVERT(DATE, '3-12-4') +GO +~~START~~ +date +2004-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3-12-24') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3-12-2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '11-12-2024') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '3 - 12 - 2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3.2.4') +GO +~~START~~ +date +2004-03-02 +~~END~~ + + +SELECT CONVERT(DATE, '3.12.4') +GO +~~START~~ +date +2004-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3.12.24') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3.12.2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '11.12.2024') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '3 . 12 . 2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3/2/4') +GO +~~START~~ +date +2004-03-02 +~~END~~ + + +SELECT CONVERT(DATE, '3/12/4') +GO +~~START~~ +date +2004-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3/12/24') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '3/12/2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '11/12/2024') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '3 / 12 / 2024') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATE, '3-4-2') +GO +~~START~~ +date +2002-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3-4-12') +GO +~~START~~ +date +2012-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3-24-12') +GO +~~START~~ +date +2012-03-24 +~~END~~ + + +SELECT CONVERT(DATE, '3-2024-12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11-2024-12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3 - 2024 - 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3.4.2') +GO +~~START~~ +date +2002-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3.4.12') +GO +~~START~~ +date +2012-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3.24.12') +GO +~~START~~ +date +2012-03-24 +~~END~~ + + +SELECT CONVERT(DATE, '3.2024.12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11.2024.12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3 . 2024 . 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3/4/2') +GO +~~START~~ +date +2002-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3/4/12') +GO +~~START~~ +date +2012-03-04 +~~END~~ + + +SELECT CONVERT(DATE, '3/24/12') +GO +~~START~~ +date +2012-03-24 +~~END~~ + + +SELECT CONVERT(DATE, '3/2024/12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11/2024/12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3 / 2024 / 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-3-4') +GO +~~START~~ +date +2004-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-3-24') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-3-2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12-11-2024') +GO +~~START~~ +date +2024-12-11 +~~END~~ + + +SELECT CONVERT(DATE, '12 - 3 - 2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '2.3.4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.3.4') +GO +~~START~~ +date +2004-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.3.24') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.3.2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12.11.2024') +GO +~~START~~ +date +2024-12-11 +~~END~~ + + +SELECT CONVERT(DATE, '12 . 3 . 2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '2/3/4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/3/4') +GO +~~START~~ +date +2004-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/3/24') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/3/2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +SELECT CONVERT(DATE, '12/11/2024') +GO +~~START~~ +date +2024-12-11 +~~END~~ + + +SELECT CONVERT(DATE, '12 / 3 / 2024') +GO +~~START~~ +date +2024-12-03 +~~END~~ + + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATE, '2-4-3') +GO +~~START~~ +date +2003-02-04 +~~END~~ + + +SELECT CONVERT(DATE, '12-4-3') +GO +~~START~~ +date +2003-12-04 +~~END~~ + + +SELECT CONVERT(DATE, '12-24-3') +GO +~~START~~ +date +2003-12-24 +~~END~~ + + +SELECT CONVERT(DATE, '12-2024-3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12-2024-11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 - 2024 - 3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2.4.3') +GO +~~START~~ +date +2003-02-04 +~~END~~ + + +SELECT CONVERT(DATE, '12.4.3') +GO +~~START~~ +date +2003-12-04 +~~END~~ + + +SELECT CONVERT(DATE, '12.24.3') +GO +~~START~~ +date +2003-12-24 +~~END~~ + + +SELECT CONVERT(DATE, '12.2024.3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12.2024.11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 . 2024 . 3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2/4/3') +GO +~~START~~ +date +2003-02-04 +~~END~~ + + +SELECT CONVERT(DATE, '12/4/3') +GO +~~START~~ +date +2003-12-04 +~~END~~ + + +SELECT CONVERT(DATE, '12/24/3') +GO +~~START~~ +date +2003-12-24 +~~END~~ + + +SELECT CONVERT(DATE, '12/2024/3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12/2024/11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 / 2024 / 3') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATE, '4-3-2') +GO +~~START~~ +date +2002-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '4-3-12') +GO +~~START~~ +date +2012-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '24-3-12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2024-3-12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024-11-12') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 - 3 - 12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '4.3.2') +GO +~~START~~ +date +2002-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '4.3.12') +GO +~~START~~ +date +2012-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '24.3.12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2024.3.12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024.11.12') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 . 3 . 12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '4/3/2') +GO +~~START~~ +date +2002-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '4/3/12') +GO +~~START~~ +date +2012-04-03 +~~END~~ + + +SELECT CONVERT(DATE, '24/3/12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2024/3/12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024/11/12') +GO +~~START~~ +date +2024-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 / 3 / 12') +GO +~~START~~ +date +2024-03-12 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(DATE, '3 12 2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3#12#2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '3/12.2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- cut off year +SELECT CONVERT(DATE, '11-12-49') +GO +~~START~~ +date +2049-11-12 +~~END~~ + + +SELECT CONVERT(DATE, '11-12-50') +GO +~~START~~ +date +1950-11-12 +~~END~~ + + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '03-22-2024') +GO +~~START~~ +date +2024-03-22 +~~END~~ + + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '22-03-2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '2024-03-22') +GO +~~START~~ +date +2024-03-22 +~~END~~ + + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '03-2024-22') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +SELECT CONVERT(DATE, '22-2024-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATE, Hence following query should throw error +SELECT CONVERT(DATE, '2-3-4') +GO +~~START~~ +date +2004-02-03 +~~END~~ + + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATE, '2024-22-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- -- Boundary values +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999') +GO +~~START~~ +date +9999-12-30 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.99999999') +GO +~~START~~ +date +9999-12-30 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.999999999') +GO +~~START~~ +date +9999-12-30 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999') +GO +~~START~~ +date +9999-12-31 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.99999999') +GO +~~START~~ +date +9999-12-31 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.999999999') +GO +~~START~~ +date +9999-12-31 +~~END~~ + + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE,'2022-10-00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'0000-10-01') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'2023-00-01') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'0000-00-00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE,'1752-01-01') +GO +~~START~~ +date +1752-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'1753-01-01') +GO +~~START~~ +date +1753-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'1899-01-01') +GO +~~START~~ +date +1899-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'1900-01-01') +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE,'2079-06-06') +GO +~~START~~ +date +2079-06-06 +~~END~~ + + +SELECT CONVERT(DATE,'2079-06-07') +GO +~~START~~ +date +2079-06-07 +~~END~~ + + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATE, 'Apr 12,2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1 2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12,2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12 2000') +GO +~~START~~ +date +2000-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1 2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr,2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2000') +GO +~~START~~ +date +2000-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO +~~START~~ +date +2562-01-18 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO +~~START~~ +date +2562-01-07 +~~END~~ + + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATE, 'Apr 12, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr 12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr 1, 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1, 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 1,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr 1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr12, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr12,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr1, 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1 24') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1, 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1 4') +GO +~~START~~ +date +2004-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr1,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, 'Apr1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 12,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم 12', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم 1, 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1, 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 1,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم 1', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم12, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم12,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم12', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم1, 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1 24', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1, 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1 4', 130) +GO +~~START~~ +date +2565-11-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم1,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'محرم1', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- mon yyyy [dd] +SELECT CONVERT(DATE, 'Apr 2024 22') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2024 2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024 22') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024 2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 2024 22', 130) +GO +~~START~~ +date +2585-05-12 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2024 2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024 22', 130) +GO +~~START~~ +date +2585-05-12 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024 2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATE, '24 Apr, 2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '24 Apr 2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '4 Apr, 2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, '4 Apr 2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr, 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '24Apr, 2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '24Apr2024') +GO +~~START~~ +date +2024-04-24 +~~END~~ + + +SELECT CONVERT(DATE, '4Apr, 2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, '4Apr2024') +GO +~~START~~ +date +2024-04-04 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr, 2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr2024') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATE, N'24 محرم, 2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'24 محرم 2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'4 محرم, 2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'4 محرم 2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'24محرم, 2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'24محرم2024', 130) +GO +~~START~~ +date +2585-05-14 +~~END~~ + + +SELECT CONVERT(DATE, N'4محرم, 2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'4محرم2024', 130) +GO +~~START~~ +date +2585-04-24 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- dd mon[,][yy]yy +SELECT CONVERT(DATE, '12 Apr, 2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12 Apr') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12Apr, 2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr2024') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr, 24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr24') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr, 4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr4') +GO +~~START~~ +date +2004-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12Apr,') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12Apr') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATE, N'12 محرم, 2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم 2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12 محرم,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'12 محرم', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'12محرم, 2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم2024', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم, 24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم24', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم, 4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم4', 130) +GO +~~START~~ +date +2565-12-05 +~~END~~ + + +SELECT CONVERT(DATE, N'12محرم,', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, N'12محرم', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- dd [yy]yy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 24 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 2024Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 24Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 24 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'12 24محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +--- [dd] yyyy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2 2024 Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '12 2024Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2 2024Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2 2024 محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2 2024محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- yyyy mon [dd] +SELECT CONVERT(DATE, '2024 Apr 12') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr 2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr12') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr2') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 محرم 12', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم 2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم12', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم2', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +--- yyyy [dd] mon +SELECT CONVERT(DATE, '2024 12 Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 2 Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024 Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +SELECT CONVERT(DATE, '2024 12Apr') +GO +~~START~~ +date +2024-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '2024 2Apr') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +SELECT CONVERT(DATE, '2024Apr') +GO +~~START~~ +date +2024-04-01 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 12 محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 2 محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 12محرم', 130) +GO +~~START~~ +date +2585-05-02 +~~END~~ + + +SELECT CONVERT(DATE, N'2024 2محرم', 130) +GO +~~START~~ +date +2585-04-22 +~~END~~ + + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO +~~START~~ +date +2585-04-21 +~~END~~ + + +-- ISO 8601 +SELECT CONVERT(DATE, '2023-11-27') +GO +~~START~~ +date +2023-11-27 +~~END~~ + + +SELECT CONVERT(DATE, '2023-2-29') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-1-22T13:34:12.123') +GO +~~START~~ +date +2022-01-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-2T13:34:12.123') +GO +~~START~~ +date +2022-10-02 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T3:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:4:12.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:1.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345678') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456789') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567891') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.15') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123-11:11') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123Z') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATE, '2022-10-22T13 :34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10 -22T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22 T 13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 -11:11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- -- rounding +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999995') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999994') +GO +~~START~~ +date +2022-10-22 +~~END~~ + + +-- DATE with typmod +SELECT CONVERT(DATE(1), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: type modifier is not allowed for type "date")~~ + + +SELECT CONVERT(DATE(2), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: type modifier is not allowed for type "date")~~ + + +SELECT CONVERT(DATE(3), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: type modifier is not allowed for type "date")~~ + + +-- Unseparated +SELECT CONVERT(DATE, '20240129') +GO +~~START~~ +date +2024-01-29 +~~END~~ + + +SELECT CONVERT(DATE, '20790606') +GO +~~START~~ +date +2079-06-06 +~~END~~ + + +SELECT CONVERT(DATE, '20790607') +GO +~~START~~ +date +2079-06-07 +~~END~~ + + +SELECT CONVERT(DATE, '240129') +GO +~~START~~ +date +2024-01-29 +~~END~~ + + +SELECT CONVERT(DATE, '241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '2001') +GO +~~START~~ +date +2001-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '0001') +GO +~~START~~ +date +0001-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '1753') +GO +~~START~~ +date +1753-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '1900') +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +-- for styles 130 and 131, the DATE ranges (for example, number of days in a month) are different compared to other styles +SELECT CONVERT(DATE, '20231229', 130) +GO +~~START~~ +date +2585-04-19 +~~END~~ + + +SELECT CONVERT(DATE, '20231230', 130) +GO +~~START~~ +date +2585-04-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231129', 130) +GO +~~START~~ +date +2585-03-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231130', 130) +GO +~~START~~ +date +2585-03-21 +~~END~~ + + +SELECT CONVERT(DATE, '20231229', 131) +GO +~~START~~ +date +2585-04-19 +~~END~~ + + +SELECT CONVERT(DATE, '20231230', 131) +GO +~~START~~ +date +2585-04-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231129', 131) +GO +~~START~~ +date +2585-03-20 +~~END~~ + + +SELECT CONVERT(DATE, '20231130', 131) +GO +~~START~~ +date +2585-03-21 +~~END~~ + + +-- -- hijri leap year only contains 29 days in 12th month (for style 130 and 131) +SELECT CONVERT(DATE, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '20241230', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a date data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATE, '20241229', 130) +GO +~~START~~ +date +2586-04-09 +~~END~~ + + +SELECT CONVERT(DATE, '20241229', 131) +GO +~~START~~ +date +2586-04-09 +~~END~~ + + +-- -- invalid syntax +SELECT CONVERT(DATE, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- W3C XML format +SELECT CONVERT(DATE, '2024-04-22-05:12') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22+05:12') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22-14:00') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22+14:00') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-22-14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2024-04-22+14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2024-04-22Z') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '24-04-22Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2024-4-22Z') +GO +~~START~~ +date +2024-04-22 +~~END~~ + + +SELECT CONVERT(DATE, '2024-04-2Z') +GO +~~START~~ +date +2024-04-02 +~~END~~ + + +-- hijri +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +date +2018-10-02 +~~END~~ + + +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +date +2018-10-02 +~~END~~ + + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +date +2019-08-23 +~~END~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +date +2021-04-10 +~~END~~ + + +SELECT CONVERT(DATE, '02/12/21', 1) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '21.02.12', 2) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12/02/21', 3) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12.02.21', 4) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12-02-21', 5) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 21', 6) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12, 21', 7) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '10:13:14', 8) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '10:13:14', 24) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '02-12-21', 10) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '21/02/12', 11) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '210212', 12) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '15:13:14:123', 14) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 20) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '02/12/21 15:13:14 PM', 22) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12', 23) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 25) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +date +2021-04-10 +~~END~~ + + +SELECT CONVERT(DATE, '02/12/2021', 101) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021.02.12', 102) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12/02/2021', 103) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12.02.2021', 104) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12-02-2021', 105) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2021', 106) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12, 2021', 107) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '10:13:14', 108) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '02-12-2021', 110) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021/02/12', 111) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '20210212', 112) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +date +2021-04-12 +~~END~~ + + +SELECT CONVERT(DATE, '15:13:14:123', 114) +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 120) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +date +2021-02-12 +~~END~~ + + +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +date +2018-10-02 +~~END~~ + + +SELECT CONVERT(DATE, N'22 April 1440 1:39:17.090', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +date +2582-07-04 +~~END~~ + + +-- -- misc +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO +~~START~~ +date +2022-10-29 +~~END~~ + + +SELECT CONVERT(DATE, '2020') +GO +~~START~~ +date +2020-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(DATE, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(DATE, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '1900-05-06 13:59:29.050 -8:00') +GO +~~START~~ +date +1900-05-06 +~~END~~ + + +SELECT CONVERT(DATE, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO +~~START~~ +date +2022-10-29 +~~END~~ + + +SELECT CONVERT(DATE, '2020') +GO +~~START~~ +date +2020-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2022-10-30T03:00:00') +GO +~~START~~ +date +2022-10-30 +~~END~~ + + +SELECT CONVERT(DATE, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +date +2021-01-01 +~~END~~ + + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATE, @TM_ICLO) +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type time without time zone to date is not allowed.)~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_date_v1 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p1 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f1() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v2 +GO +~~START~~ +date +9999-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p2 +GO +~~START~~ +date +9999-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f2() +GO +~~START~~ +date +9999-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v3 +GO +~~START~~ +date +1900-01-01 +~~END~~ + +EXEC test_conv_string_to_date_p3 +GO +~~START~~ +date +1900-01-01 +~~END~~ + +SELECT test_conv_string_to_date_f3() +GO +~~START~~ +date +1900-01-01 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v4 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p4 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f4() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v5 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p5 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f5() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v6 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p6 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f6() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v7 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p7 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f7() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + +EXEC test_conv_string_to_date_p8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + +SELECT test_conv_string_to_date_f8() +GO +~~START~~ +date +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + + +SELECT * FROM test_conv_string_to_date_v9 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +EXEC test_conv_string_to_date_p9 +GO +~~START~~ +date +2017-08-25 +~~END~~ + +SELECT test_conv_string_to_date_f9() +GO +~~START~~ +date +2017-08-25 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_v10 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT * FROM test_conv_string_to_date_v11 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT * FROM test_conv_string_to_date_v12 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ + diff --git a/test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-cleanup.out new file mode 100644 index 0000000000..eee79e360d --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-cleanup.out @@ -0,0 +1,68 @@ +DROP VIEW test_conv_string_to_datetime_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime_p1 +GO +DROP FUNCTION test_conv_string_to_datetime_f1() +GO + +DROP VIEW test_conv_string_to_datetime_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime_p2 +GO +DROP FUNCTION test_conv_string_to_datetime_f2() +GO + +DROP VIEW test_conv_string_to_datetime_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime_p3 +GO +DROP FUNCTION test_conv_string_to_datetime_f3() +GO + +DROP VIEW test_conv_string_to_datetime_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime_p4 +GO +DROP FUNCTION test_conv_string_to_datetime_f4() +GO + +DROP VIEW test_conv_string_to_datetime_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime_p5 +GO +DROP FUNCTION test_conv_string_to_datetime_f5() +GO + +DROP VIEW test_conv_string_to_datetime_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime_p6 +GO +DROP FUNCTION test_conv_string_to_datetime_f6() +GO + +DROP VIEW test_conv_string_to_datetime_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime_p7 +GO +DROP FUNCTION test_conv_string_to_datetime_f7() +GO + +DROP VIEW test_conv_string_to_datetime_v8 +GO +DROP PROCEDURE test_conv_string_to_datetime_p8 +GO +DROP FUNCTION test_conv_string_to_datetime_f8() +GO + +DROP VIEW test_conv_string_to_datetime_v9 +GO +DROP PROCEDURE test_conv_string_to_datetime_p9 +GO +DROP FUNCTION test_conv_string_to_datetime_f9() +GO + +DROP VIEW test_conv_string_to_datetime_v10 +GO + +DROP VIEW test_conv_string_to_datetime_v11 +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-prepare.out new file mode 100644 index 0000000000..7194d7f94d --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-prepare.out @@ -0,0 +1,104 @@ +CREATE VIEW test_conv_string_to_datetime_v1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f1() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f2() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f3() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f4() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f5() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f6() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f7() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f8() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f9() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v10 as (SELECT CONVERT(datetime, '20')); +GO + +CREATE VIEW test_conv_string_to_datetime_v11 as (SELECT CONVERT(datetime, CAST('20' AS INTEGER))); +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-verify.out b/test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-verify.out new file mode 100644 index 0000000000..eba0447f9b --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime-before-14_6-vu-verify.out @@ -0,0 +1,3543 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIME, '') +GO +~~START~~ +datetime +1900-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '', 130) +GO +~~START~~ +datetime +1900-01-01 00:00:00.0 +~~END~~ + + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATETIME, '3-2-4 14:30') +GO +~~START~~ +datetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-12-4 14:30') +GO +~~START~~ +datetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-12-24 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-12-2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11-12-2024 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 - 12 - 2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.2.4 14:30') +GO +~~START~~ +datetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.12.4 14:30') +GO +~~START~~ +datetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.12.24 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.12.2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11.12.2024 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 . 12 . 2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/2/4 14:30') +GO +~~START~~ +datetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/12/4 14:30') +GO +~~START~~ +datetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/12/24 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/12/2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11/12/2024 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 / 12 / 2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATETIME, '3-4-2 14:30') +GO +~~START~~ +datetime +2002-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-4-12 14:30') +GO +~~START~~ +datetime +2012-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-24-12 14:30') +GO +~~START~~ +datetime +2012-03-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-2024-12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11-2024-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 - 2024 - 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.4.2 14:30') +GO +~~START~~ +datetime +2002-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.4.12 14:30') +GO +~~START~~ +datetime +2012-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.24.12 14:30') +GO +~~START~~ +datetime +2012-03-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.2024.12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11.2024.12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 . 2024 . 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/4/2 14:30') +GO +~~START~~ +datetime +2002-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/4/12 14:30') +GO +~~START~~ +datetime +2012-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/24/12 14:30') +GO +~~START~~ +datetime +2012-03-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/2024/12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11/2024/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 / 2024 / 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATETIME, '2-3-4 14:30') +GO +~~START~~ +datetime +2004-02-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-3-4 14:30') +GO +~~START~~ +datetime +2004-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-3-24 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-3-2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-11-2024 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 - 3 - 2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2.3.4 14:30') +GO +~~START~~ +datetime +2004-02-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.3.4 14:30') +GO +~~START~~ +datetime +2004-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.3.24 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.3.2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.11.2024 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 . 3 . 2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2/3/4 14:30') +GO +~~START~~ +datetime +2004-02-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/3/4 14:30') +GO +~~START~~ +datetime +2004-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/3/24 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/3/2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/11/2024 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 / 3 / 2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATETIME, '2-4-3 14:30') +GO +~~START~~ +datetime +2003-02-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-4-3 14:30') +GO +~~START~~ +datetime +2003-12-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-24-3 14:30') +GO +~~START~~ +datetime +2003-12-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-2024-3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-2024-11 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 - 2024 - 3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2.4.3 14:30') +GO +~~START~~ +datetime +2003-02-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.4.3 14:30') +GO +~~START~~ +datetime +2003-12-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.24.3 14:30') +GO +~~START~~ +datetime +2003-12-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.2024.3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.2024.11 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 . 2024 . 3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2/4/3 14:30') +GO +~~START~~ +datetime +2003-02-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/4/3 14:30') +GO +~~START~~ +datetime +2003-12-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/24/3 14:30') +GO +~~START~~ +datetime +2003-12-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/2024/3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/2024/11 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 / 2024 / 3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATETIME, '4-3-2 14:30') +GO +~~START~~ +datetime +2002-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4-3-12 14:30') +GO +~~START~~ +datetime +2012-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24-3-12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2024-3-12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024-11-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 - 3 - 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4.3.2 14:30') +GO +~~START~~ +datetime +2002-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4.3.12 14:30') +GO +~~START~~ +datetime +2012-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24.3.12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2024.3.12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024.11.12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 . 3 . 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4/3/2 14:30') +GO +~~START~~ +datetime +2002-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4/3/12 14:30') +GO +~~START~~ +datetime +2012-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24/3/12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2024/3/12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024/11/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 / 3 / 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +-- combination of different seperator also works for DATETIME +SELECT CONVERT(DATETIME, '2024/11-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024-11/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024.11/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024.11-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(DATETIME, '3 12 2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '3#12#2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- cut off year +SELECT CONVERT(DATETIME, '11-12-49') +GO +~~START~~ +datetime +2049-11-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11-12-50') +GO +~~START~~ +datetime +1950-11-12 00:00:00.0 +~~END~~ + + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '03-22-2024') +GO +~~START~~ +datetime +2024-03-22 00:00:00.0 +~~END~~ + + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '22-03-2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024-03-22') +GO +~~START~~ +datetime +2024-03-22 00:00:00.0 +~~END~~ + + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '03-2024-22') +GO +~~START~~ +datetime +2024-03-22 00:00:00.0 +~~END~~ + + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '22-2024-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATETIME, Hence following query should throw error +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATETIME, '2024-22-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATETIME, 'Apr 12,2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12,2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12 2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1 2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATETIME, 'Apr 12, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 1, 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1, 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr12, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr1, 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1, 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr1 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- mon yyyy [dd] +SELECT CONVERT(DATETIME, 'Apr 2024 22 14:30') +GO +~~START~~ +datetime +2024-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2024 2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 22 14:30') +GO +~~START~~ +datetime +2024-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 2024 22 14:30', 130) +GO +~~START~~ +datetime +2585-05-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2024 2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 22 14:30', 130) +GO +~~START~~ +datetime +2585-05-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATETIME, '24 Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24 Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4 Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4 Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATETIME, N'24 محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'24 محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4 محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4 محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'24محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'24محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- dd mon[,][yy]yy +SELECT CONVERT(DATETIME, '12 Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '12 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '12Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '12Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATETIME, N'12 محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 محرم, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- dd [yy]yy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 24 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 24Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 24 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 24محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +--- [dd] yyyy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2 2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2 2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2 2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2 2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- yyyy mon [dd] +SELECT CONVERT(DATETIME, '2024 Apr 12 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr12 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 محرم 12 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم12 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- yyyy [dd] mon +SELECT CONVERT(DATETIME, '2024 12 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 2 Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 12Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 2Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 12 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 2 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 12محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 2محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +-- ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO +~~START~~ +datetime +2022-10-22 13:34:12.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-1-22T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-2T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T3:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:4:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:1.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1') +GO +~~START~~ +datetime +2022-10-22 13:34:12.1 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.12') +GO +~~START~~ +datetime +2022-10-22 13:34:12.12 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO +~~START~~ +datetime +2022-10-22 13:34:12.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.15') +GO +~~START~~ +datetime +2022-10-22 13:34:12.15 +~~END~~ + + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13 :34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10 -22T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22 T 13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Unseparated +SELECT CONVERT(DATETIME, '20240129') +GO +~~START~~ +datetime +2024-01-29 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '240129') +GO +~~START~~ +datetime +2024-01-29 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2001') +GO +~~START~~ +datetime +2001-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '0001') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '20240129 03:00:00') +GO +~~START~~ +datetime +2024-01-29 03:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20241329 03:00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '240129 03:00') +GO +~~START~~ +datetime +2024-01-29 03:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '241329 03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2001 03:00:00.123') +GO +~~START~~ +datetime +2001-01-01 03:00:00.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '0001 03:00:00.421') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- -- invalid syntax +SELECT CONVERT(DATETIME, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- should return default DATETIME +SELECT CONVERT(DATETIME, '16:23:51') +GO +~~START~~ +datetime +1900-01-01 16:23:51.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4:12:12:123') +GO +~~START~~ +datetime +1900-01-01 04:12:12.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '4:12:12:1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '4:12:12.1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- hijri +SELECT CONVERT(DATETIME, '20231229', 130) +GO +~~START~~ +datetime +2585-04-19 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20231230', 130) +GO +~~START~~ +datetime +2585-04-20 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20231129', 130) +GO +~~START~~ +datetime +2585-03-20 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20231130', 130) +GO +~~START~~ +datetime +2585-03-21 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime +2018-10-02 01:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +datetime +2018-10-02 01:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 130) +GO +~~START~~ +datetime +2019-08-23 13:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +datetime +2019-08-23 13:39:17.09 +~~END~~ + + +-- -- hijri leap year +SELECT CONVERT(DATETIME, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- rounding of DATETIME +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.999') +GO +~~START~~ +datetime +1998-01-02 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.998') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.997') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.996') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.995') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.994') +GO +~~START~~ +datetime +1998-01-01 23:59:59.993 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.993') +GO +~~START~~ +datetime +1998-01-01 23:59:59.993 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.992') +GO +~~START~~ +datetime +1998-01-01 23:59:59.993 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.991') +GO +~~START~~ +datetime +1998-01-01 23:59:59.99 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.990') +GO +~~START~~ +datetime +1998-01-01 23:59:59.99 +~~END~~ + + +-- DATETIME with typmod +SELECT CONVERT(DATETIME(1), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'datetime')~~ + + +SELECT CONVERT(DATETIME(2), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'datetime')~~ + + +SELECT CONVERT(DATETIME(3), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'datetime')~~ + + +-- boundary tests +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.998') +GO +~~START~~ +datetime +9999-12-31 23:59:59.997 +~~END~~ + + +-- -- out of bound values +SELECT CONVERT(DATETIME,'2022-10-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'0000-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'2023-00-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'0000-00-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'1742-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +datetime +2021-04-10 11:12:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '02/12/21', 1) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '21.02.12', 2) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/02/21', 3) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.02.21', 4) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-02-21', 5) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 21', 6) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 21', 7) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '10:13:14', 8) +GO +~~START~~ +datetime +1900-01-01 10:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '10:13:14', 24) +GO +~~START~~ +datetime +1900-01-01 10:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +datetime +2021-04-12 10:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '02-12-21', 10) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '21/02/12', 11) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '210212', 12) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +datetime +2021-04-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '15:13:14:123', 14) +GO +~~START~~ +datetime +1900-01-01 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 20) +GO +~~START~~ +datetime +2021-02-12 15:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '02/12/21 15:13:14 PM', 22) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2021-02-12', 23) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 25) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +datetime +2021-04-10 11:12:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '02/12/2021', 101) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021.02.12', 102) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/02/2021', 103) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.02.2021', 104) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-02-2021', 105) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2021', 106) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 2021', 107) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '10:13:14', 108) +GO +~~START~~ +datetime +1900-01-01 10:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +datetime +2021-04-12 10:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '02-12-2021', 110) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021/02/12', 111) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20210212', 112) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +datetime +2021-04-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '15:13:14:123', 114) +GO +~~START~~ +datetime +1900-01-01 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 120) +GO +~~START~~ +datetime +2021-02-12 15:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime +2018-10-02 01:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +datetime +2582-07-04 15:13:14.123 +~~END~~ + + +--- misc +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime +2022-10-29 20:01:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2020') +GO +~~START~~ +datetime +2020-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(DATETIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '1900-05-06 13:59:29.050 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2011-08-15 14:30.00') +GO +~~START~~ +datetime +2011-08-15 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime +2022-10-29 20:01:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2020') +GO +~~START~~ +datetime +2020-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-30T03:00:00') +GO +~~START~~ +datetime +2022-10-30 03:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +datetime +2021-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME, @TM_ICLO) +GO +~~START~~ +datetime +1900-01-01 17:24:07.177 +~~END~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime_v1 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p1 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f1() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v2 +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p2 +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f2() +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v3 +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p3 +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f3() +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v4 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p4 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f4() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v5 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p5 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f5() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v6 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p6 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f6() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v7 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p7 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f7() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v8 +GO +~~START~~ +datetime +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to timestamp without time zone)~~ + +EXEC test_conv_string_to_datetime_p8 +GO +~~START~~ +datetime +1905-07-11 00:00:00.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f8() +GO +~~START~~ +datetime +1905-07-11 00:00:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v9 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p9 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f9() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v10 +GO +~~START~~ +datetime +1900-01-21 00:00:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v11 +GO +~~START~~ +datetime +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to timestamp without time zone)~~ + diff --git a/test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-cleanup.out new file mode 100644 index 0000000000..eee79e360d --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-cleanup.out @@ -0,0 +1,68 @@ +DROP VIEW test_conv_string_to_datetime_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime_p1 +GO +DROP FUNCTION test_conv_string_to_datetime_f1() +GO + +DROP VIEW test_conv_string_to_datetime_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime_p2 +GO +DROP FUNCTION test_conv_string_to_datetime_f2() +GO + +DROP VIEW test_conv_string_to_datetime_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime_p3 +GO +DROP FUNCTION test_conv_string_to_datetime_f3() +GO + +DROP VIEW test_conv_string_to_datetime_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime_p4 +GO +DROP FUNCTION test_conv_string_to_datetime_f4() +GO + +DROP VIEW test_conv_string_to_datetime_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime_p5 +GO +DROP FUNCTION test_conv_string_to_datetime_f5() +GO + +DROP VIEW test_conv_string_to_datetime_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime_p6 +GO +DROP FUNCTION test_conv_string_to_datetime_f6() +GO + +DROP VIEW test_conv_string_to_datetime_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime_p7 +GO +DROP FUNCTION test_conv_string_to_datetime_f7() +GO + +DROP VIEW test_conv_string_to_datetime_v8 +GO +DROP PROCEDURE test_conv_string_to_datetime_p8 +GO +DROP FUNCTION test_conv_string_to_datetime_f8() +GO + +DROP VIEW test_conv_string_to_datetime_v9 +GO +DROP PROCEDURE test_conv_string_to_datetime_p9 +GO +DROP FUNCTION test_conv_string_to_datetime_f9() +GO + +DROP VIEW test_conv_string_to_datetime_v10 +GO + +DROP VIEW test_conv_string_to_datetime_v11 +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-prepare.out new file mode 100644 index 0000000000..7194d7f94d --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-prepare.out @@ -0,0 +1,104 @@ +CREATE VIEW test_conv_string_to_datetime_v1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f1() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f2() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f3() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f4() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f5() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f6() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f7() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f8() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f9() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v10 as (SELECT CONVERT(datetime, '20')); +GO + +CREATE VIEW test_conv_string_to_datetime_v11 as (SELECT CONVERT(datetime, CAST('20' AS INTEGER))); +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-verify.out b/test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-verify.out new file mode 100644 index 0000000000..1d33b5ad7e --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime-before-17_3-vu-verify.out @@ -0,0 +1,3541 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIME, '') +GO +~~START~~ +datetime +1900-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '', 130) +GO +~~START~~ +datetime +1900-01-01 00:00:00.0 +~~END~~ + + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATETIME, '3-2-4 14:30') +GO +~~START~~ +datetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-12-4 14:30') +GO +~~START~~ +datetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-12-24 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-12-2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11-12-2024 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 - 12 - 2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.2.4 14:30') +GO +~~START~~ +datetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.12.4 14:30') +GO +~~START~~ +datetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.12.24 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.12.2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11.12.2024 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 . 12 . 2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/2/4 14:30') +GO +~~START~~ +datetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/12/4 14:30') +GO +~~START~~ +datetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/12/24 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/12/2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11/12/2024 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 / 12 / 2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATETIME, '3-4-2 14:30') +GO +~~START~~ +datetime +2002-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-4-12 14:30') +GO +~~START~~ +datetime +2012-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-24-12 14:30') +GO +~~START~~ +datetime +2012-03-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-2024-12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11-2024-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 - 2024 - 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.4.2 14:30') +GO +~~START~~ +datetime +2002-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.4.12 14:30') +GO +~~START~~ +datetime +2012-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.24.12 14:30') +GO +~~START~~ +datetime +2012-03-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.2024.12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11.2024.12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 . 2024 . 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/4/2 14:30') +GO +~~START~~ +datetime +2002-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/4/12 14:30') +GO +~~START~~ +datetime +2012-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/24/12 14:30') +GO +~~START~~ +datetime +2012-03-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/2024/12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11/2024/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 / 2024 / 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATETIME, '2-3-4 14:30') +GO +~~START~~ +datetime +2004-02-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-3-4 14:30') +GO +~~START~~ +datetime +2004-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-3-24 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-3-2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-11-2024 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 - 3 - 2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2.3.4 14:30') +GO +~~START~~ +datetime +2004-02-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.3.4 14:30') +GO +~~START~~ +datetime +2004-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.3.24 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.3.2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.11.2024 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 . 3 . 2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2/3/4 14:30') +GO +~~START~~ +datetime +2004-02-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/3/4 14:30') +GO +~~START~~ +datetime +2004-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/3/24 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/3/2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/11/2024 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 / 3 / 2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATETIME, '2-4-3 14:30') +GO +~~START~~ +datetime +2003-02-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-4-3 14:30') +GO +~~START~~ +datetime +2003-12-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-24-3 14:30') +GO +~~START~~ +datetime +2003-12-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-2024-3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-2024-11 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 - 2024 - 3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2.4.3 14:30') +GO +~~START~~ +datetime +2003-02-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.4.3 14:30') +GO +~~START~~ +datetime +2003-12-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.24.3 14:30') +GO +~~START~~ +datetime +2003-12-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.2024.3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.2024.11 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 . 2024 . 3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2/4/3 14:30') +GO +~~START~~ +datetime +2003-02-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/4/3 14:30') +GO +~~START~~ +datetime +2003-12-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/24/3 14:30') +GO +~~START~~ +datetime +2003-12-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/2024/3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/2024/11 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 / 2024 / 3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATETIME, '4-3-2 14:30') +GO +~~START~~ +datetime +2002-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4-3-12 14:30') +GO +~~START~~ +datetime +2012-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24-3-12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2024-3-12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024-11-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 - 3 - 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4.3.2 14:30') +GO +~~START~~ +datetime +2002-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4.3.12 14:30') +GO +~~START~~ +datetime +2012-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24.3.12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2024.3.12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024.11.12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 . 3 . 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4/3/2 14:30') +GO +~~START~~ +datetime +2002-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4/3/12 14:30') +GO +~~START~~ +datetime +2012-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24/3/12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2024/3/12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024/11/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 / 3 / 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +-- combination of different seperator also works for DATETIME +SELECT CONVERT(DATETIME, '2024/11-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024-11/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024.11/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024.11-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(DATETIME, '3 12 2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '3#12#2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- cut off year +SELECT CONVERT(DATETIME, '11-12-49') +GO +~~START~~ +datetime +2049-11-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11-12-50') +GO +~~START~~ +datetime +1950-11-12 00:00:00.0 +~~END~~ + + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '03-22-2024') +GO +~~START~~ +datetime +2024-03-22 00:00:00.0 +~~END~~ + + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '22-03-2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024-03-22') +GO +~~START~~ +datetime +2024-03-22 00:00:00.0 +~~END~~ + + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '03-2024-22') +GO +~~START~~ +datetime +2024-03-22 00:00:00.0 +~~END~~ + + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '22-2024-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATETIME, Hence following query should throw error +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATETIME, '2024-22-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATETIME, 'Apr 12,2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12,2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12 2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1 2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATETIME, 'Apr 12, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 1, 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1, 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr12, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr1, 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1, 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr1 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- mon yyyy [dd] +SELECT CONVERT(DATETIME, 'Apr 2024 22 14:30') +GO +~~START~~ +datetime +2024-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2024 2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 22 14:30') +GO +~~START~~ +datetime +2024-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 2024 22 14:30', 130) +GO +~~START~~ +datetime +2585-05-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2024 2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 22 14:30', 130) +GO +~~START~~ +datetime +2585-05-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATETIME, '24 Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24 Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4 Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4 Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATETIME, N'24 محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'24 محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4 محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4 محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'24محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'24محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- dd mon[,][yy]yy +SELECT CONVERT(DATETIME, '12 Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '12 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '12Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '12Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATETIME, N'12 محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 محرم, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- dd [yy]yy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 24 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 24Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 24 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 24محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +--- [dd] yyyy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2 2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2 2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2 2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2 2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- yyyy mon [dd] +SELECT CONVERT(DATETIME, '2024 Apr 12 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr12 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 محرم 12 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم12 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- yyyy [dd] mon +SELECT CONVERT(DATETIME, '2024 12 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 2 Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 12Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 2Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 12 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 2 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 12محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 2محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +-- ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO +~~START~~ +datetime +2022-10-22 13:34:12.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-1-22T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-2T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T3:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:4:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:1.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1') +GO +~~START~~ +datetime +2022-10-22 13:34:12.1 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.12') +GO +~~START~~ +datetime +2022-10-22 13:34:12.12 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO +~~START~~ +datetime +2022-10-22 13:34:12.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.15') +GO +~~START~~ +datetime +2022-10-22 13:34:12.15 +~~END~~ + + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13 :34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10 -22T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22 T 13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Unseparated +SELECT CONVERT(DATETIME, '20240129') +GO +~~START~~ +datetime +2024-01-29 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '240129') +GO +~~START~~ +datetime +2024-01-29 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2001') +GO +~~START~~ +datetime +2001-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '0001') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '20240129 03:00:00') +GO +~~START~~ +datetime +2024-01-29 03:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20241329 03:00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '240129 03:00') +GO +~~START~~ +datetime +2024-01-29 03:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '241329 03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2001 03:00:00.123') +GO +~~START~~ +datetime +2001-01-01 03:00:00.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '0001 03:00:00.421') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- -- invalid syntax +SELECT CONVERT(DATETIME, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- should return default DATETIME +SELECT CONVERT(DATETIME, '16:23:51') +GO +~~START~~ +datetime +1900-01-01 16:23:51.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4:12:12:123') +GO +~~START~~ +datetime +1900-01-01 04:12:12.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '4:12:12:1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '4:12:12.1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- hijri +SELECT CONVERT(DATETIME, '20231229', 130) +GO +~~START~~ +datetime +2585-04-19 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20231230', 130) +GO +~~START~~ +datetime +2585-04-20 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20231129', 130) +GO +~~START~~ +datetime +2585-03-20 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20231130', 130) +GO +~~START~~ +datetime +2585-03-21 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime +2018-10-02 01:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +datetime +2018-10-02 01:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 130) +GO +~~START~~ +datetime +2019-08-23 13:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +datetime +2019-08-23 13:39:17.09 +~~END~~ + + +-- -- hijri leap year +SELECT CONVERT(DATETIME, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- rounding of DATETIME +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.999') +GO +~~START~~ +datetime +1998-01-02 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.998') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.997') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.996') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.995') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.994') +GO +~~START~~ +datetime +1998-01-01 23:59:59.993 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.993') +GO +~~START~~ +datetime +1998-01-01 23:59:59.993 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.992') +GO +~~START~~ +datetime +1998-01-01 23:59:59.993 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.991') +GO +~~START~~ +datetime +1998-01-01 23:59:59.99 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.990') +GO +~~START~~ +datetime +1998-01-01 23:59:59.99 +~~END~~ + + +-- DATETIME with typmod +SELECT CONVERT(DATETIME(1), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'datetime')~~ + + +SELECT CONVERT(DATETIME(2), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'datetime')~~ + + +SELECT CONVERT(DATETIME(3), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'datetime')~~ + + +-- boundary tests +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.998') +GO +~~START~~ +datetime +9999-12-31 23:59:59.997 +~~END~~ + + +-- -- out of bound values +SELECT CONVERT(DATETIME,'2022-10-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'0000-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'2023-00-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'0000-00-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'1742-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +datetime +2021-04-10 11:12:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '02/12/21', 1) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '21.02.12', 2) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/02/21', 3) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.02.21', 4) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-02-21', 5) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 21', 6) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 21', 7) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '10:13:14', 8) +GO +~~START~~ +datetime +1900-01-01 10:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '10:13:14', 24) +GO +~~START~~ +datetime +1900-01-01 10:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +datetime +2021-04-12 10:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '02-12-21', 10) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '21/02/12', 11) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '210212', 12) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +datetime +2021-04-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '15:13:14:123', 14) +GO +~~START~~ +datetime +1900-01-01 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 20) +GO +~~START~~ +datetime +2021-02-12 15:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '02/12/21 15:13:14 PM', 22) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2021-02-12', 23) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 25) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +datetime +2021-04-10 11:12:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '02/12/2021', 101) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021.02.12', 102) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/02/2021', 103) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.02.2021', 104) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-02-2021', 105) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2021', 106) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 2021', 107) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '10:13:14', 108) +GO +~~START~~ +datetime +1900-01-01 10:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +datetime +2021-04-12 10:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '02-12-2021', 110) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021/02/12', 111) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20210212', 112) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +datetime +2021-04-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '15:13:14:123', 114) +GO +~~START~~ +datetime +1900-01-01 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 120) +GO +~~START~~ +datetime +2021-02-12 15:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime +2018-10-02 01:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +datetime +2582-07-04 15:13:14.123 +~~END~~ + + +--- misc +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime +2022-10-29 20:01:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2020') +GO +~~START~~ +datetime +2020-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(DATETIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '1900-05-06 13:59:29.050 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2011-08-15 14:30.00') +GO +~~START~~ +datetime +2011-08-15 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime +2022-10-29 20:01:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2020') +GO +~~START~~ +datetime +2020-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-30T03:00:00') +GO +~~START~~ +datetime +2022-10-30 03:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +datetime +2021-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME, @TM_ICLO) +GO +~~START~~ +datetime +1900-01-01 17:24:07.177 +~~END~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime_v1 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p1 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f1() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v2 +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p2 +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f2() +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v3 +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p3 +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f3() +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v4 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p4 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f4() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v5 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p5 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f5() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v6 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p6 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f6() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v7 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p7 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f7() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v8 +GO +~~START~~ +datetime +1905-07-11 00:00:00.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p8 +GO +~~START~~ +datetime +1905-07-11 00:00:00.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f8() +GO +~~START~~ +datetime +1905-07-11 00:00:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v9 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p9 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f9() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v10 +GO +~~START~~ +datetime +1900-01-21 00:00:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v11 +GO +~~START~~ +datetime +1900-01-21 00:00:00.0 +~~END~~ + diff --git a/test/JDBC/expected/test_conv_string_to_datetime-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_datetime-vu-cleanup.out new file mode 100644 index 0000000000..eee79e360d --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime-vu-cleanup.out @@ -0,0 +1,68 @@ +DROP VIEW test_conv_string_to_datetime_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime_p1 +GO +DROP FUNCTION test_conv_string_to_datetime_f1() +GO + +DROP VIEW test_conv_string_to_datetime_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime_p2 +GO +DROP FUNCTION test_conv_string_to_datetime_f2() +GO + +DROP VIEW test_conv_string_to_datetime_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime_p3 +GO +DROP FUNCTION test_conv_string_to_datetime_f3() +GO + +DROP VIEW test_conv_string_to_datetime_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime_p4 +GO +DROP FUNCTION test_conv_string_to_datetime_f4() +GO + +DROP VIEW test_conv_string_to_datetime_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime_p5 +GO +DROP FUNCTION test_conv_string_to_datetime_f5() +GO + +DROP VIEW test_conv_string_to_datetime_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime_p6 +GO +DROP FUNCTION test_conv_string_to_datetime_f6() +GO + +DROP VIEW test_conv_string_to_datetime_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime_p7 +GO +DROP FUNCTION test_conv_string_to_datetime_f7() +GO + +DROP VIEW test_conv_string_to_datetime_v8 +GO +DROP PROCEDURE test_conv_string_to_datetime_p8 +GO +DROP FUNCTION test_conv_string_to_datetime_f8() +GO + +DROP VIEW test_conv_string_to_datetime_v9 +GO +DROP PROCEDURE test_conv_string_to_datetime_p9 +GO +DROP FUNCTION test_conv_string_to_datetime_f9() +GO + +DROP VIEW test_conv_string_to_datetime_v10 +GO + +DROP VIEW test_conv_string_to_datetime_v11 +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_datetime-vu-prepare.out new file mode 100644 index 0000000000..7194d7f94d --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime-vu-prepare.out @@ -0,0 +1,104 @@ +CREATE VIEW test_conv_string_to_datetime_v1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f1() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f2() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f3() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f4() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f5() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f6() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f7() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f8() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f9() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v10 as (SELECT CONVERT(datetime, '20')); +GO + +CREATE VIEW test_conv_string_to_datetime_v11 as (SELECT CONVERT(datetime, CAST('20' AS INTEGER))); +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime-vu-verify.out b/test/JDBC/expected/test_conv_string_to_datetime-vu-verify.out new file mode 100644 index 0000000000..45d17344a4 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime-vu-verify.out @@ -0,0 +1,3540 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIME, '') +GO +~~START~~ +datetime +1900-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '', 130) +GO +~~START~~ +datetime +1900-01-01 00:00:00.0 +~~END~~ + + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATETIME, '3-2-4 14:30') +GO +~~START~~ +datetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-12-4 14:30') +GO +~~START~~ +datetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-12-24 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-12-2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11-12-2024 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 - 12 - 2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.2.4 14:30') +GO +~~START~~ +datetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.12.4 14:30') +GO +~~START~~ +datetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.12.24 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.12.2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11.12.2024 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 . 12 . 2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/2/4 14:30') +GO +~~START~~ +datetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/12/4 14:30') +GO +~~START~~ +datetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/12/24 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/12/2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11/12/2024 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 / 12 / 2024 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATETIME, '3-4-2 14:30') +GO +~~START~~ +datetime +2002-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-4-12 14:30') +GO +~~START~~ +datetime +2012-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-24-12 14:30') +GO +~~START~~ +datetime +2012-03-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3-2024-12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11-2024-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 - 2024 - 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.4.2 14:30') +GO +~~START~~ +datetime +2002-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.4.12 14:30') +GO +~~START~~ +datetime +2012-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.24.12 14:30') +GO +~~START~~ +datetime +2012-03-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3.2024.12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11.2024.12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 . 2024 . 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/4/2 14:30') +GO +~~START~~ +datetime +2002-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/4/12 14:30') +GO +~~START~~ +datetime +2012-03-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/24/12 14:30') +GO +~~START~~ +datetime +2012-03-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3/2024/12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11/2024/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '3 / 2024 / 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATETIME, '2-3-4 14:30') +GO +~~START~~ +datetime +2004-02-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-3-4 14:30') +GO +~~START~~ +datetime +2004-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-3-24 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-3-2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-11-2024 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 - 3 - 2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2.3.4 14:30') +GO +~~START~~ +datetime +2004-02-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.3.4 14:30') +GO +~~START~~ +datetime +2004-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.3.24 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.3.2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.11.2024 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 . 3 . 2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2/3/4 14:30') +GO +~~START~~ +datetime +2004-02-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/3/4 14:30') +GO +~~START~~ +datetime +2004-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/3/24 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/3/2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/11/2024 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 / 3 / 2024 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATETIME, '2-4-3 14:30') +GO +~~START~~ +datetime +2003-02-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-4-3 14:30') +GO +~~START~~ +datetime +2003-12-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-24-3 14:30') +GO +~~START~~ +datetime +2003-12-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-2024-3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-2024-11 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 - 2024 - 3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2.4.3 14:30') +GO +~~START~~ +datetime +2003-02-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.4.3 14:30') +GO +~~START~~ +datetime +2003-12-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.24.3 14:30') +GO +~~START~~ +datetime +2003-12-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.2024.3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.2024.11 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 . 2024 . 3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2/4/3 14:30') +GO +~~START~~ +datetime +2003-02-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/4/3 14:30') +GO +~~START~~ +datetime +2003-12-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/24/3 14:30') +GO +~~START~~ +datetime +2003-12-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/2024/3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/2024/11 14:30') +GO +~~START~~ +datetime +2024-12-11 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 / 2024 / 3 14:30') +GO +~~START~~ +datetime +2024-12-03 14:30:00.0 +~~END~~ + + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATETIME, '4-3-2 14:30') +GO +~~START~~ +datetime +2002-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4-3-12 14:30') +GO +~~START~~ +datetime +2012-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24-3-12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2024-3-12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024-11-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 - 3 - 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4.3.2 14:30') +GO +~~START~~ +datetime +2002-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4.3.12 14:30') +GO +~~START~~ +datetime +2012-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24.3.12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2024.3.12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024.11.12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 . 3 . 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4/3/2 14:30') +GO +~~START~~ +datetime +2002-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4/3/12 14:30') +GO +~~START~~ +datetime +2012-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24/3/12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2024/3/12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024/11/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 / 3 / 12 14:30') +GO +~~START~~ +datetime +2024-03-12 14:30:00.0 +~~END~~ + + +-- combination of different seperator also works for DATETIME +SELECT CONVERT(DATETIME, '2024/11-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024-11/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024.11/12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024.11-12 14:30') +GO +~~START~~ +datetime +2024-11-12 14:30:00.0 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(DATETIME, '3 12 2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '3#12#2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- cut off year +SELECT CONVERT(DATETIME, '11-12-49') +GO +~~START~~ +datetime +2049-11-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '11-12-50') +GO +~~START~~ +datetime +1950-11-12 00:00:00.0 +~~END~~ + + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '03-22-2024') +GO +~~START~~ +datetime +2024-03-22 00:00:00.0 +~~END~~ + + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '22-03-2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024-03-22') +GO +~~START~~ +datetime +2024-03-22 00:00:00.0 +~~END~~ + + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '03-2024-22') +GO +~~START~~ +datetime +2024-03-22 00:00:00.0 +~~END~~ + + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '22-2024-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATETIME, Hence following query should throw error +SELECT CONVERT(DATETIME, '2-3-4') +GO +~~START~~ +datetime +2004-02-03 00:00:00.0 +~~END~~ + + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATETIME, '2024-22-03') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATETIME, 'Apr 12,2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12,2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12 2000 14:30') +GO +~~START~~ +datetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1 2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2000 14:30') +GO +~~START~~ +datetime +2000-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-18 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO +~~START~~ +datetime +2562-01-07 14:30:00.0 +~~END~~ + + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATETIME, 'Apr 12, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 1, 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1, 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 1, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 1 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr12, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr12, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr1, 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1 24 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1, 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1 4 14:30') +GO +~~START~~ +datetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr1, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr1 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 12 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم 1 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم12 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'محرم1 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- mon yyyy [dd] +SELECT CONVERT(DATETIME, 'Apr 2024 22 14:30') +GO +~~START~~ +datetime +2024-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2024 2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 22 14:30') +GO +~~START~~ +datetime +2024-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 2024 22 14:30', 130) +GO +~~START~~ +datetime +2585-05-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2024 2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 22 14:30', 130) +GO +~~START~~ +datetime +2585-05-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATETIME, '24 Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24 Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4 Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4 Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '24Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-04 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATETIME, N'24 محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'24 محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4 محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4 محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'24محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'24محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-14 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'4محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- dd mon[,][yy]yy +SELECT CONVERT(DATETIME, '12 Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '12 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '12Apr, 2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr2024 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr, 24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr24 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr, 4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr4 14:30') +GO +~~START~~ +datetime +2004-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12Apr, 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '12Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATETIME, N'12 محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 محرم, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'12 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12محرم2024 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم, 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, N'12محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +--- dd [yy]yy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 24 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 24Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 24 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 24محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +--- [dd] yyyy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2 2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2 2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2 2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2 2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- yyyy mon [dd] +SELECT CONVERT(DATETIME, '2024 Apr 12 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr12 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr2 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 محرم 12 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم12 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم2 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +--- yyyy [dd] mon +SELECT CONVERT(DATETIME, '2024 12 Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 2 Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 12Apr 14:30') +GO +~~START~~ +datetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024 2Apr 14:30') +GO +~~START~~ +datetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO +~~START~~ +datetime +2024-04-01 14:30:00.0 +~~END~~ + + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 12 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 2 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 12محرم 14:30', 130) +GO +~~START~~ +datetime +2585-05-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024 2محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO +~~START~~ +datetime +2585-04-21 14:30:00.0 +~~END~~ + + +-- ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO +~~START~~ +datetime +2022-10-22 13:34:12.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-1-22T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-2T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T3:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:4:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:1.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1') +GO +~~START~~ +datetime +2022-10-22 13:34:12.1 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.12') +GO +~~START~~ +datetime +2022-10-22 13:34:12.12 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO +~~START~~ +datetime +2022-10-22 13:34:12.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.15') +GO +~~START~~ +datetime +2022-10-22 13:34:12.15 +~~END~~ + + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13 :34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10 -22T13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2022-10-22 T 13:34:12.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Unseparated +SELECT CONVERT(DATETIME, '20240129') +GO +~~START~~ +datetime +2024-01-29 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '240129') +GO +~~START~~ +datetime +2024-01-29 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2001') +GO +~~START~~ +datetime +2001-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '0001') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '20240129 03:00:00') +GO +~~START~~ +datetime +2024-01-29 03:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20241329 03:00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '240129 03:00') +GO +~~START~~ +datetime +2024-01-29 03:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '241329 03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '2001 03:00:00.123') +GO +~~START~~ +datetime +2001-01-01 03:00:00.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '0001 03:00:00.421') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- -- invalid syntax +SELECT CONVERT(DATETIME, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- should return default DATETIME +SELECT CONVERT(DATETIME, '16:23:51') +GO +~~START~~ +datetime +1900-01-01 16:23:51.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '4:12:12:123') +GO +~~START~~ +datetime +1900-01-01 04:12:12.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '4:12:12:1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '4:12:12.1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- hijri +SELECT CONVERT(DATETIME, '20231229', 130) +GO +~~START~~ +datetime +2585-04-19 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20231230', 130) +GO +~~START~~ +datetime +2585-04-20 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20231129', 130) +GO +~~START~~ +datetime +2585-03-20 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20231130', 130) +GO +~~START~~ +datetime +2585-03-21 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime +2018-10-02 01:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +datetime +2018-10-02 01:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 130) +GO +~~START~~ +datetime +2019-08-23 13:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +datetime +2019-08-23 13:39:17.09 +~~END~~ + + +-- -- hijri leap year +SELECT CONVERT(DATETIME, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- rounding of DATETIME +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.999') +GO +~~START~~ +datetime +1998-01-02 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.998') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.997') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.996') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.995') +GO +~~START~~ +datetime +1998-01-01 23:59:59.997 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.994') +GO +~~START~~ +datetime +1998-01-01 23:59:59.993 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.993') +GO +~~START~~ +datetime +1998-01-01 23:59:59.993 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.992') +GO +~~START~~ +datetime +1998-01-01 23:59:59.993 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.991') +GO +~~START~~ +datetime +1998-01-01 23:59:59.99 +~~END~~ + + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.990') +GO +~~START~~ +datetime +1998-01-01 23:59:59.99 +~~END~~ + + +-- DATETIME with typmod +SELECT CONVERT(DATETIME(1), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'datetime')~~ + + +SELECT CONVERT(DATETIME(2), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'datetime')~~ + + +SELECT CONVERT(DATETIME(3), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'datetime')~~ + + +-- boundary tests +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.998') +GO +~~START~~ +datetime +9999-12-31 23:59:59.997 +~~END~~ + + +-- -- out of bound values +SELECT CONVERT(DATETIME,'2022-10-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'0000-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'2023-00-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'0000-00-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME,'1742-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.)~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +datetime +2021-04-10 11:12:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '02/12/21', 1) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '21.02.12', 2) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/02/21', 3) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.02.21', 4) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-02-21', 5) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 21', 6) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 21', 7) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '10:13:14', 8) +GO +~~START~~ +datetime +1900-01-01 10:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '10:13:14', 24) +GO +~~START~~ +datetime +1900-01-01 10:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +datetime +2021-04-12 10:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '02-12-21', 10) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '21/02/12', 11) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '210212', 12) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +datetime +2021-04-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '15:13:14:123', 14) +GO +~~START~~ +datetime +1900-01-01 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 20) +GO +~~START~~ +datetime +2021-02-12 15:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '02/12/21 15:13:14 PM', 22) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2021-02-12', 23) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 25) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +datetime +2021-04-10 11:12:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '02/12/2021', 101) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021.02.12', 102) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/02/2021', 103) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12.02.2021', 104) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12-02-2021', 105) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2021', 106) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12, 2021', 107) +GO +~~START~~ +datetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '10:13:14', 108) +GO +~~START~~ +datetime +1900-01-01 10:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +datetime +2021-04-12 10:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '02-12-2021', 110) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021/02/12', 111) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '20210212', 112) +GO +~~START~~ +datetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +datetime +2021-04-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '15:13:14:123', 114) +GO +~~START~~ +datetime +1900-01-01 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 120) +GO +~~START~~ +datetime +2021-02-12 15:13:14.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +datetime +2021-02-12 15:13:14.123 +~~END~~ + + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime +2018-10-02 01:39:17.09 +~~END~~ + + +SELECT CONVERT(DATETIME, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +datetime +2582-07-04 15:13:14.123 +~~END~~ + + +--- misc +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime +2022-10-29 20:01:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2020') +GO +~~START~~ +datetime +2020-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(DATETIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '1900-05-06 13:59:29.050 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2011-08-15 14:30.00') +GO +~~START~~ +datetime +2011-08-15 14:30:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime +2022-10-29 20:01:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2020') +GO +~~START~~ +datetime +2020-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2022-10-30T03:00:00') +GO +~~START~~ +datetime +2022-10-30 03:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +datetime +2021-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME, @TM_ICLO) +GO +~~START~~ +datetime +1900-01-01 17:24:07.177 +~~END~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime_v1 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p1 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f1() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v2 +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p2 +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f2() +GO +~~START~~ +datetime +1900-01-01 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v3 +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p3 +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f3() +GO +~~START~~ +datetime +1753-01-01 00:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v4 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p4 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f4() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v5 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p5 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f5() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v6 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p6 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f6() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v7 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p7 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f7() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v8 +GO +~~START~~ +datetime +1905-07-11 00:00:00.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p8 +GO +~~START~~ +datetime +1905-07-11 00:00:00.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f8() +GO +~~START~~ +datetime +1905-07-11 00:00:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v9 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime_p9 +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime_f9() +GO +~~START~~ +datetime +2017-08-25 13:01:59.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime_v10 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT * FROM test_conv_string_to_datetime_v11 +GO +~~START~~ +datetime +1900-01-21 00:00:00.0 +~~END~~ + diff --git a/test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-cleanup.out new file mode 100644 index 0000000000..26b069f721 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-cleanup.out @@ -0,0 +1,64 @@ +DROP VIEW test_conv_string_to_datetime2_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p1 +GO +DROP FUNCTION test_conv_string_to_datetime2_f1() +GO + +DROP VIEW test_conv_string_to_datetime2_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2() +GO + +DROP PROCEDURE test_conv_string_to_datetime2_p2_2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2_2() +GO + +DROP VIEW test_conv_string_to_datetime2_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p3 +GO +DROP FUNCTION test_conv_string_to_datetime2_f3() +GO + +DROP VIEW test_conv_string_to_datetime2_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p4 +GO +DROP FUNCTION test_conv_string_to_datetime2_f4() +GO + +DROP VIEW test_conv_string_to_datetime2_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p5 +GO +DROP FUNCTION test_conv_string_to_datetime2_f5() +GO + +DROP VIEW test_conv_string_to_datetime2_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p6 +GO +DROP FUNCTION test_conv_string_to_datetime2_f6() +GO + +DROP VIEW test_conv_string_to_datetime2_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p7 +GO +DROP FUNCTION test_conv_string_to_datetime2_f7() +GO + +DROP VIEW test_conv_string_to_datetime2_v8 +GO +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: view "test_conv_string_to_datetime2_v8" does not exist)~~ + +DROP PROCEDURE test_conv_string_to_datetime2_p8 +GO +DROP FUNCTION test_conv_string_to_datetime2_f8() +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-prepare.out new file mode 100644 index 0000000000..9d01bcef73 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-prepare.out @@ -0,0 +1,101 @@ +CREATE VIEW test_conv_string_to_datetime2_v1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f1() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE PROCEDURE test_conv_string_to_datetime2_p2_2 as (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2_2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +END +GO + + +CREATE VIEW test_conv_string_to_datetime2_v3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f3() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f4() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f5() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f6() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f7() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to datetime2)~~ + +CREATE PROCEDURE test_conv_string_to_datetime2_p8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f8() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-verify.out b/test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-verify.out new file mode 100644 index 0000000000..754a90e706 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime2-before-14_5-vu-verify.out @@ -0,0 +1,1768 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIME2, '') +GO +~~START~~ +datetime2 +1900-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '', 130) +GO +~~START~~ +datetime2 +2464-12-29 00:00:00.0000000 +~~END~~ + + +-- -- Numeric +SELECT CONVERT(DATETIME2, '3-2-4 14:30') +GO +~~START~~ +datetime2 +2004-03-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3-12-4 14:30') +GO +~~START~~ +datetime2 +2004-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3-12-24 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3-12-2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 - 12 - 2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.2.4 14:30') +GO +~~START~~ +datetime2 +2004-03-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.12.4 14:30') +GO +~~START~~ +datetime2 +2004-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.12.24 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.12.2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 . 12 . 2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/2/4 14:30') +GO +~~START~~ +datetime2 +2004-03-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/12/4 14:30') +GO +~~START~~ +datetime2 +2004-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/12/24 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/12/2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 / 12 / 2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '04-02-03 14:30') +GO +~~START~~ +datetime2 +2003-04-02 14:30:00.0000000 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(DATETIME2, '3 12 2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '3#12#2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '3/12.2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Alphabetical +SELECT CONVERT(DATETIME2, 'Apr 12,2000 14:30') +GO +~~START~~ +datetime2 +2000-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1,2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16, 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1, 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'April 16, 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'April 16 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16, 24 14:30') +GO +~~START~~ +datetime2 +2024-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16,4 14:30') +GO +~~START~~ +datetime2 +2004-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1,4 14:30') +GO +~~START~~ +datetime2 +2004-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16 24 14:30') +GO +~~START~~ +datetime2 +2024-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16 4 14:30') +GO +~~START~~ +datetime2 +2004-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'April 16 14:30') +GO +~~START~~ +datetime2 +2016-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 22 14:30') +GO +~~START~~ +datetime2 +2024-04-22 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 2 14:30') +GO +~~START~~ +datetime2 +2024-04-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '24 Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-24 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 Apr 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3Apr2024 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3Apr24 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr24 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr,24 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '24 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 24 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 2024 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 12 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 9 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-09 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 Apr 12 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12, Apr, 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12 Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12, Apr 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, Apr, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024 Apr, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, Apr 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 12, 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 12 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 2024, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 2024 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12, 2024, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12 2024, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12, 2024 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, 12, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024 12, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, 12 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- ISO 8601 +SELECT CONVERT(DATETIME2, '2023-11-27') +GO +~~START~~ +datetime2 +2023-11-27 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123-12:12') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123+12:12') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2022-10 -30T03: 00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.12345') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1234500 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:12345') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Unseparated +SELECT CONVERT(DATETIME2, '20240129') +GO +~~START~~ +datetime2 +2024-01-29 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '240129') +GO +~~START~~ +datetime2 +2024-01-29 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '2001') +GO +~~START~~ +datetime2 +2001-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '0001') +GO +~~START~~ +datetime2 +0001-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20240129 03:00:00') +GO +~~START~~ +datetime2 +2024-01-29 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20241329 03:00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '240129 03:00') +GO +~~START~~ +datetime2 +2024-01-29 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '241329 03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '2001 03:00:00.123') +GO +~~START~~ +datetime2 +2001-01-01 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '0001 03:00:00.421') +GO +~~START~~ +datetime2 +0001-01-01 03:00:00.4210000 +~~END~~ + + +-- -- invalid syntax +SELECT CONVERT(DATETIME2, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- should return default DATETIME2 +SELECT CONVERT(DATETIME2, '16:23:51') +GO +~~START~~ +datetime2 +1900-01-01 16:23:51.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '4:12:12:123') +GO +~~START~~ +datetime2 +1900-01-01 04:12:12.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '4:12:12:1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '4:12:12.1234') +GO +~~START~~ +datetime2 +1900-01-01 04:12:12.1234000 +~~END~~ + + +-- hijri +SELECT CONVERT(DATETIME2, '20231229', 130) +GO +~~START~~ +datetime2 +2585-04-19 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20231230', 130) +GO +~~START~~ +datetime2 +2585-04-20 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20231129', 130) +GO +~~START~~ +datetime2 +2585-03-20 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20231130', 130) +GO +~~START~~ +datetime2 +2585-03-21 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime2 +2018-10-02 01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +datetime2 +2018-10-02 01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +datetime2 +2019-08-23 13:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 130) +GO +~~START~~ +datetime2 +2024-05-07 11:46:25.3470000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 131) +GO +~~START~~ +datetime2 +2024-05-07 11:46:25.3470000 +~~END~~ + + +-- -- hijri leap year +SELECT CONVERT(DATETIME2, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +-- rounding of DATETIME2 +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345679') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345678') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345677') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345676') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345675') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345674') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345673') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345672') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345671') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345670') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +-- DATETIME2 with typmod +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.501') +GO +~~START~~ +datetime2 +1998-01-01 23:59:57 +~~END~~ + + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.500') +GO +~~START~~ +datetime2 +1998-01-01 23:59:57 +~~END~~ + + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.499') +GO +~~START~~ +datetime2 +1998-01-01 23:59:56 +~~END~~ + + +SELECT CONVERT(DATETIME2(1), '01/01/98 23:59:59.123') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1 +~~END~~ + + +SELECT CONVERT(DATETIME2(2), '01/01/98 23:59:59.123') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.12 +~~END~~ + + +SELECT CONVERT(DATETIME2(3), '01/01/98 23:59:59.123') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.123 +~~END~~ + + +-- -- Boundary values +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999') +GO +~~START~~ +datetime2 +9999-12-31 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.99999999') +GO +~~START~~ +datetime2 +9999-12-31 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.999999999') +GO +~~START~~ +datetime2 +9999-12-31 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999') +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.99999999') +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.999999999') +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- -- out of bound values +SELECT CONVERT(DATETIME2,'2022-10-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2,'0000-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2,'2023-00-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2,'0000-00-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +datetime2 +2021-04-10 11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02/12/21', 1) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '21.02.12', 2) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12/02/21', 3) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12.02.21', 4) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12-02-21', 5) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 21', 6) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12, 21', 7) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '10:13:14', 8) +GO +~~START~~ +datetime2 +1900-01-01 10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '10:13:14', 24) +GO +~~START~~ +datetime2 +1900-01-01 10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +datetime2 +2021-04-12 10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02-12-21', 10) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '21/02/12', 11) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '210212', 12) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +datetime2 +2021-04-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '15:13:14:123', 14) +GO +~~START~~ +datetime2 +1900-01-01 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 20) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02/12/21 15:13:14 PM', 22) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12', 23) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 25) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +datetime2 +2021-04-10 11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02/12/2021', 101) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021.02.12', 102) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12/02/2021', 103) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12.02.2021', 104) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12-02-2021', 105) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 2021', 106) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12, 2021', 107) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '10:13:14', 108) +GO +~~START~~ +datetime2 +1900-01-01 10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +datetime2 +2021-04-12 10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02-12-2021', 110) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021/02/12', 111) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20210212', 112) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +datetime2 +2021-04-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '15:13:14:123', 114) +GO +~~START~~ +datetime2 +1900-01-01 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 120) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime2 +2018-10-02 01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +datetime2 +2582-07-04 15:13:14.1230000 +~~END~~ + + +--- misc +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime2 +2022-10-29 20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2020') +GO +~~START~~ +datetime2 +2020-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(DATETIME2, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '1900-05-06 13:59:29.050 -8:00') +GO +~~START~~ +datetime2 +1900-05-06 13:59:29.0500000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime2 +2022-10-29 20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2020') +GO +~~START~~ +datetime2 +2020-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +datetime2 +2021-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME2, @TM_ICLO) +GO +~~START~~ +datetime2 +1900-01-01 17:24:07.1766670 +~~END~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime2_v1 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime2_p1 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime2_f1() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v2 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.123457 +~~END~~ + +EXEC test_conv_string_to_datetime2_p2 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f2() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +EXEC test_conv_string_to_datetime2_p2_2 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Specified scale 10 is invalid. 'datetime2' datatype must have scale between 0 and 7)~~ + +SELECT test_conv_string_to_datetime2_f2_2() +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Specified scale 10 is invalid. 'datetime2' datatype must have scale between 0 and 7)~~ + + +SELECT * FROM test_conv_string_to_datetime2_v3 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.12346 +~~END~~ + +EXEC test_conv_string_to_datetime2_p3 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.12346 +~~END~~ + +SELECT test_conv_string_to_datetime2_f3() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234600 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v4 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.123457 +~~END~~ + +EXEC test_conv_string_to_datetime2_p4 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f4() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v5 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.123457 +~~END~~ + +EXEC test_conv_string_to_datetime2_p5 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f5() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v6 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.123457 +~~END~~ + +EXEC test_conv_string_to_datetime2_p6 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f6() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v7 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.123457 +~~END~~ + +EXEC test_conv_string_to_datetime2_p7 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f7() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "test_conv_string_to_datetime2_v8" does not exist)~~ + +EXEC test_conv_string_to_datetime2_p8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetime2 is not allowed.)~~ + +SELECT test_conv_string_to_datetime2_f8() +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetime2 is not allowed.)~~ + diff --git a/test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-cleanup.out new file mode 100644 index 0000000000..26b069f721 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-cleanup.out @@ -0,0 +1,64 @@ +DROP VIEW test_conv_string_to_datetime2_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p1 +GO +DROP FUNCTION test_conv_string_to_datetime2_f1() +GO + +DROP VIEW test_conv_string_to_datetime2_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2() +GO + +DROP PROCEDURE test_conv_string_to_datetime2_p2_2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2_2() +GO + +DROP VIEW test_conv_string_to_datetime2_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p3 +GO +DROP FUNCTION test_conv_string_to_datetime2_f3() +GO + +DROP VIEW test_conv_string_to_datetime2_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p4 +GO +DROP FUNCTION test_conv_string_to_datetime2_f4() +GO + +DROP VIEW test_conv_string_to_datetime2_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p5 +GO +DROP FUNCTION test_conv_string_to_datetime2_f5() +GO + +DROP VIEW test_conv_string_to_datetime2_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p6 +GO +DROP FUNCTION test_conv_string_to_datetime2_f6() +GO + +DROP VIEW test_conv_string_to_datetime2_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p7 +GO +DROP FUNCTION test_conv_string_to_datetime2_f7() +GO + +DROP VIEW test_conv_string_to_datetime2_v8 +GO +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: view "test_conv_string_to_datetime2_v8" does not exist)~~ + +DROP PROCEDURE test_conv_string_to_datetime2_p8 +GO +DROP FUNCTION test_conv_string_to_datetime2_f8() +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-prepare.out new file mode 100644 index 0000000000..9d01bcef73 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-prepare.out @@ -0,0 +1,101 @@ +CREATE VIEW test_conv_string_to_datetime2_v1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f1() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE PROCEDURE test_conv_string_to_datetime2_p2_2 as (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2_2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +END +GO + + +CREATE VIEW test_conv_string_to_datetime2_v3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f3() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f4() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f5() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f6() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f7() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to datetime2)~~ + +CREATE PROCEDURE test_conv_string_to_datetime2_p8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f8() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-verify.out b/test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-verify.out new file mode 100644 index 0000000000..aab7a85472 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime2-before-17_3-vu-verify.out @@ -0,0 +1,1768 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIME2, '') +GO +~~START~~ +datetime2 +1900-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '', 130) +GO +~~START~~ +datetime2 +2464-12-29 00:00:00.0000000 +~~END~~ + + +-- -- Numeric +SELECT CONVERT(DATETIME2, '3-2-4 14:30') +GO +~~START~~ +datetime2 +2004-03-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3-12-4 14:30') +GO +~~START~~ +datetime2 +2004-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3-12-24 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3-12-2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 - 12 - 2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.2.4 14:30') +GO +~~START~~ +datetime2 +2004-03-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.12.4 14:30') +GO +~~START~~ +datetime2 +2004-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.12.24 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.12.2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 . 12 . 2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/2/4 14:30') +GO +~~START~~ +datetime2 +2004-03-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/12/4 14:30') +GO +~~START~~ +datetime2 +2004-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/12/24 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/12/2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 / 12 / 2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '04-02-03 14:30') +GO +~~START~~ +datetime2 +2003-04-02 14:30:00.0000000 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(DATETIME2, '3 12 2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '3#12#2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '3/12.2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Alphabetical +SELECT CONVERT(DATETIME2, 'Apr 12,2000 14:30') +GO +~~START~~ +datetime2 +2000-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1,2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16, 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1, 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'April 16, 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'April 16 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16, 24 14:30') +GO +~~START~~ +datetime2 +2024-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16,4 14:30') +GO +~~START~~ +datetime2 +2004-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1,4 14:30') +GO +~~START~~ +datetime2 +2004-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16 24 14:30') +GO +~~START~~ +datetime2 +2024-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16 4 14:30') +GO +~~START~~ +datetime2 +2004-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'April 16 14:30') +GO +~~START~~ +datetime2 +2016-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 22 14:30') +GO +~~START~~ +datetime2 +2024-04-22 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 2 14:30') +GO +~~START~~ +datetime2 +2024-04-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '24 Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-24 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 Apr 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3Apr2024 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3Apr24 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr24 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr,24 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '24 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 24 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 2024 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 12 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 9 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-09 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 Apr 12 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12, Apr, 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12 Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12, Apr 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, Apr, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024 Apr, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, Apr 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 12, 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 12 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 2024, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 2024 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12, 2024, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12 2024, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12, 2024 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, 12, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024 12, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, 12 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- ISO 8601 +SELECT CONVERT(DATETIME2, '2023-11-27') +GO +~~START~~ +datetime2 +2023-11-27 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123-12:12') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123+12:12') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2022-10 -30T03: 00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.12345') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1234500 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:12345') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Unseparated +SELECT CONVERT(DATETIME2, '20240129') +GO +~~START~~ +datetime2 +2024-01-29 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '240129') +GO +~~START~~ +datetime2 +2024-01-29 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '2001') +GO +~~START~~ +datetime2 +2001-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '0001') +GO +~~START~~ +datetime2 +0001-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20240129 03:00:00') +GO +~~START~~ +datetime2 +2024-01-29 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20241329 03:00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '240129 03:00') +GO +~~START~~ +datetime2 +2024-01-29 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '241329 03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '2001 03:00:00.123') +GO +~~START~~ +datetime2 +2001-01-01 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '0001 03:00:00.421') +GO +~~START~~ +datetime2 +0001-01-01 03:00:00.4210000 +~~END~~ + + +-- -- invalid syntax +SELECT CONVERT(DATETIME2, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- should return default DATETIME2 +SELECT CONVERT(DATETIME2, '16:23:51') +GO +~~START~~ +datetime2 +1900-01-01 16:23:51.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '4:12:12:123') +GO +~~START~~ +datetime2 +1900-01-01 04:12:12.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '4:12:12:1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '4:12:12.1234') +GO +~~START~~ +datetime2 +1900-01-01 04:12:12.1234000 +~~END~~ + + +-- hijri +SELECT CONVERT(DATETIME2, '20231229', 130) +GO +~~START~~ +datetime2 +2585-04-19 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20231230', 130) +GO +~~START~~ +datetime2 +2585-04-20 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20231129', 130) +GO +~~START~~ +datetime2 +2585-03-20 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20231130', 130) +GO +~~START~~ +datetime2 +2585-03-21 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime2 +2018-10-02 01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +datetime2 +2018-10-02 01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +datetime2 +2019-08-23 13:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 130) +GO +~~START~~ +datetime2 +2024-05-07 11:46:25.3470000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 131) +GO +~~START~~ +datetime2 +2024-05-07 11:46:25.3470000 +~~END~~ + + +-- -- hijri leap year +SELECT CONVERT(DATETIME2, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +-- rounding of DATETIME2 +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345679') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345678') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345677') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345676') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345675') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345674') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345673') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345672') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345671') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345670') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +-- DATETIME2 with typmod +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.501') +GO +~~START~~ +datetime2 +1998-01-01 23:59:57 +~~END~~ + + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.500') +GO +~~START~~ +datetime2 +1998-01-01 23:59:57 +~~END~~ + + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.499') +GO +~~START~~ +datetime2 +1998-01-01 23:59:56 +~~END~~ + + +SELECT CONVERT(DATETIME2(1), '01/01/98 23:59:59.123') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1 +~~END~~ + + +SELECT CONVERT(DATETIME2(2), '01/01/98 23:59:59.123') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.12 +~~END~~ + + +SELECT CONVERT(DATETIME2(3), '01/01/98 23:59:59.123') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.123 +~~END~~ + + +-- -- Boundary values +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999') +GO +~~START~~ +datetime2 +9999-12-31 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.99999999') +GO +~~START~~ +datetime2 +9999-12-31 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.999999999') +GO +~~START~~ +datetime2 +9999-12-31 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999') +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.99999999') +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.999999999') +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- -- out of bound values +SELECT CONVERT(DATETIME2,'2022-10-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2,'0000-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2,'2023-00-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2,'0000-00-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +datetime2 +2021-04-10 11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02/12/21', 1) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '21.02.12', 2) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12/02/21', 3) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12.02.21', 4) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12-02-21', 5) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 21', 6) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12, 21', 7) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '10:13:14', 8) +GO +~~START~~ +datetime2 +1900-01-01 10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '10:13:14', 24) +GO +~~START~~ +datetime2 +1900-01-01 10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +datetime2 +2021-04-12 10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02-12-21', 10) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '21/02/12', 11) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '210212', 12) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +datetime2 +2021-04-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '15:13:14:123', 14) +GO +~~START~~ +datetime2 +1900-01-01 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 20) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02/12/21 15:13:14 PM', 22) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12', 23) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 25) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +datetime2 +2021-04-10 11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02/12/2021', 101) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021.02.12', 102) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12/02/2021', 103) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12.02.2021', 104) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12-02-2021', 105) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 2021', 106) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12, 2021', 107) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '10:13:14', 108) +GO +~~START~~ +datetime2 +1900-01-01 10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +datetime2 +2021-04-12 10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02-12-2021', 110) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021/02/12', 111) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20210212', 112) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +datetime2 +2021-04-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '15:13:14:123', 114) +GO +~~START~~ +datetime2 +1900-01-01 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 120) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime2 +2018-10-02 01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +datetime2 +2582-07-04 15:13:14.1230000 +~~END~~ + + +--- misc +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime2 +2022-10-29 20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2020') +GO +~~START~~ +datetime2 +2020-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(DATETIME2, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '1900-05-06 13:59:29.050 -8:00') +GO +~~START~~ +datetime2 +1900-05-06 13:59:29.0500000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime2 +2022-10-29 20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2020') +GO +~~START~~ +datetime2 +2020-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +datetime2 +2021-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME2, @TM_ICLO) +GO +~~START~~ +datetime2 +1900-01-01 17:24:07.1766670 +~~END~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime2_v1 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime2_p1 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime2_f1() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v2 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +EXEC test_conv_string_to_datetime2_p2 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f2() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +EXEC test_conv_string_to_datetime2_p2_2 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Specified scale 10 is invalid. 'datetime2' datatype must have scale between 0 and 7)~~ + +SELECT test_conv_string_to_datetime2_f2_2() +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Specified scale 10 is invalid. 'datetime2' datatype must have scale between 0 and 7)~~ + + +SELECT * FROM test_conv_string_to_datetime2_v3 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.12346 +~~END~~ + +EXEC test_conv_string_to_datetime2_p3 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.12346 +~~END~~ + +SELECT test_conv_string_to_datetime2_f3() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234600 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v4 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +EXEC test_conv_string_to_datetime2_p4 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f4() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v5 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +EXEC test_conv_string_to_datetime2_p5 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f5() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v6 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +EXEC test_conv_string_to_datetime2_p6 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f6() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v7 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +EXEC test_conv_string_to_datetime2_p7 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f7() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "test_conv_string_to_datetime2_v8" does not exist)~~ + +EXEC test_conv_string_to_datetime2_p8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetime2 is not allowed.)~~ + +SELECT test_conv_string_to_datetime2_f8() +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetime2 is not allowed.)~~ + diff --git a/test/JDBC/expected/test_conv_string_to_datetime2-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_datetime2-vu-cleanup.out new file mode 100644 index 0000000000..e9e44fd452 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime2-vu-cleanup.out @@ -0,0 +1,60 @@ +DROP VIEW test_conv_string_to_datetime2_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p1 +GO +DROP FUNCTION test_conv_string_to_datetime2_f1() +GO + +DROP VIEW test_conv_string_to_datetime2_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2() +GO + +DROP PROCEDURE test_conv_string_to_datetime2_p2_2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2_2() +GO + +DROP VIEW test_conv_string_to_datetime2_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p3 +GO +DROP FUNCTION test_conv_string_to_datetime2_f3() +GO + +DROP VIEW test_conv_string_to_datetime2_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p4 +GO +DROP FUNCTION test_conv_string_to_datetime2_f4() +GO + +DROP VIEW test_conv_string_to_datetime2_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p5 +GO +DROP FUNCTION test_conv_string_to_datetime2_f5() +GO + +DROP VIEW test_conv_string_to_datetime2_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p6 +GO +DROP FUNCTION test_conv_string_to_datetime2_f6() +GO + +DROP VIEW test_conv_string_to_datetime2_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p7 +GO +DROP FUNCTION test_conv_string_to_datetime2_f7() +GO + +DROP VIEW test_conv_string_to_datetime2_v8 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p8 +GO +DROP FUNCTION test_conv_string_to_datetime2_f8() +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime2-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_datetime2-vu-prepare.out new file mode 100644 index 0000000000..19948dc11c --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime2-vu-prepare.out @@ -0,0 +1,97 @@ +CREATE VIEW test_conv_string_to_datetime2_v1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f1() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE PROCEDURE test_conv_string_to_datetime2_p2_2 as (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2_2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +END +GO + + +CREATE VIEW test_conv_string_to_datetime2_v3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f3() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f4() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f5() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f6() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f7() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f8() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetime2-vu-verify.out b/test/JDBC/expected/test_conv_string_to_datetime2-vu-verify.out new file mode 100644 index 0000000000..c2f2dca720 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetime2-vu-verify.out @@ -0,0 +1,1768 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIME2, '') +GO +~~START~~ +datetime2 +1900-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '', 130) +GO +~~START~~ +datetime2 +2464-12-29 00:00:00.0000000 +~~END~~ + + +-- -- Numeric +SELECT CONVERT(DATETIME2, '3-2-4 14:30') +GO +~~START~~ +datetime2 +2004-03-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3-12-4 14:30') +GO +~~START~~ +datetime2 +2004-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3-12-24 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3-12-2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 - 12 - 2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.2.4 14:30') +GO +~~START~~ +datetime2 +2004-03-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.12.4 14:30') +GO +~~START~~ +datetime2 +2004-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.12.24 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3.12.2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 . 12 . 2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/2/4 14:30') +GO +~~START~~ +datetime2 +2004-03-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/12/4 14:30') +GO +~~START~~ +datetime2 +2004-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/12/24 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3/12/2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 / 12 / 2024 14:30') +GO +~~START~~ +datetime2 +2024-03-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '04-02-03 14:30') +GO +~~START~~ +datetime2 +2003-04-02 14:30:00.0000000 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(DATETIME2, '3 12 2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '3#12#2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '3/12.2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Alphabetical +SELECT CONVERT(DATETIME2, 'Apr 12,2000 14:30') +GO +~~START~~ +datetime2 +2000-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1,2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16, 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1, 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'April 16, 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'April 16 2000 14:30') +GO +~~START~~ +datetime2 +2000-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16, 24 14:30') +GO +~~START~~ +datetime2 +2024-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16,4 14:30') +GO +~~START~~ +datetime2 +2004-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 1,4 14:30') +GO +~~START~~ +datetime2 +2004-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16 24 14:30') +GO +~~START~~ +datetime2 +2024-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 16 4 14:30') +GO +~~START~~ +datetime2 +2004-04-16 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'April 16 14:30') +GO +~~START~~ +datetime2 +2016-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 22 14:30') +GO +~~START~~ +datetime2 +2024-04-22 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 2 14:30') +GO +~~START~~ +datetime2 +2024-04-02 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '24 Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-24 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3 Apr 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3Apr2024 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '3Apr24 14:30') +GO +~~START~~ +datetime2 +2024-04-03 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr24 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr,24 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '24 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 24 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 2024 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-01 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 12 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 9 Apr 14:30') +GO +~~START~~ +datetime2 +2024-04-09 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2024 Apr 12 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12, Apr, 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12 Apr, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12, Apr 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, Apr, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024 Apr, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, Apr 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 12, 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12, 2024 14:30') +GO +~~START~~ +datetime2 +2024-04-12 14:30:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 12 2024 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 2024, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr 2024, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, 'Apr, 2024 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12, 2024, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12 2024, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '12, 2024 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, 12, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024 12, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2024, 12 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- ISO 8601 +SELECT CONVERT(DATETIME2, '2023-11-27') +GO +~~START~~ +datetime2 +2023-11-27 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123-12:12') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123+12:12') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2022-10 -30T03: 00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.12345') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.1234500 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:12345') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Unseparated +SELECT CONVERT(DATETIME2, '20240129') +GO +~~START~~ +datetime2 +2024-01-29 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '240129') +GO +~~START~~ +datetime2 +2024-01-29 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '2001') +GO +~~START~~ +datetime2 +2001-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '0001') +GO +~~START~~ +datetime2 +0001-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20240129 03:00:00') +GO +~~START~~ +datetime2 +2024-01-29 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20241329 03:00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '240129 03:00') +GO +~~START~~ +datetime2 +2024-01-29 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '241329 03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2, '2001 03:00:00.123') +GO +~~START~~ +datetime2 +2001-01-01 03:00:00.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '0001 03:00:00.421') +GO +~~START~~ +datetime2 +0001-01-01 03:00:00.4210000 +~~END~~ + + +-- -- invalid syntax +SELECT CONVERT(DATETIME2, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- should return default DATETIME2 +SELECT CONVERT(DATETIME2, '16:23:51') +GO +~~START~~ +datetime2 +1900-01-01 16:23:51.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '4:12:12:123') +GO +~~START~~ +datetime2 +1900-01-01 04:12:12.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '4:12:12:1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '4:12:12.1234') +GO +~~START~~ +datetime2 +1900-01-01 04:12:12.1234000 +~~END~~ + + +-- hijri +SELECT CONVERT(DATETIME2, '20231229', 130) +GO +~~START~~ +datetime2 +2585-04-19 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20231230', 130) +GO +~~START~~ +datetime2 +2585-04-20 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20231129', 130) +GO +~~START~~ +datetime2 +2585-03-20 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20231130', 130) +GO +~~START~~ +datetime2 +2585-03-21 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime2 +2018-10-02 01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +datetime2 +2018-10-02 01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +datetime2 +2019-08-23 13:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 130) +GO +~~START~~ +datetime2 +2024-05-07 11:46:25.3470000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 131) +GO +~~START~~ +datetime2 +2024-05-07 11:46:25.3470000 +~~END~~ + + +-- -- hijri leap year +SELECT CONVERT(DATETIME2, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +-- rounding of DATETIME2 +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345679') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345678') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345677') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345676') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345675') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345674') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345673') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345672') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345671') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345670') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1234570 +~~END~~ + + +-- DATETIME2 with typmod +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.501') +GO +~~START~~ +datetime2 +1998-01-01 23:59:57 +~~END~~ + + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.500') +GO +~~START~~ +datetime2 +1998-01-01 23:59:57 +~~END~~ + + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.499') +GO +~~START~~ +datetime2 +1998-01-01 23:59:56 +~~END~~ + + +SELECT CONVERT(DATETIME2(1), '01/01/98 23:59:59.123') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.1 +~~END~~ + + +SELECT CONVERT(DATETIME2(2), '01/01/98 23:59:59.123') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.12 +~~END~~ + + +SELECT CONVERT(DATETIME2(3), '01/01/98 23:59:59.123') +GO +~~START~~ +datetime2 +1998-01-01 23:59:59.123 +~~END~~ + + +-- -- Boundary values +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999') +GO +~~START~~ +datetime2 +9999-12-31 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.99999999') +GO +~~START~~ +datetime2 +9999-12-31 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.999999999') +GO +~~START~~ +datetime2 +9999-12-31 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999') +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.99999999') +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.999999999') +GO +~~START~~ +datetime2 +9999-12-31 23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- -- out of bound values +SELECT CONVERT(DATETIME2,'2022-10-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2,'0000-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2,'2023-00-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIME2,'0000-00-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetime2 data type resulted in an out-of-range value.)~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +datetime2 +2021-04-10 11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02/12/21', 1) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '21.02.12', 2) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12/02/21', 3) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12.02.21', 4) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12-02-21', 5) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 21', 6) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12, 21', 7) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '10:13:14', 8) +GO +~~START~~ +datetime2 +1900-01-01 10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '10:13:14', 24) +GO +~~START~~ +datetime2 +1900-01-01 10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +datetime2 +2021-04-12 10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02-12-21', 10) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '21/02/12', 11) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '210212', 12) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +datetime2 +2021-04-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '15:13:14:123', 14) +GO +~~START~~ +datetime2 +1900-01-01 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 20) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02/12/21 15:13:14 PM', 22) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12', 23) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 25) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +datetime2 +2021-04-10 11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02/12/2021', 101) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021.02.12', 102) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12/02/2021', 103) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12.02.2021', 104) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12-02-2021', 105) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 2021', 106) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12, 2021', 107) +GO +~~START~~ +datetime2 +2021-04-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '10:13:14', 108) +GO +~~START~~ +datetime2 +1900-01-01 10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +datetime2 +2021-04-12 10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '02-12-2021', 110) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021/02/12', 111) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '20210212', 112) +GO +~~START~~ +datetime2 +2021-02-12 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +datetime2 +2021-04-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '15:13:14:123', 114) +GO +~~START~~ +datetime2 +1900-01-01 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 120) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +datetime2 +2021-02-12 15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetime2 +2018-10-02 01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +datetime2 +2582-07-04 15:13:14.1230000 +~~END~~ + + +--- misc +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime2 +2022-10-29 20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2020') +GO +~~START~~ +datetime2 +2020-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(DATETIME2, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '1900-05-06 13:59:29.050 -8:00') +GO +~~START~~ +datetime2 +1900-05-06 13:59:29.0500000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetime2 +2022-10-29 20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2020') +GO +~~START~~ +datetime2 +2020-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO +~~START~~ +datetime2 +2022-10-30 03:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +datetime2 +2021-01-01 00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME2, @TM_ICLO) +GO +~~START~~ +datetime2 +1900-01-01 17:24:07.1766670 +~~END~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime2_v1 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0 +~~END~~ + +EXEC test_conv_string_to_datetime2_p1 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0 +~~END~~ + +SELECT test_conv_string_to_datetime2_f1() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v2 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +EXEC test_conv_string_to_datetime2_p2 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f2() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +EXEC test_conv_string_to_datetime2_p2_2 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Specified scale 10 is invalid. 'datetime2' datatype must have scale between 0 and 7)~~ + +SELECT test_conv_string_to_datetime2_f2_2() +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Specified scale 10 is invalid. 'datetime2' datatype must have scale between 0 and 7)~~ + + +SELECT * FROM test_conv_string_to_datetime2_v3 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.12346 +~~END~~ + +EXEC test_conv_string_to_datetime2_p3 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.12346 +~~END~~ + +SELECT test_conv_string_to_datetime2_f3() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234600 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v4 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +EXEC test_conv_string_to_datetime2_p4 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f4() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v5 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +EXEC test_conv_string_to_datetime2_p5 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f5() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v6 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +EXEC test_conv_string_to_datetime2_p6 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f6() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v7 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +EXEC test_conv_string_to_datetime2_p7 +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + +SELECT test_conv_string_to_datetime2_f7() +GO +~~START~~ +datetime2 +2017-08-25 13:01:59.1234570 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetime2_v8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetime2 is not allowed.)~~ + +EXEC test_conv_string_to_datetime2_p8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetime2 is not allowed.)~~ + +SELECT test_conv_string_to_datetime2_f8() +GO +~~START~~ +datetime2 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetime2 is not allowed.)~~ + diff --git a/test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-cleanup.out new file mode 100644 index 0000000000..e679d34c36 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-cleanup.out @@ -0,0 +1,52 @@ +DROP VIEW test_conv_string_to_datetimeoffset_v1 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p1 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f1() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v2 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p2 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f2() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v3 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p3 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f3() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v4 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p4 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f4() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v5 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p5 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f5() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v6 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p6 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f6() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v7 +GO +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: view "test_conv_string_to_datetimeoffset_v7" does not exist)~~ + +DROP PROCEDURE test_conv_string_to_datetimeoffset_p7 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f7() +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-prepare.out new file mode 100644 index 0000000000..7d26551b1c --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-prepare.out @@ -0,0 +1,80 @@ +CREATE VIEW test_conv_string_to_datetimeoffset_v1 as (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p1 as (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f1() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v2 as (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p2 as (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f2() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v3 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p3 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f3() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v4 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p4 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f4() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v5 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p5 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f5() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v6 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p6 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f6() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v7 as (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to datetimeoffset)~~ + +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p7 as (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f7() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-verify.out b/test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-verify.out new file mode 100644 index 0000000000..040328e76f --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetimeoffset-before-17_3-vu-verify.out @@ -0,0 +1,1893 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIMEOFFSET, '') +GO +~~START~~ +datetimeoffset +1900-01-01 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '', 130) +GO +~~START~~ +datetimeoffset +2464-12-29 00:00:00.0000000 +00:00 +~~END~~ + + +-- -- Numeric +SELECT CONVERT(DATETIMEOFFSET, '3-2-4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-03-02 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3-12-4 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2004-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3-12-24 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3-12-2024 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3 - 12 - 2024 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3.2.4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-03-02 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3.12.4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3.12.24 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3.12.2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3 . 12 . 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3/2/4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-03-02 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3/12/4 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2004-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3/12/24 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3/12/2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3 / 12 / 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '04-02-03 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2003-04-02 14:30:00.0000000 -08:00 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(DATETIMEOFFSET, '3 12 2024 +8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3#12#2024 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3/12.2024 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Alphabetical +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12,2000 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2000-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2000 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2000-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1 2000 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2000-04-01 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1,2000 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2000-04-01 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2000 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2000-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16, 2000 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2000-04-16 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1, 2000 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2000-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'April 16, 2000 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2000-04-16 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'April 16 2000 14:30Z') +GO +~~START~~ +datetimeoffset +2000-04-16 14:30:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16, 24 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-16 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16,4 14:30Z') +GO +~~START~~ +datetimeoffset +2004-04-16 14:30:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1,4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16 24 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-16 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16 4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-04-16 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'April 16 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2016-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 14:30Z') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 22 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-22 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 2 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-02 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '24 Apr, 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-24 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3 Apr, 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-03 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3 Apr 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-03 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3Apr2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-03 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3Apr24 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-03 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr24 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr,24 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '24 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 24 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 2024 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 12 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 9 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-09 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr 12 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12, Apr, 2024 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr, 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12, Apr 2024 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024, Apr, 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr, 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024, Apr 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 12, 2024 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 12 2024 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024, 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024, 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12, 2024, Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 2024, Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12, 2024 Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024, 12, Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 12, Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024, 12 Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- W3C XML +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- ISO 8601 +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 -12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 +12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 -12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 +12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27Z') +GO +~~START~~ +datetimeoffset +2023-11-27 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00Z') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123Z') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 -12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 +12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345Z') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1234500 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +-- Unseparated +SELECT CONVERT(DATETIMEOFFSET, '20240129 +8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20241329 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '240129 Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '241329 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2001 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '0001 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20240129 03:00:00 -8:00') +GO +~~START~~ +datetimeoffset +2024-01-29 03:00:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20241329 03:00:00 +8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '240129 03:00 Z') +GO +~~START~~ +datetimeoffset +2024-01-29 03:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '241329 03:00 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2001 03:00:00.123 -8:00') +GO +~~START~~ +datetimeoffset +2001-01-01 03:00:00.1230000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '0001 03:00:00.421Z') +GO +~~START~~ +datetimeoffset +0001-01-01 03:00:00.4210000 +00:00 +~~END~~ + + +-- -- invalid syntax +SELECT CONVERT(DATETIMEOFFSET, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- should return default DATETIMEOFFSET +SELECT CONVERT(DATETIMEOFFSET, '16:23:51 -8:00') +GO +~~START~~ +datetimeoffset +1900-01-01 16:23:51.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12:123 -8:00') +GO +~~START~~ +datetimeoffset +1900-01-01 04:12:12.1230000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12:1234 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12.1234 -8:00') +GO +~~START~~ +datetimeoffset +1900-01-01 04:12:12.1234000 -08:00 +~~END~~ + + +-- hijri +SELECT CONVERT(DATETIMEOFFSET, '20231229', 130) +GO +~~START~~ +datetimeoffset +2585-04-19 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20231230', 130) +GO +~~START~~ +datetimeoffset +2585-04-20 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20231129', 130) +GO +~~START~~ +datetimeoffset +2585-03-20 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20231130', 130) +GO +~~START~~ +datetimeoffset +2585-03-21 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetimeoffset +2018-10-02 01:39:17.0900000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +datetimeoffset +2018-10-02 01:39:17.0900000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '22/12/1440 1:39:17.090PM', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +datetimeoffset +2019-08-23 13:39:17.0900000 +00:00 +~~END~~ + + +-- -- hijri leap year +SELECT CONVERT(DATETIMEOFFSET, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +-- rounding of DATETIMEOFFSET +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345679 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345678 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345677 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345676 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345675 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345674 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345673 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345672 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345671 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345670 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +-- DATETIMEOFFSET with typmod +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.501') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:57 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.500') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:57 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.499') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:56 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET(1), '01/01/98 23:59:59.123') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET(2), '01/01/98 23:59:59.123') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.12 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET(3), '01/01/98 23:59:59.123') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.123 +00:00 +~~END~~ + + +-- -- Boundary values +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.9999999') +GO +~~START~~ +datetimeoffset +9999-12-31 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.99999999') +GO +~~START~~ +datetimeoffset +9999-12-31 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.999999999') +GO +~~START~~ +datetimeoffset +9999-12-31 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.9999999') +GO +~~START~~ +datetimeoffset +9999-12-31 23:59:59.9999990 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.99999999') +GO +~~START~~ +datetimeoffset +9999-12-31 23:59:59.9999990 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.999999999') +GO +~~START~~ +datetimeoffset +9999-12-31 23:59:59.9999990 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- -- out of bound values +SELECT CONVERT(DATETIMEOFFSET,'2022-10-00 23:59:59.990 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'0000-10-01 23:59:59.990 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'2023-00-01 23:59:59.990 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'0000-00-00 23:59:59.990 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-21 23:59:59.990 +14:01') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-21 23:59:59.990 -15:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIMEOFFSET, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +datetimeoffset +2021-04-10 11:12:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02/12/21', 1) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '21.02.12', 2) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12/02/21', 3) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12.02.21', 4) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12-02-21', 5) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 21', 6) +GO +~~START~~ +datetimeoffset +2021-04-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 21', 7) +GO +~~START~~ +datetimeoffset +2021-04-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 8) +GO +~~START~~ +datetimeoffset +1900-01-01 10:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 24) +GO +~~START~~ +datetimeoffset +1900-01-01 10:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +datetimeoffset +2021-04-12 10:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02-12-21', 10) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '21/02/12', 11) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '210212', 12) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +datetimeoffset +2021-04-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '15:13:14:123', 14) +GO +~~START~~ +datetimeoffset +1900-01-01 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14', 20) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02/12/21 15:13:14 PM', 22) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12', 23) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 25) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +datetimeoffset +2021-04-10 11:12:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02/12/2021', 101) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021.02.12', 102) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12/02/2021', 103) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12.02.2021', 104) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12-02-2021', 105) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021', 106) +GO +~~START~~ +datetimeoffset +2021-04-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 2021', 107) +GO +~~START~~ +datetimeoffset +2021-04-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 108) +GO +~~START~~ +datetimeoffset +1900-01-01 10:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +datetimeoffset +2021-04-12 10:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02-12-2021', 110) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021/02/12', 111) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20210212', 112) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +datetimeoffset +2021-04-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '15:13:14:123', 114) +GO +~~START~~ +datetimeoffset +1900-01-01 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14', 120) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetimeoffset +2018-10-02 01:39:17.0900000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +datetimeoffset +2582-07-04 15:13:14.1230000 +00:00 +~~END~~ + + +--- misc +SELECT CONVERT(DATETIMEOFFSET,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetimeoffset +2022-10-29 20:01:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2020') +GO +~~START~~ +datetimeoffset +2020-01-01 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(DATETIMEOFFSET, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '1900-05-06 13:59:29.050 -8:00') +GO +~~START~~ +datetimeoffset +1900-05-06 13:59:29.0500000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetimeoffset +2022-10-29 20:01:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2020') +GO +~~START~~ +datetimeoffset +2020-01-01 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +datetimeoffset +2021-01-01 00:00:00.0000000 +12:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIMEOFFSET, @TM_ICLO) +GO +~~START~~ +datetimeoffset +1900-01-01 17:24:07.1766670 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '1900-05-06 13:59:29.050') +GO +~~START~~ +datetimeoffset +1900-05-06 13:59:29.0500000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2000-04-22 16:23:51.7668c0 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetimeoffset_v1 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p1 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f1() +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v2 +GO +~~START~~ +datetimeoffset +1900-01-01 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p2 +GO +~~START~~ +datetimeoffset +1900-01-01 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f2() +GO +~~START~~ +datetimeoffset +1900-01-01 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v3 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p3 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f3() +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v4 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p4 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f4() +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v5 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p5 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f5() +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v6 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p6 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f6() +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v7 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "test_conv_string_to_datetimeoffset_v7" does not exist)~~ + +EXEC test_conv_string_to_datetimeoffset_p7 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetimeoffset is not allowed.)~~ + +SELECT test_conv_string_to_datetimeoffset_f7() +GO +~~START~~ +datetimeoffset +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetimeoffset is not allowed.)~~ + diff --git a/test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-cleanup.out new file mode 100644 index 0000000000..751e44c265 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-cleanup.out @@ -0,0 +1,48 @@ +DROP VIEW test_conv_string_to_datetimeoffset_v1 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p1 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f1() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v2 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p2 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f2() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v3 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p3 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f3() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v4 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p4 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f4() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v5 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p5 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f5() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v6 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p6 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f6() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v7 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p7 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f7() +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-prepare.out new file mode 100644 index 0000000000..809c7e2ac9 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-prepare.out @@ -0,0 +1,76 @@ +CREATE VIEW test_conv_string_to_datetimeoffset_v1 as (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p1 as (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f1() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v2 as (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p2 as (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f2() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v3 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p3 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f3() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v4 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p4 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f4() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v5 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p5 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f5() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v6 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p6 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f6() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v7 as (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p7 as (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f7() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-verify.out b/test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-verify.out new file mode 100644 index 0000000000..166b92c707 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_datetimeoffset-vu-verify.out @@ -0,0 +1,1893 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIMEOFFSET, '') +GO +~~START~~ +datetimeoffset +1900-01-01 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '', 130) +GO +~~START~~ +datetimeoffset +2464-12-29 00:00:00.0000000 +00:00 +~~END~~ + + +-- -- Numeric +SELECT CONVERT(DATETIMEOFFSET, '3-2-4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-03-02 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3-12-4 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2004-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3-12-24 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3-12-2024 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3 - 12 - 2024 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3.2.4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-03-02 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3.12.4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3.12.24 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3.12.2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3 . 12 . 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3/2/4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-03-02 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3/12/4 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2004-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3/12/24 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3/12/2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3 / 12 / 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-03-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '04-02-03 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2003-04-02 14:30:00.0000000 -08:00 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(DATETIMEOFFSET, '3 12 2024 +8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3#12#2024 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3/12.2024 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Alphabetical +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12,2000 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2000-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2000 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2000-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1 2000 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2000-04-01 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1,2000 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2000-04-01 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2000 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2000-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16, 2000 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2000-04-16 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1, 2000 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2000-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'April 16, 2000 14:30 +8:00') +GO +~~START~~ +datetimeoffset +2000-04-16 14:30:00.0000000 +08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'April 16 2000 14:30Z') +GO +~~START~~ +datetimeoffset +2000-04-16 14:30:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16, 24 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-16 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16,4 14:30Z') +GO +~~START~~ +datetimeoffset +2004-04-16 14:30:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1,4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16 24 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-16 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16 4 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2004-04-16 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'April 16 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2016-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 14:30Z') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 22 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-22 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 2 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-02 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '24 Apr, 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-24 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3 Apr, 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-03 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3 Apr 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-03 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3Apr2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-03 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '3Apr24 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-03 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr24 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr,24 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '24 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 24 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 2024 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-01 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 12 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 9 Apr 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-09 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr 12 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12, Apr, 2024 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr, 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12, Apr 2024 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024, Apr, 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr, 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024, Apr 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 12, 2024 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 2024 14:30 -8:00') +GO +~~START~~ +datetimeoffset +2024-04-12 14:30:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 12 2024 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024, 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024, 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024 12 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12, 2024, Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 2024, Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12, 2024 Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024, 12, Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024 12, Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2024, 12 Apr 14:30 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- W3C XML +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- ISO 8601 +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 -12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 +12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345-8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 -12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 +12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345+8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27Z') +GO +~~START~~ +datetimeoffset +2023-11-27 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00Z') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123Z') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 -12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1230000 +12:12 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345Z') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.1234500 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +-- Unseparated +SELECT CONVERT(DATETIMEOFFSET, '20240129 +8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20241329 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '240129 Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '241329 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2001 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '0001 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20240129 03:00:00 -8:00') +GO +~~START~~ +datetimeoffset +2024-01-29 03:00:00.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20241329 03:00:00 +8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '240129 03:00 Z') +GO +~~START~~ +datetimeoffset +2024-01-29 03:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '241329 03:00 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2001 03:00:00.123 -8:00') +GO +~~START~~ +datetimeoffset +2001-01-01 03:00:00.1230000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '0001 03:00:00.421Z') +GO +~~START~~ +datetimeoffset +0001-01-01 03:00:00.4210000 +00:00 +~~END~~ + + +-- -- invalid syntax +SELECT CONVERT(DATETIMEOFFSET, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- should return default DATETIMEOFFSET +SELECT CONVERT(DATETIMEOFFSET, '16:23:51 -8:00') +GO +~~START~~ +datetimeoffset +1900-01-01 16:23:51.0000000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12:123 -8:00') +GO +~~START~~ +datetimeoffset +1900-01-01 04:12:12.1230000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12:1234 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12.1234 -8:00') +GO +~~START~~ +datetimeoffset +1900-01-01 04:12:12.1234000 -08:00 +~~END~~ + + +-- hijri +SELECT CONVERT(DATETIMEOFFSET, '20231229', 130) +GO +~~START~~ +datetimeoffset +2585-04-19 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20231230', 130) +GO +~~START~~ +datetimeoffset +2585-04-20 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20231129', 130) +GO +~~START~~ +datetimeoffset +2585-03-20 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20231130', 130) +GO +~~START~~ +datetimeoffset +2585-03-21 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetimeoffset +2018-10-02 01:39:17.0900000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +datetimeoffset +2018-10-02 01:39:17.0900000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '22/12/1440 1:39:17.090PM', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +datetimeoffset +2019-08-23 13:39:17.0900000 +00:00 +~~END~~ + + +-- -- hijri leap year +SELECT CONVERT(DATETIMEOFFSET, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +-- rounding of DATETIMEOFFSET +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345679 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345678 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345677 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345676 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345675 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345674 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345673 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345672 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345671 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345670 -8:00') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1234570 -08:00 +~~END~~ + + +-- DATETIMEOFFSET with typmod +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.501') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:57 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.500') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:57 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.499') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:56 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET(1), '01/01/98 23:59:59.123') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.1 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET(2), '01/01/98 23:59:59.123') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.12 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET(3), '01/01/98 23:59:59.123') +GO +~~START~~ +datetimeoffset +1998-01-01 23:59:59.123 +00:00 +~~END~~ + + +-- -- Boundary values +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.9999999') +GO +~~START~~ +datetimeoffset +9999-12-31 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.99999999') +GO +~~START~~ +datetimeoffset +9999-12-31 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.999999999') +GO +~~START~~ +datetimeoffset +9999-12-31 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.9999999') +GO +~~START~~ +datetimeoffset +9999-12-31 23:59:59.9999990 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.99999999') +GO +~~START~~ +datetimeoffset +9999-12-31 23:59:59.9999990 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.999999999') +GO +~~START~~ +datetimeoffset +9999-12-31 23:59:59.9999990 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- -- out of bound values +SELECT CONVERT(DATETIMEOFFSET,'2022-10-00 23:59:59.990 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'0000-10-01 23:59:59.990 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'2023-00-01 23:59:59.990 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'0000-00-00 23:59:59.990 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-21 23:59:59.990 +14:01') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-21 23:59:59.990 -15:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a datetimeoffset data type resulted in an out-of-range value.)~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIMEOFFSET, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +datetimeoffset +2021-04-10 11:12:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02/12/21', 1) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '21.02.12', 2) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12/02/21', 3) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12.02.21', 4) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12-02-21', 5) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 21', 6) +GO +~~START~~ +datetimeoffset +2021-04-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 21', 7) +GO +~~START~~ +datetimeoffset +2021-04-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 8) +GO +~~START~~ +datetimeoffset +1900-01-01 10:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 24) +GO +~~START~~ +datetimeoffset +1900-01-01 10:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +datetimeoffset +2021-04-12 10:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02-12-21', 10) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '21/02/12', 11) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '210212', 12) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +datetimeoffset +2021-04-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '15:13:14:123', 14) +GO +~~START~~ +datetimeoffset +1900-01-01 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14', 20) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02/12/21 15:13:14 PM', 22) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12', 23) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 25) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +datetimeoffset +2021-04-10 11:12:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02/12/2021', 101) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021.02.12', 102) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12/02/2021', 103) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12.02.2021', 104) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12-02-2021', 105) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021', 106) +GO +~~START~~ +datetimeoffset +2021-04-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 2021', 107) +GO +~~START~~ +datetimeoffset +2021-04-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 108) +GO +~~START~~ +datetimeoffset +1900-01-01 10:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +datetimeoffset +2021-04-12 10:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02-12-2021', 110) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021/02/12', 111) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '20210212', 112) +GO +~~START~~ +datetimeoffset +2021-02-12 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +datetimeoffset +2021-04-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '15:13:14:123', 114) +GO +~~START~~ +datetimeoffset +1900-01-01 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14', 120) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +datetimeoffset +2021-02-12 15:13:14.1230000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +datetimeoffset +2018-10-02 01:39:17.0900000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +datetimeoffset +2582-07-04 15:13:14.1230000 +00:00 +~~END~~ + + +--- misc +SELECT CONVERT(DATETIMEOFFSET,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetimeoffset +2022-10-29 20:01:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2020') +GO +~~START~~ +datetimeoffset +2020-01-01 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(DATETIMEOFFSET, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '1900-05-06 13:59:29.050 -8:00') +GO +~~START~~ +datetimeoffset +1900-05-06 13:59:29.0500000 -08:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-29 20:01:00.000') +GO +~~START~~ +datetimeoffset +2022-10-29 20:01:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2020') +GO +~~START~~ +datetimeoffset +2020-01-01 00:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00') +GO +~~START~~ +datetimeoffset +2022-10-30 03:00:00.0000000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +datetimeoffset +2021-01-01 00:00:00.0000000 +12:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIMEOFFSET, @TM_ICLO) +GO +~~START~~ +datetimeoffset +1900-01-01 17:24:07.1766670 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(DATETIMEOFFSET, '1900-05-06 13:59:29.050') +GO +~~START~~ +datetimeoffset +1900-05-06 13:59:29.0500000 +00:00 +~~END~~ + + +SELECT CONVERT(DATETIMEOFFSET, '2000-04-22 16:23:51.7668c0 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetimeoffset_v1 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p1 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f1() +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v2 +GO +~~START~~ +datetimeoffset +1900-01-01 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p2 +GO +~~START~~ +datetimeoffset +1900-01-01 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f2() +GO +~~START~~ +datetimeoffset +1900-01-01 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v3 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p3 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f3() +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v4 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p4 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f4() +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v5 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p5 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f5() +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v6 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +EXEC test_conv_string_to_datetimeoffset_p6 +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + +SELECT test_conv_string_to_datetimeoffset_f6() +GO +~~START~~ +datetimeoffset +2017-08-25 13:01:59.0000000 +12:15 +~~END~~ + + +SELECT * FROM test_conv_string_to_datetimeoffset_v7 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetimeoffset is not allowed.)~~ + +EXEC test_conv_string_to_datetimeoffset_p7 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetimeoffset is not allowed.)~~ + +SELECT test_conv_string_to_datetimeoffset_f7() +GO +~~START~~ +datetimeoffset +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to datetimeoffset is not allowed.)~~ + diff --git a/test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-cleanup.out new file mode 100644 index 0000000000..8887fe27c1 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-cleanup.out @@ -0,0 +1,52 @@ +DROP VIEW test_conv_string_to_smalldatetime_v1 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p1 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f1() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v2 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p2 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f2() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v3 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p3 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f3() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v4 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p4 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f4() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v5 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p5 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f5() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v6 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p6 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f6() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v7 +GO +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: view "test_conv_string_to_smalldatetime_v7" does not exist)~~ + +DROP PROCEDURE test_conv_string_to_smalldatetime_p7 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f7() +GO diff --git a/test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-prepare.out new file mode 100644 index 0000000000..be0e6d06bb --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-prepare.out @@ -0,0 +1,80 @@ +CREATE VIEW test_conv_string_to_smalldatetime_v1 as (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p1 as (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f1() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v2 as (SELECT CONVERT(smalldatetime, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p2 as (SELECT CONVERT(smalldatetime, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f2() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v3 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p3 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f3() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v4 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p4 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f4() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v5 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p5 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f5() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v6 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p6 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f6() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v7 as (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to smalldatetime)~~ + +CREATE PROCEDURE test_conv_string_to_smalldatetime_p7 as (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f7() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-verify.out b/test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-verify.out new file mode 100644 index 0000000000..4bb06a9483 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_smalldatetime-before-14_6-vu-verify.out @@ -0,0 +1,1943 @@ +-- Empty string, should return default values +SELECT CONVERT(SMALLDATETIME, '') +GO +~~START~~ +smalldatetime +1900-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '', 130) +GO +~~START~~ +smalldatetime +1900-01-01 00:00:00.0 +~~END~~ + + +-- -- Numeric +SELECT CONVERT(SMALLDATETIME, '3-2-4 14:30') +GO +~~START~~ +smalldatetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3-12-4 14:30') +GO +~~START~~ +smalldatetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3-12-24 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3-12-2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3 - 12 - 2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3.2.4 14:30') +GO +~~START~~ +smalldatetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3.12.4 14:30') +GO +~~START~~ +smalldatetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3.12.24 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3.12.2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3 . 12 . 2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3/2/4 14:30') +GO +~~START~~ +smalldatetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3/12/4 14:30') +GO +~~START~~ +smalldatetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3/12/24 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3/12/2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3 / 12 / 2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '04-02-03 14:30') +GO +~~START~~ +smalldatetime +2003-04-02 14:30:00.0 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(SMALLDATETIME, '3 12 2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '3#12#2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '3/12.2024') +GO +~~START~~ +smalldatetime +2024-03-12 00:00:00.0 +~~END~~ + + +-- Alphabetical +SELECT CONVERT(SMALLDATETIME, 'Apr 12,2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 1 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 1,2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 16, 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 1, 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'April 16, 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'April 16 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 16, 24 14:30') +GO +~~START~~ +smalldatetime +2024-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 16,4 14:30') +GO +~~START~~ +smalldatetime +2004-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 1,4 14:30') +GO +~~START~~ +smalldatetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 16 24 14:30') +GO +~~START~~ +smalldatetime +2024-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 16 4 14:30') +GO +~~START~~ +smalldatetime +2004-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'April 16 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 22 14:30') +GO +~~START~~ +smalldatetime +2024-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 2 14:30') +GO +~~START~~ +smalldatetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '24 Apr, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3 Apr, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3 Apr 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3Apr2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3Apr24 14:30') +GO +~~START~~ +smalldatetime +2024-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr24 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr,24 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '24 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '12 24 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 2024 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 12 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 9 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-09 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 Apr 12 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12, Apr, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 Apr, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12, Apr 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024, Apr, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 Apr, 12 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024, Apr 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr, 12, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr, 12 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024 12 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12, 2024, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '12 2024, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '12, 2024 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024, 12, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 12, Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024, 12 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(SMALLDATETIME, N'محرم 12,2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 12 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 1 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 1,2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 1, 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16,4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 1,4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 22 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 2 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'24 محرم, 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'3 محرم, 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'3 محرم 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'3محرم2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'3محرم24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم,24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'24 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12 24 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12 2024 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 12 محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 9 محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12, محرم, 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12 محرم, 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12, محرم 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024, محرم, 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم, 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024, محرم 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم, 12, 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 12, 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم, 12 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024, 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024, 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12, 2024, محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12 2024, محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12, 2024 محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024, 12, محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 12, محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024, 12 محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +-- ISO 8601 +SELECT CONVERT(SMALLDATETIME, '2023-11-27') +GO +~~START~~ +smalldatetime +2023-11-27 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00') +GO +~~START~~ +smalldatetime +2022-10-30 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123') +GO +~~START~~ +smalldatetime +2022-10-30 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123-12:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123+12:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10 -30T03: 00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.12345') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00:123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00:12345') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +-- Unseparated +SELECT CONVERT(SMALLDATETIME, '20240129') +GO +~~START~~ +smalldatetime +2024-01-29 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '20241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '240129') +GO +~~START~~ +smalldatetime +2024-01-29 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2001') +GO +~~START~~ +smalldatetime +2001-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '0001') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '20240129 03:00:00') +GO +~~START~~ +smalldatetime +2024-01-29 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '20241329 03:00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '240129 03:00') +GO +~~START~~ +smalldatetime +2024-01-29 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '241329 03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2001 03:00:00.123') +GO +~~START~~ +smalldatetime +2001-01-01 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '0001 03:00:00.421') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +-- -- invalid syntax +SELECT CONVERT(SMALLDATETIME, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +-- should return default SMALLDATETIME +SELECT CONVERT(SMALLDATETIME, '16:23:51') +GO +~~START~~ +smalldatetime +1900-01-01 16:24:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '4:12:12:123') +GO +~~START~~ +smalldatetime +1900-01-01 04:12:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '4:12:12:1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '4:12:12.1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +-- hijri +SELECT CONVERT(SMALLDATETIME, '20231229', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '20231230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '20231129', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '20231130', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +smalldatetime +2018-10-02 01:39:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +smalldatetime +2018-10-02 01:39:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '22/12/1440 1:39:17.090PM', 130) +GO +~~START~~ +smalldatetime +2019-08-23 13:39:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +smalldatetime +2019-08-23 13:39:00.0 +~~END~~ + + +-- -- hijri leap year +SELECT CONVERT(SMALLDATETIME, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +-- rounding of SMALLDATETIME +SELECT CONVERT(SMALLDATETIME, '01/01/98 23:44:29') +GO +~~START~~ +smalldatetime +1998-01-01 23:44:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '01/01/98 23:44:30') +GO +~~START~~ +smalldatetime +1998-01-01 23:45:00.0 +~~END~~ + + +-- SMALLDATETIME with typmod +SELECT CONVERT(SMALLDATETIME(1), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'smalldatetime')~~ + + +SELECT CONVERT(SMALLDATETIME(2), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'smalldatetime')~~ + + +SELECT CONVERT(SMALLDATETIME(3), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'smalldatetime')~~ + + +-- boundary tests +SELECT CONVERT(SMALLDATETIME, '2079-06-06 23:59:29.999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2079-06-06 23:59:29.998') +GO +~~START~~ +smalldatetime +2079-06-06 23:59:00.0 +~~END~~ + + +-- -- out of bound values +SELECT CONVERT(SMALLDATETIME,'2022-10-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME,'0000-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME,'2023-00-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME,'0000-00-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME,'1742-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(SMALLDATETIME, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +smalldatetime +2021-04-10 11:12:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '02/12/21', 1) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '21.02.12', 2) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12/02/21', 3) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12.02.21', 4) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12-02-21', 5) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 Apr 21', 6) +GO +~~START~~ +smalldatetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 21', 7) +GO +~~START~~ +smalldatetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 8) +GO +~~START~~ +smalldatetime +1900-01-01 10:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 24) +GO +~~START~~ +smalldatetime +1900-01-01 10:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +smalldatetime +2021-04-12 10:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '02-12-21', 10) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '21/02/12', 11) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '210212', 12) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +smalldatetime +2021-04-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '15:13:14:123', 14) +GO +~~START~~ +smalldatetime +1900-01-01 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14', 20) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '02/12/21 15:13:14 PM', 22) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12', 23) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 25) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +smalldatetime +2021-04-10 11:12:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '02/12/2021', 101) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021.02.12', 102) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12/02/2021', 103) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12.02.2021', 104) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12-02-2021', 105) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021', 106) +GO +~~START~~ +smalldatetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 2021', 107) +GO +~~START~~ +smalldatetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 108) +GO +~~START~~ +smalldatetime +1900-01-01 10:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +smalldatetime +2021-04-12 10:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '02-12-2021', 110) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021/02/12', 111) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '20210212', 112) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +smalldatetime +2021-04-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '15:13:14:123', 114) +GO +~~START~~ +smalldatetime +1900-01-01 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14', 120) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +smalldatetime +2018-10-02 01:39:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12/02/2021 15:13:14:123 PM', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +--- misc +SELECT CONVERT(SMALLDATETIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +smalldatetime +2022-10-29 20:01:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2020') +GO +~~START~~ +smalldatetime +2020-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + + +SELECT CONVERT(SMALLDATETIME, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(SMALLDATETIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '1900-05-06 13:59:29.050 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 14:30.00') +GO +~~START~~ +smalldatetime +2011-08-15 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +smalldatetime +2022-10-29 20:01:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2020') +GO +~~START~~ +smalldatetime +2020-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00') +GO +~~START~~ +smalldatetime +2022-10-30 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +smalldatetime +2021-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(SMALLDATETIME, @TM_ICLO) +GO +~~START~~ +smalldatetime +1900-01-01 17:24:00.0 +~~END~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_smalldatetime_v1 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p1 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f1() +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v2 +GO +~~START~~ +smalldatetime +1900-01-01 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p2 +GO +~~START~~ +smalldatetime +1900-01-01 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f2() +GO +~~START~~ +smalldatetime +1900-01-01 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v3 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p3 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f3() +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v4 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p4 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f4() +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v5 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p5 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f5() +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v6 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p6 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f6() +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v7 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "test_conv_string_to_smalldatetime_v7" does not exist)~~ + +EXEC test_conv_string_to_smalldatetime_p7 +GO +~~START~~ +smalldatetime +1905-07-11 00:00:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f7() +GO +~~START~~ +smalldatetime +1905-07-11 00:00:00.0 +~~END~~ + diff --git a/test/JDBC/expected/test_conv_string_to_smalldatetime-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_smalldatetime-vu-cleanup.out new file mode 100644 index 0000000000..b7292d08e8 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_smalldatetime-vu-cleanup.out @@ -0,0 +1,48 @@ +DROP VIEW test_conv_string_to_smalldatetime_v1 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p1 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f1() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v2 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p2 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f2() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v3 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p3 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f3() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v4 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p4 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f4() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v5 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p5 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f5() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v6 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p6 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f6() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v7 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p7 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f7() +GO diff --git a/test/JDBC/expected/test_conv_string_to_smalldatetime-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_smalldatetime-vu-prepare.out new file mode 100644 index 0000000000..e778e0dfaa --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_smalldatetime-vu-prepare.out @@ -0,0 +1,76 @@ +CREATE VIEW test_conv_string_to_smalldatetime_v1 as (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p1 as (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f1() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v2 as (SELECT CONVERT(smalldatetime, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p2 as (SELECT CONVERT(smalldatetime, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f2() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v3 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p3 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f3() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v4 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p4 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f4() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v5 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p5 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f5() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v6 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p6 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f6() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v7 as (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p7 as (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f7() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/expected/test_conv_string_to_smalldatetime-vu-verify.out b/test/JDBC/expected/test_conv_string_to_smalldatetime-vu-verify.out new file mode 100644 index 0000000000..b96051360e --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_smalldatetime-vu-verify.out @@ -0,0 +1,1944 @@ +-- Empty string, should return default values +SELECT CONVERT(SMALLDATETIME, '') +GO +~~START~~ +smalldatetime +1900-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '', 130) +GO +~~START~~ +smalldatetime +1900-01-01 00:00:00.0 +~~END~~ + + +-- -- Numeric +SELECT CONVERT(SMALLDATETIME, '3-2-4 14:30') +GO +~~START~~ +smalldatetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3-12-4 14:30') +GO +~~START~~ +smalldatetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3-12-24 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3-12-2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3 - 12 - 2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3.2.4 14:30') +GO +~~START~~ +smalldatetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3.12.4 14:30') +GO +~~START~~ +smalldatetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3.12.24 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3.12.2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3 . 12 . 2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3/2/4 14:30') +GO +~~START~~ +smalldatetime +2004-03-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3/12/4 14:30') +GO +~~START~~ +smalldatetime +2004-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3/12/24 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3/12/2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3 / 12 / 2024 14:30') +GO +~~START~~ +smalldatetime +2024-03-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '04-02-03 14:30') +GO +~~START~~ +smalldatetime +2003-04-02 14:30:00.0 +~~END~~ + + +-- invalid syntax +SELECT CONVERT(SMALLDATETIME, '3 12 2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '3#12#2024') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '3/12.2024') +GO +~~START~~ +smalldatetime +2024-03-12 00:00:00.0 +~~END~~ + + +-- Alphabetical +SELECT CONVERT(SMALLDATETIME, 'Apr 12,2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 1 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 1,2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 16, 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 1, 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'April 16, 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'April 16 2000 14:30') +GO +~~START~~ +smalldatetime +2000-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 16, 24 14:30') +GO +~~START~~ +smalldatetime +2024-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 16,4 14:30') +GO +~~START~~ +smalldatetime +2004-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 1,4 14:30') +GO +~~START~~ +smalldatetime +2004-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 16 24 14:30') +GO +~~START~~ +smalldatetime +2024-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 16 4 14:30') +GO +~~START~~ +smalldatetime +2004-04-16 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'April 16 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 22 14:30') +GO +~~START~~ +smalldatetime +2024-04-22 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 2 14:30') +GO +~~START~~ +smalldatetime +2024-04-02 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '24 Apr, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-24 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3 Apr, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3 Apr 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3Apr2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '3Apr24 14:30') +GO +~~START~~ +smalldatetime +2024-04-03 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr24 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr,24 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '24 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '12 24 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 2024 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-01 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 12 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 9 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-09 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 Apr 12 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12, Apr, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 Apr, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12, Apr 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024, Apr, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 Apr, 12 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024, Apr 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr, 12, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr, 12 2024 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024, 12 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024 12 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12, 2024, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '12 2024, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '12, 2024 Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024, 12, Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2024 12, Apr 14:30') +GO +~~START~~ +smalldatetime +2024-04-12 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2024, 12 Apr 14:30') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(SMALLDATETIME, N'محرم 12,2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 12 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 1 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 1,2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 1, 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 2000 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16,4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 1,4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 4 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 22 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 2 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'24 محرم, 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'3 محرم, 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'3 محرم 2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'3محرم2024 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'3محرم24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم,24 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'24 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12 24 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12 2024 محرم 14:30', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 12 محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 9 محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12, محرم, 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12 محرم, 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12, محرم 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024, محرم, 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم, 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024, محرم 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم, 12, 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 12, 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم, 12 2024 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024, 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024, 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024 12 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12, 2024, محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12 2024, محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'12, 2024 محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024, 12, محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024 12, محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'2024, 12 محرم 14:30', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +-- ISO 8601 +SELECT CONVERT(SMALLDATETIME, '2023-11-27') +GO +~~START~~ +smalldatetime +2023-11-27 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00') +GO +~~START~~ +smalldatetime +2022-10-30 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123') +GO +~~START~~ +smalldatetime +2022-10-30 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123-12:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123+12:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10 -30T03: 00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.12345') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00:123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00:12345') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +-- Unseparated +SELECT CONVERT(SMALLDATETIME, '20240129') +GO +~~START~~ +smalldatetime +2024-01-29 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '20241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '240129') +GO +~~START~~ +smalldatetime +2024-01-29 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '241329') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2001') +GO +~~START~~ +smalldatetime +2001-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '0001') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '20240129 03:00:00') +GO +~~START~~ +smalldatetime +2024-01-29 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '20241329 03:00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '240129 03:00') +GO +~~START~~ +smalldatetime +2024-01-29 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '241329 03:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2001 03:00:00.123') +GO +~~START~~ +smalldatetime +2001-01-01 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '0001 03:00:00.421') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +-- -- invalid syntax +SELECT CONVERT(SMALLDATETIME, '0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '1') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '11111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '1111111') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +-- should return default SMALLDATETIME +SELECT CONVERT(SMALLDATETIME, '16:23:51') +GO +~~START~~ +smalldatetime +1900-01-01 16:24:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '4:12:12:123') +GO +~~START~~ +smalldatetime +1900-01-01 04:12:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '4:12:12:1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '4:12:12.1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +-- hijri +SELECT CONVERT(SMALLDATETIME, '20231229', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '20231230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '20231129', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '20231130', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +smalldatetime +2018-10-02 01:39:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 131) +GO +~~START~~ +smalldatetime +2018-10-02 01:39:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '22/12/1440 1:39:17.090PM', 130) +GO +~~START~~ +smalldatetime +2019-08-23 13:39:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '22/12/1440 1:39:17.090PM', 131) +GO +~~START~~ +smalldatetime +2019-08-23 13:39:00.0 +~~END~~ + + +-- -- hijri leap year +SELECT CONVERT(SMALLDATETIME, '20241230', 130) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +-- rounding of SMALLDATETIME +SELECT CONVERT(SMALLDATETIME, '01/01/98 23:44:29') +GO +~~START~~ +smalldatetime +1998-01-01 23:44:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '01/01/98 23:44:30') +GO +~~START~~ +smalldatetime +1998-01-01 23:45:00.0 +~~END~~ + + +-- SMALLDATETIME with typmod +SELECT CONVERT(SMALLDATETIME(1), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'smalldatetime')~~ + + +SELECT CONVERT(SMALLDATETIME(2), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'smalldatetime')~~ + + +SELECT CONVERT(SMALLDATETIME(3), '01/01/98 23:59:59.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: CAST or CONVERT: invalid attributes specified for type 'smalldatetime')~~ + + +-- boundary tests +SELECT CONVERT(SMALLDATETIME, '2079-06-06 23:59:29.999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2079-06-06 23:59:29.998') +GO +~~START~~ +smalldatetime +2079-06-06 23:59:00.0 +~~END~~ + + +-- -- out of bound values +SELECT CONVERT(SMALLDATETIME,'2022-10-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME,'0000-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME,'2023-00-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME,'0000-00-00 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(SMALLDATETIME,'1742-10-01 23:59:59.990') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(SMALLDATETIME, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +smalldatetime +2021-04-10 11:12:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '02/12/21', 1) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '21.02.12', 2) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12/02/21', 3) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12.02.21', 4) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12-02-21', 5) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 Apr 21', 6) +GO +~~START~~ +smalldatetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 21', 7) +GO +~~START~~ +smalldatetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 8) +GO +~~START~~ +smalldatetime +1900-01-01 10:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 24) +GO +~~START~~ +smalldatetime +1900-01-01 10:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +smalldatetime +2021-04-12 10:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '02-12-21', 10) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '21/02/12', 11) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '210212', 12) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +smalldatetime +2021-04-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '15:13:14:123', 14) +GO +~~START~~ +smalldatetime +1900-01-01 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14', 20) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '02/12/21 15:13:14 PM', 22) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12', 23) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 25) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +smalldatetime +2021-04-10 11:12:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '02/12/2021', 101) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021.02.12', 102) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12/02/2021', 103) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12.02.2021', 104) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12-02-2021', 105) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021', 106) +GO +~~START~~ +smalldatetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 2021', 107) +GO +~~START~~ +smalldatetime +2021-04-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 108) +GO +~~START~~ +smalldatetime +1900-01-01 10:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +smalldatetime +2021-04-12 10:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '02-12-2021', 110) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021/02/12', 111) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '20210212', 112) +GO +~~START~~ +smalldatetime +2021-02-12 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +smalldatetime +2021-04-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '15:13:14:123', 114) +GO +~~START~~ +smalldatetime +1900-01-01 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14', 120) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +smalldatetime +2021-02-12 15:13:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +smalldatetime +2018-10-02 01:39:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '12/02/2021 15:13:14:123 PM', 131) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.)~~ + + +--- misc +SELECT CONVERT(SMALLDATETIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +smalldatetime +2022-10-29 20:01:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2020') +GO +~~START~~ +smalldatetime +2020-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + + +SELECT CONVERT(SMALLDATETIME, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(SMALLDATETIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '1900-05-06 13:59:29.050 -8:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 14:30.00') +GO +~~START~~ +smalldatetime +2011-08-15 14:30:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +smalldatetime +2022-10-29 20:01:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2020') +GO +~~START~~ +smalldatetime +2020-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00') +GO +~~START~~ +smalldatetime +2022-10-30 03:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO +~~START~~ +smalldatetime +2021-01-01 00:00:00.0 +~~END~~ + + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 10:30.00 AMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 10:30.00 PMZ') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting character string to smalldatetime data type.)~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(SMALLDATETIME, @TM_ICLO) +GO +~~START~~ +smalldatetime +1900-01-01 17:24:00.0 +~~END~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_smalldatetime_v1 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p1 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f1() +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v2 +GO +~~START~~ +smalldatetime +1900-01-01 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p2 +GO +~~START~~ +smalldatetime +1900-01-01 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f2() +GO +~~START~~ +smalldatetime +1900-01-01 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v3 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p3 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f3() +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v4 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p4 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f4() +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v5 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p5 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f5() +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v6 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p6 +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f6() +GO +~~START~~ +smalldatetime +2017-08-25 13:02:00.0 +~~END~~ + + +SELECT * FROM test_conv_string_to_smalldatetime_v7 +GO +~~START~~ +smalldatetime +1905-07-11 00:00:00.0 +~~END~~ + +EXEC test_conv_string_to_smalldatetime_p7 +GO +~~START~~ +smalldatetime +1905-07-11 00:00:00.0 +~~END~~ + +SELECT test_conv_string_to_smalldatetime_f7() +GO +~~START~~ +smalldatetime +1905-07-11 00:00:00.0 +~~END~~ + diff --git a/test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-cleanup.out new file mode 100644 index 0000000000..a33d1bdadf --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-cleanup.out @@ -0,0 +1,71 @@ +DROP VIEW test_conv_string_to_time_v1 +GO +DROP PROCEDURE test_conv_string_to_time_p1 +GO +DROP FUNCTION test_conv_string_to_time_f1() +GO + +DROP VIEW test_conv_string_to_time_v2 +GO +DROP PROCEDURE test_conv_string_to_time_p2 +GO +DROP FUNCTION test_conv_string_to_time_f2() +GO + +DROP VIEW test_conv_string_to_time_v3 +GO +DROP PROCEDURE test_conv_string_to_time_p3 +GO +DROP FUNCTION test_conv_string_to_time_f3() +GO + +DROP VIEW test_conv_string_to_time_v4 +GO +DROP PROCEDURE test_conv_string_to_time_p4 +GO +DROP FUNCTION test_conv_string_to_time_f4() +GO + +DROP VIEW test_conv_string_to_time_v5 +GO +DROP PROCEDURE test_conv_string_to_time_p5 +GO +DROP FUNCTION test_conv_string_to_time_f5() +GO + +DROP VIEW test_conv_string_to_time_v6 +GO +DROP PROCEDURE test_conv_string_to_time_p6 +GO +DROP FUNCTION test_conv_string_to_time_f6() +GO + +DROP VIEW test_conv_string_to_time_v7 +GO +DROP PROCEDURE test_conv_string_to_time_p7 +GO +DROP FUNCTION test_conv_string_to_time_f7() +GO + +DROP VIEW test_conv_string_to_time_v8 +GO +DROP PROCEDURE test_conv_string_to_time_p8 +GO +DROP FUNCTION test_conv_string_to_time_f8() +GO + +DROP VIEW test_conv_string_to_time_v9 +GO +DROP PROCEDURE test_conv_string_to_time_p9 +GO +DROP FUNCTION test_conv_string_to_time_f9() +GO + +DROP VIEW test_conv_string_to_time_v10 +GO + +DROP VIEW test_conv_string_to_time_v11 +GO + +DROP VIEW test_conv_string_to_time_v12 +GO diff --git a/test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-prepare.out new file mode 100644 index 0000000000..b3fed4c393 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-prepare.out @@ -0,0 +1,107 @@ +CREATE VIEW test_conv_string_to_time_v1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_time_p1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_time_f1() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_time_v2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE PROCEDURE test_conv_string_to_time_p2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE FUNCTION test_conv_string_to_time_f2() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '00:00:00')); +END +GO + +CREATE VIEW test_conv_string_to_time_v3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE PROCEDURE test_conv_string_to_time_p3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE FUNCTION test_conv_string_to_time_f3() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '1:1:1')); +END +GO + +CREATE VIEW test_conv_string_to_time_v4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_time_p4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_time_f4() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_time_v5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f5() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f6() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f7() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_time_p8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_time_f8() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_time_v9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f9() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v10 as (SELECT CONVERT(time, '02-03-2003 11:11:11 +11:11')); +GO + +CREATE VIEW test_conv_string_to_time_v11 as (SELECT CONVERT(time, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)))); +GO + +CREATE VIEW test_conv_string_to_time_v12 as (SELECT CONVERT(time, CAST('20' as INTEGER))); +GO diff --git a/test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-verify.out b/test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-verify.out new file mode 100644 index 0000000000..631f685abd --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_time-before-13_6-vu-verify.out @@ -0,0 +1,2365 @@ +-- Empty string, should return default values +SELECT CONVERT(TIME, '') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '', 130) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM ') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 ') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +-- TIME with typmod +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.501') +GO +~~START~~ +time +23:59:57 +~~END~~ + + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.500') +GO +~~START~~ +time +23:59:57 +~~END~~ + + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.499') +GO +~~START~~ +time +23:59:56 +~~END~~ + + +SELECT CONVERT(TIME(1), '01/01/98 23:59:59.123') +GO +~~START~~ +time +23:59:59.1 +~~END~~ + + +SELECT CONVERT(TIME(2), '01/01/98 23:59:59.123') +GO +~~START~~ +time +23:59:59.12 +~~END~~ + + +SELECT CONVERT(TIME(3), '01/01/98 23:59:59.123') +GO +~~START~~ +time +23:59:59.123 +~~END~~ + + +-- -- rounding of minutes or fractional seconds +SELECT CONVERT(TIME, '11:22:12.12345675') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.12345674') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +-- -- Boundary values +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.99999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.999999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.99999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.999999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12.129') +GO +~~START~~ +time +11:22:12.1290000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.128') +GO +~~START~~ +time +11:22:12.1280000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.127') +GO +~~START~~ +time +11:22:12.1270000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.126') +GO +~~START~~ +time +11:22:12.1260000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.125') +GO +~~START~~ +time +11:22:12.1250000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.124') +GO +~~START~~ +time +11:22:12.1240000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.123') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.122') +GO +~~START~~ +time +11:22:12.1220000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.121') +GO +~~START~~ +time +11:22:12.1210000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.120') +GO +~~START~~ +time +11:22:12.1200000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:29') +GO +~~START~~ +time +11:22:29.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:30') +GO +~~START~~ +time +11:22:30.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM +00:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM +00:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM -00:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM +00:00') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM -00:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM -00:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM +00:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 -00:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM -00:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM +00:00') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123 -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +00:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -00:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +00:00') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +00:00') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +00:00') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -00:00') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +00:00') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM -05:12') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM -05:12') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM +05:12') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM -05:12') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM +05:12') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM +05:12') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM -05:12') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 +05:12') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM -05:12') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM +05:12') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123 -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +05:12') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -05:12') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +05:12') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +05:12') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +05:12') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -05:12') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +05:12') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM -14:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM -14:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM +14:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM -14:00') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM +14:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM +14:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM -14:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 +14:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM -14:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM +14:00') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123 -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +14:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -14:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +14:00') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:00') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:00') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:00') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:00') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '13 AM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '13 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '24 PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11AM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, ' 13AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '13PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '24PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22.123 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 AM Z') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM Z') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM Z') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM Z') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM Z') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM Z') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM Z') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 Z') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM Z') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM Z') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12Z') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM Z') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM Z') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM Z') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234Z') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789Z') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM Z') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +-- default value if only DATE is passed +SELECT CONVERT(TIME, '2000-04-22') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +time +11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '02/12/21', 1) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '21.02.12', 2) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12/02/21', 3) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12.02.21', 4) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12-02-21', 5) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 21', 6) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12, 21', 7) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '10:13:14', 8) +GO +~~START~~ +time +10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '10:13:14', 24) +GO +~~START~~ +time +10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +time +10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '02-12-21', 10) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '21/02/12', 11) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '210212', 12) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '15:13:14:123', 14) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 20) +GO +~~START~~ +time +15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '02/12/21 15:13:14 PM', 22) +GO +~~START~~ +time +15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12', 23) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 25) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +time +11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '02/12/2021', 101) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021.02.12', 102) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12/02/2021', 103) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12.02.2021', 104) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12-02-2021', 105) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 2021', 106) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12, 2021', 107) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '10:13:14', 108) +GO +~~START~~ +time +10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +time +10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '02-12-2021', 110) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021/02/12', 111) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '20210212', 112) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '15:13:14:123', 114) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 120) +GO +~~START~~ +time +15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +time +01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(TIME, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +-- -- misc +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +time +20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2020') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(TIME, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(TIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '1900-05-06 13:59:29.050 -8:00') +GO +~~START~~ +time +13:59:29.0500000 +~~END~~ + + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +time +20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2020') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2022-10-30T03:00:00') +GO +~~START~~ +time +03:00:00.0000000 +~~END~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(TIME, @TM_ICLO) +GO +~~START~~ +time +17:24:07.1766670 +~~END~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_time_v1 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p1 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f1() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v2 +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p2 +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f2() +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v3 +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p3 +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f3() +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v4 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p4 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f4() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v5 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p5 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f5() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v6 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p6 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f6() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v7 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p7 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f7() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to time without time zone)~~ + +EXEC test_conv_string_to_time_p8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to time is not allowed.)~~ + +SELECT test_conv_string_to_time_f8() +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to time is not allowed.)~~ + + +SELECT * FROM test_conv_string_to_time_v9 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p9 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f9() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v10 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting time from character string.)~~ + + +SELECT * FROM test_conv_string_to_time_v11 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting time from character string.)~~ + + +SELECT * FROM test_conv_string_to_time_v12 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to time without time zone)~~ + diff --git a/test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-cleanup.out new file mode 100644 index 0000000000..a33d1bdadf --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-cleanup.out @@ -0,0 +1,71 @@ +DROP VIEW test_conv_string_to_time_v1 +GO +DROP PROCEDURE test_conv_string_to_time_p1 +GO +DROP FUNCTION test_conv_string_to_time_f1() +GO + +DROP VIEW test_conv_string_to_time_v2 +GO +DROP PROCEDURE test_conv_string_to_time_p2 +GO +DROP FUNCTION test_conv_string_to_time_f2() +GO + +DROP VIEW test_conv_string_to_time_v3 +GO +DROP PROCEDURE test_conv_string_to_time_p3 +GO +DROP FUNCTION test_conv_string_to_time_f3() +GO + +DROP VIEW test_conv_string_to_time_v4 +GO +DROP PROCEDURE test_conv_string_to_time_p4 +GO +DROP FUNCTION test_conv_string_to_time_f4() +GO + +DROP VIEW test_conv_string_to_time_v5 +GO +DROP PROCEDURE test_conv_string_to_time_p5 +GO +DROP FUNCTION test_conv_string_to_time_f5() +GO + +DROP VIEW test_conv_string_to_time_v6 +GO +DROP PROCEDURE test_conv_string_to_time_p6 +GO +DROP FUNCTION test_conv_string_to_time_f6() +GO + +DROP VIEW test_conv_string_to_time_v7 +GO +DROP PROCEDURE test_conv_string_to_time_p7 +GO +DROP FUNCTION test_conv_string_to_time_f7() +GO + +DROP VIEW test_conv_string_to_time_v8 +GO +DROP PROCEDURE test_conv_string_to_time_p8 +GO +DROP FUNCTION test_conv_string_to_time_f8() +GO + +DROP VIEW test_conv_string_to_time_v9 +GO +DROP PROCEDURE test_conv_string_to_time_p9 +GO +DROP FUNCTION test_conv_string_to_time_f9() +GO + +DROP VIEW test_conv_string_to_time_v10 +GO + +DROP VIEW test_conv_string_to_time_v11 +GO + +DROP VIEW test_conv_string_to_time_v12 +GO diff --git a/test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-prepare.out new file mode 100644 index 0000000000..b3fed4c393 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-prepare.out @@ -0,0 +1,107 @@ +CREATE VIEW test_conv_string_to_time_v1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_time_p1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_time_f1() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_time_v2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE PROCEDURE test_conv_string_to_time_p2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE FUNCTION test_conv_string_to_time_f2() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '00:00:00')); +END +GO + +CREATE VIEW test_conv_string_to_time_v3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE PROCEDURE test_conv_string_to_time_p3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE FUNCTION test_conv_string_to_time_f3() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '1:1:1')); +END +GO + +CREATE VIEW test_conv_string_to_time_v4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_time_p4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_time_f4() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_time_v5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f5() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f6() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f7() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_time_p8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_time_f8() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_time_v9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f9() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v10 as (SELECT CONVERT(time, '02-03-2003 11:11:11 +11:11')); +GO + +CREATE VIEW test_conv_string_to_time_v11 as (SELECT CONVERT(time, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)))); +GO + +CREATE VIEW test_conv_string_to_time_v12 as (SELECT CONVERT(time, CAST('20' as INTEGER))); +GO diff --git a/test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-verify.out b/test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-verify.out new file mode 100644 index 0000000000..54fec357c5 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_time-before-17_3-vu-verify.out @@ -0,0 +1,2372 @@ +-- Empty string, should return default values +SELECT CONVERT(TIME, '') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '', 130) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM ') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 ') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +-- TIME with typmod +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.501') +GO +~~START~~ +time +23:59:57 +~~END~~ + + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.500') +GO +~~START~~ +time +23:59:57 +~~END~~ + + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.499') +GO +~~START~~ +time +23:59:56 +~~END~~ + + +SELECT CONVERT(TIME(1), '01/01/98 23:59:59.123') +GO +~~START~~ +time +23:59:59.1 +~~END~~ + + +SELECT CONVERT(TIME(2), '01/01/98 23:59:59.123') +GO +~~START~~ +time +23:59:59.12 +~~END~~ + + +SELECT CONVERT(TIME(3), '01/01/98 23:59:59.123') +GO +~~START~~ +time +23:59:59.123 +~~END~~ + + +-- -- rounding of minutes or fractional seconds +SELECT CONVERT(TIME, '11:22:12.12345675') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.12345674') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +-- -- Boundary values +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.99999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.999999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.99999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.999999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12.129') +GO +~~START~~ +time +11:22:12.1290000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.128') +GO +~~START~~ +time +11:22:12.1280000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.127') +GO +~~START~~ +time +11:22:12.1270000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.126') +GO +~~START~~ +time +11:22:12.1260000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.125') +GO +~~START~~ +time +11:22:12.1250000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.124') +GO +~~START~~ +time +11:22:12.1240000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.123') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.122') +GO +~~START~~ +time +11:22:12.1220000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.121') +GO +~~START~~ +time +11:22:12.1210000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.120') +GO +~~START~~ +time +11:22:12.1200000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:29') +GO +~~START~~ +time +11:22:29.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:30') +GO +~~START~~ +time +11:22:30.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM +00:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM +00:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM -00:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM +00:00') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM -00:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM -00:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM +00:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 -00:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM -00:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM +00:00') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123 -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +00:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -00:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +00:00') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +00:00') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +00:00') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -00:00') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +00:00') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM -05:12') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM -05:12') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM +05:12') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM -05:12') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM +05:12') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM +05:12') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM -05:12') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 +05:12') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM -05:12') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM +05:12') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123 -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +05:12') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -05:12') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +05:12') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +05:12') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +05:12') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -05:12') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +05:12') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM -14:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM -14:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM +14:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM -14:00') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM +14:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM +14:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM -14:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 +14:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM -14:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM +14:00') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123 -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +14:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -14:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +14:00') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:00') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:00') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:00') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:00') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '13 AM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '13 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '24 PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11AM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, ' 13AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '13PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '24PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22.123 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 AM Z') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM Z') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM Z') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM Z') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM Z') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM Z') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM Z') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 Z') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM Z') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM Z') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12Z') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM Z') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM Z') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM Z') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234Z') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789Z') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM Z') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +-- default value if only DATE is passed +SELECT CONVERT(TIME, '2000-04-22') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +time +11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '02/12/21', 1) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '21.02.12', 2) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12/02/21', 3) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12.02.21', 4) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12-02-21', 5) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 21', 6) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12, 21', 7) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '10:13:14', 8) +GO +~~START~~ +time +10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '10:13:14', 24) +GO +~~START~~ +time +10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +time +10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '02-12-21', 10) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '21/02/12', 11) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '210212', 12) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '15:13:14:123', 14) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 20) +GO +~~START~~ +time +15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '02/12/21 15:13:14 PM', 22) +GO +~~START~~ +time +15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12', 23) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 25) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +time +11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '02/12/2021', 101) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021.02.12', 102) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12/02/2021', 103) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12.02.2021', 104) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12-02-2021', 105) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 2021', 106) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12, 2021', 107) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '10:13:14', 108) +GO +~~START~~ +time +10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +time +10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '02-12-2021', 110) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021/02/12', 111) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '20210212', 112) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '15:13:14:123', 114) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 120) +GO +~~START~~ +time +15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +time +01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(TIME, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +-- -- misc +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +time +20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2020') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(TIME, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(TIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '1900-05-06 13:59:29.050 -8:00') +GO +~~START~~ +time +13:59:29.0500000 +~~END~~ + + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +time +20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2020') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2022-10-30T03:00:00') +GO +~~START~~ +time +03:00:00.0000000 +~~END~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(TIME, @TM_ICLO) +GO +~~START~~ +time +17:24:07.1766670 +~~END~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_time_v1 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p1 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f1() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v2 +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p2 +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f2() +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v3 +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p3 +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f3() +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v4 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p4 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f4() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v5 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p5 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f5() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v6 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p6 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f6() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v7 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p7 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f7() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v8 +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to time without time zone)~~ + +EXEC test_conv_string_to_time_p8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to time is not allowed.)~~ + +SELECT test_conv_string_to_time_f8() +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to time is not allowed.)~~ + + +SELECT * FROM test_conv_string_to_time_v9 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p9 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f9() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v10 +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting time from character string.)~~ + + +SELECT * FROM test_conv_string_to_time_v11 +GO +~~START~~ +time +11:11:11.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v12 +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type integer to time without time zone)~~ + diff --git a/test/JDBC/expected/test_conv_string_to_time-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_time-vu-cleanup.out new file mode 100644 index 0000000000..a33d1bdadf --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_time-vu-cleanup.out @@ -0,0 +1,71 @@ +DROP VIEW test_conv_string_to_time_v1 +GO +DROP PROCEDURE test_conv_string_to_time_p1 +GO +DROP FUNCTION test_conv_string_to_time_f1() +GO + +DROP VIEW test_conv_string_to_time_v2 +GO +DROP PROCEDURE test_conv_string_to_time_p2 +GO +DROP FUNCTION test_conv_string_to_time_f2() +GO + +DROP VIEW test_conv_string_to_time_v3 +GO +DROP PROCEDURE test_conv_string_to_time_p3 +GO +DROP FUNCTION test_conv_string_to_time_f3() +GO + +DROP VIEW test_conv_string_to_time_v4 +GO +DROP PROCEDURE test_conv_string_to_time_p4 +GO +DROP FUNCTION test_conv_string_to_time_f4() +GO + +DROP VIEW test_conv_string_to_time_v5 +GO +DROP PROCEDURE test_conv_string_to_time_p5 +GO +DROP FUNCTION test_conv_string_to_time_f5() +GO + +DROP VIEW test_conv_string_to_time_v6 +GO +DROP PROCEDURE test_conv_string_to_time_p6 +GO +DROP FUNCTION test_conv_string_to_time_f6() +GO + +DROP VIEW test_conv_string_to_time_v7 +GO +DROP PROCEDURE test_conv_string_to_time_p7 +GO +DROP FUNCTION test_conv_string_to_time_f7() +GO + +DROP VIEW test_conv_string_to_time_v8 +GO +DROP PROCEDURE test_conv_string_to_time_p8 +GO +DROP FUNCTION test_conv_string_to_time_f8() +GO + +DROP VIEW test_conv_string_to_time_v9 +GO +DROP PROCEDURE test_conv_string_to_time_p9 +GO +DROP FUNCTION test_conv_string_to_time_f9() +GO + +DROP VIEW test_conv_string_to_time_v10 +GO + +DROP VIEW test_conv_string_to_time_v11 +GO + +DROP VIEW test_conv_string_to_time_v12 +GO diff --git a/test/JDBC/expected/test_conv_string_to_time-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_time-vu-prepare.out new file mode 100644 index 0000000000..b3fed4c393 --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_time-vu-prepare.out @@ -0,0 +1,107 @@ +CREATE VIEW test_conv_string_to_time_v1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_time_p1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_time_f1() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_time_v2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE PROCEDURE test_conv_string_to_time_p2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE FUNCTION test_conv_string_to_time_f2() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '00:00:00')); +END +GO + +CREATE VIEW test_conv_string_to_time_v3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE PROCEDURE test_conv_string_to_time_p3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE FUNCTION test_conv_string_to_time_f3() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '1:1:1')); +END +GO + +CREATE VIEW test_conv_string_to_time_v4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_time_p4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_time_f4() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_time_v5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f5() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f6() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f7() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_time_p8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_time_f8() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_time_v9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f9() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v10 as (SELECT CONVERT(time, '02-03-2003 11:11:11 +11:11')); +GO + +CREATE VIEW test_conv_string_to_time_v11 as (SELECT CONVERT(time, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)))); +GO + +CREATE VIEW test_conv_string_to_time_v12 as (SELECT CONVERT(time, CAST('20' as INTEGER))); +GO diff --git a/test/JDBC/expected/test_conv_string_to_time-vu-verify.out b/test/JDBC/expected/test_conv_string_to_time-vu-verify.out new file mode 100644 index 0000000000..d830221d1d --- /dev/null +++ b/test/JDBC/expected/test_conv_string_to_time-vu-verify.out @@ -0,0 +1,2367 @@ +-- Empty string, should return default values +SELECT CONVERT(TIME, '') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '', 130) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM ') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 ') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +-- TIME with typmod +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.501') +GO +~~START~~ +time +23:59:57 +~~END~~ + + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.500') +GO +~~START~~ +time +23:59:57 +~~END~~ + + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.499') +GO +~~START~~ +time +23:59:56 +~~END~~ + + +SELECT CONVERT(TIME(1), '01/01/98 23:59:59.123') +GO +~~START~~ +time +23:59:59.1 +~~END~~ + + +SELECT CONVERT(TIME(2), '01/01/98 23:59:59.123') +GO +~~START~~ +time +23:59:59.12 +~~END~~ + + +SELECT CONVERT(TIME(3), '01/01/98 23:59:59.123') +GO +~~START~~ +time +23:59:59.123 +~~END~~ + + +-- -- rounding of minutes or fractional seconds +SELECT CONVERT(TIME, '11:22:12.12345675') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.12345674') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +-- -- Boundary values +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.99999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.999999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.99999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.999999999') +GO +~~START~~ +time +23:59:59.9999990 +~~END~~ + + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999999') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12.129') +GO +~~START~~ +time +11:22:12.1290000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.128') +GO +~~START~~ +time +11:22:12.1280000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.127') +GO +~~START~~ +time +11:22:12.1270000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.126') +GO +~~START~~ +time +11:22:12.1260000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.125') +GO +~~START~~ +time +11:22:12.1250000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.124') +GO +~~START~~ +time +11:22:12.1240000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.123') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.122') +GO +~~START~~ +time +11:22:12.1220000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.121') +GO +~~START~~ +time +11:22:12.1210000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12.120') +GO +~~START~~ +time +11:22:12.1200000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:29') +GO +~~START~~ +time +11:22:29.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:30') +GO +~~START~~ +time +11:22:30.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM +00:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM +00:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM -00:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM +00:00') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM -00:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM -00:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM +00:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 -00:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM -00:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM +00:00') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123 -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +00:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -00:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +00:00') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +00:00') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +00:00') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -00:00') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +00:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -00:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +00:00') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM -05:12') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM -05:12') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM +05:12') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM -05:12') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM +05:12') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM +05:12') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM -05:12') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 +05:12') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM -05:12') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM +05:12') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123 -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +05:12') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -05:12') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +05:12') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +05:12') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +05:12') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -05:12') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +05:12') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -05:12') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +05:12') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM -14:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM -14:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM +14:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM -14:00') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM +14:00') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM +14:00') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM -14:00') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 +14:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM -14:00') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM +14:00') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123 -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +14:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -14:00') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +14:00') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:00') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:00') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:00') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:00') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:00') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +SELECT CONVERT(TIME, '11 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '13 AM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '13 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '24 PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11AM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, ' 13AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '13PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '24PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22.123 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 :22:12:123 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12:1234 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:10') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 AM Z') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 AM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11 PM Z') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13 PM Z') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24 PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '0 AM Z') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11AM Z') +GO +~~START~~ +time +11:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, ' 13AM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11PM Z') +GO +~~START~~ +time +23:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '13PM Z') +GO +~~START~~ +time +13:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '24PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The conversion of a varchar data type to a time data type resulted in an out-of-range value.)~~ + + +SELECT CONVERT(TIME, '11Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, ' 11:22 Z') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 AM Z') +GO +~~START~~ +time +11:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 PM Z') +GO +~~START~~ +time +23:22:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22.123Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 AM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22.123 PM Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22 :12Z') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 AM Z') +GO +~~START~~ +time +11:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12 PM Z') +GO +~~START~~ +time +23:22:12.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '11 :22:12:123Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12:1234Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11:22:12:123 AM Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12 :123 PM Z') +GO +~~START~~ +time +23:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11: 22:12.123Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 1234Z') +GO +~~START~~ +time +11:22:12.1234000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123456789Z') +GO +~~START~~ +time +11:22:12.1234570 +~~END~~ + + +SELECT CONVERT(TIME, '11:22 :12.1234567891Z') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '11: 22:12.123 AM Z') +GO +~~START~~ +time +11:22:12.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '11:22:12. 123234 PM Z') +GO +~~START~~ +time +23:22:12.1232340 +~~END~~ + + +-- default value if only DATE is passed +SELECT CONVERT(TIME, '2000-04-22') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 0) +GO +~~START~~ +time +11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '02/12/21', 1) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '21.02.12', 2) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12/02/21', 3) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12.02.21', 4) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12-02-21', 5) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 21', 6) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12, 21', 7) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '10:13:14', 8) +GO +~~START~~ +time +10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '10:13:14', 24) +GO +~~START~~ +time +10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO +~~START~~ +time +10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '02-12-21', 10) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '21/02/12', 11) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '210212', 12) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 13) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '15:13:14:123', 14) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 20) +GO +~~START~~ +time +15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 21) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '02/12/21 15:13:14 PM', 22) +GO +~~START~~ +time +15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12', 23) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 25) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 100) +GO +~~START~~ +time +11:12:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '02/12/2021', 101) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021.02.12', 102) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12/02/2021', 103) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12.02.2021', 104) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12-02-2021', 105) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 2021', 106) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12, 2021', 107) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '10:13:14', 108) +GO +~~START~~ +time +10:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO +~~START~~ +time +10:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '02-12-2021', 110) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021/02/12', 111) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '20210212', 112) +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 113) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '15:13:14:123', 114) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 120) +GO +~~START~~ +time +15:13:14.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 121) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 126) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 127) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +SELECT CONVERT(TIME, N'22 محرم 1440 1:39:17.090', 130) +GO +~~START~~ +time +01:39:17.0900000 +~~END~~ + + +SELECT CONVERT(TIME, '12/02/2021 15:13:14:123 PM', 131) +GO +~~START~~ +time +15:13:14.1230000 +~~END~~ + + +-- -- misc +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +time +20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2020') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '2001-04-022 16:23:51.766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + + +SELECT CONVERT(TIME, '02001-04-22 16:23:51.766890 +12:00') +GO +SELECT CONVERT(TIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '02001-04-22 16:23:51') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '1900-05-06 13:59:29.050 -8:00') +GO +~~START~~ +time +13:59:29.0500000 +~~END~~ + + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Conversion failed when converting date and/or time from character string.)~~ + + +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO +~~START~~ +time +20:01:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2020') +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT CONVERT(TIME, '2022-10-30T03:00:00') +GO +~~START~~ +time +03:00:00.0000000 +~~END~~ + + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(TIME, @TM_ICLO) +GO +~~START~~ +time +17:24:07.1766670 +~~END~~ + + +-- Dependent objects +SELECT * FROM test_conv_string_to_time_v1 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p1 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f1() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v2 +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p2 +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f2() +GO +~~START~~ +time +00:00:00.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v3 +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p3 +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f3() +GO +~~START~~ +time +01:01:01.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v4 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p4 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f4() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v5 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p5 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f5() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v6 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p6 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f6() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v7 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p7 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f7() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to time is not allowed.)~~ + +EXEC test_conv_string_to_time_p8 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to time is not allowed.)~~ + +SELECT test_conv_string_to_time_f8() +GO +~~START~~ +time +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to time is not allowed.)~~ + + +SELECT * FROM test_conv_string_to_time_v9 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +EXEC test_conv_string_to_time_p9 +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + +SELECT test_conv_string_to_time_f9() +GO +~~START~~ +time +13:01:59.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v10 +GO +~~START~~ +time +11:11:11.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v11 +GO +~~START~~ +time +11:11:11.0000000 +~~END~~ + + +SELECT * FROM test_conv_string_to_time_v12 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Explicit conversion from data type integer to time is not allowed.)~~ + diff --git a/test/JDBC/input/BABEL-3486-before-17_3-vu-prepare.sql b/test/JDBC/input/BABEL-3486-before-17_3-vu-prepare.sql new file mode 100644 index 0000000000..74d18b75bb --- /dev/null +++ b/test/JDBC/input/BABEL-3486-before-17_3-vu-prepare.sql @@ -0,0 +1,1228 @@ +-- Convert BIGINT valid operations +CREATE VIEW BABEL_3486_vu_prepare_v13 as (SELECT TRY_CONVERT(bigint, 5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p13 as (SELECT TRY_CONVERT(bigint, 5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f13() +RETURNS BIGINT AS +BEGIN +RETURN (SELECT TRY_CONVERT(bigint, 5)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v14 as (SELECT TRY_CONVERT(bigint, -5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p14 as (SELECT TRY_CONVERT(bigint, -5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f14() +RETURNS BIGINT AS +BEGIN +RETURN (SELECT TRY_CONVERT(bigint, -5)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v15 as (SELECT TRY_CONVERT(bigint, 9223372036854775808)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p15 as (SELECT TRY_CONVERT(bigint, 9223372036854775808)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f15() +RETURNS BIGINT AS +BEGIN +RETURN (SELECT TRY_CONVERT(bigint, 9223372036854775808)); +END +GO + +-- Convert int valid operations +CREATE VIEW BABEL_3486_vu_prepare_v16 as (SELECT TRY_CONVERT(int, 5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p16 as (SELECT TRY_CONVERT(int, 5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f16() +RETURNS INT AS +BEGIN +RETURN (SELECT TRY_CONVERT(int, 5)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v17 as (SELECT TRY_CONVERT(int, -5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p17 as (SELECT TRY_CONVERT(int, -5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f17() +RETURNS int AS +BEGIN +RETURN (SELECT TRY_CONVERT(int, -5)); +END +GO + +-- Convert int invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v18 as (SELECT TRY_CONVERT(int, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p18 as (SELECT TRY_CONVERT(int, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f18() +RETURNS int AS +BEGIN +RETURN (SELECT TRY_CONVERT(int, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v19 as (SELECT TRY_CONVERT(int, 2147483648)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p19 as (SELECT TRY_CONVERT(int, 2147483648)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f19() +RETURNS int AS +BEGIN +RETURN (SELECT TRY_CONVERT(int, 2147483648)); +END +GO + +-- Convert smallint valid operations +CREATE VIEW BABEL_3486_vu_prepare_v20 as (SELECT TRY_CONVERT(smallint, 5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p20 as (SELECT TRY_CONVERT(smallint, 5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f20() +RETURNS smallint AS +BEGIN +RETURN (SELECT TRY_CONVERT(smallint, 5)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v21 as (SELECT TRY_CONVERT(smallint, -5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p21 as (SELECT TRY_CONVERT(smallint, -5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f21() +RETURNS smallint AS +BEGIN +RETURN (SELECT TRY_CONVERT(smallint, -5)); +END +GO + +-- Convert smallint invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v22 as (SELECT TRY_CONVERT(smallint, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p22 as (SELECT TRY_CONVERT(smallint, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f22() +RETURNS smallint AS +BEGIN +RETURN (SELECT TRY_CONVERT(smallint, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v23 as (SELECT TRY_CONVERT(smallint, 32768)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p23 as (SELECT TRY_CONVERT(smallint, 32768)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f23() +RETURNS smallint AS +BEGIN +RETURN (SELECT TRY_CONVERT(smallint, 32768)); +END +GO + +-- Convert bit valid operations +CREATE VIEW BABEL_3486_vu_prepare_v24 as (SELECT TRY_CONVERT(bit, 1)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p24 as (SELECT TRY_CONVERT(bit, 1)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f24() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, 1)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v25 as (SELECT TRY_CONVERT(bit, 0)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p25 as (SELECT TRY_CONVERT(bit, 0)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f25() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, 0)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v26 as (SELECT TRY_CONVERT(bit, 5)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p26 as (SELECT TRY_CONVERT(bit, 5)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f26() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, 5)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v27 as (SELECT TRY_CONVERT(bit, CAST(5.0 AS decimal))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p27 as (SELECT TRY_CONVERT(bit, CAST(5.0 AS decimal))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f27() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, CAST(5.0 AS decimal))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v28 as (SELECT TRY_CONVERT(bit, null)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p28 as (SELECT TRY_CONVERT(bit, null)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f28() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, null)); +END +GO + +-- Convert bit invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v29 as (SELECT TRY_CONVERT(bit, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p29 as (SELECT TRY_CONVERT(bit, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f29() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v29_2 as (SELECT TRY_CONVERT(bit, CAST('13:01:59' AS time))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p29_2 as (SELECT TRY_CONVERT(bit, CAST('13:01:59' AS time))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f29_2() +RETURNS bit AS +BEGIN +RETURN (SELECT TRY_CONVERT(bit, CAST('13:01:59' AS time))); +END +GO + +-- Convert numeric valid +CREATE VIEW BABEL_3486_vu_prepare_v30 as (SELECT TRY_CONVERT(numeric(3,2), 5.33)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p30 as (SELECT TRY_CONVERT(numeric(3,2), 5.33)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f30() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(3,2), 5.33)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v31 as (SELECT TRY_CONVERT(numeric(2,1), -5.34)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p31 as (SELECT TRY_CONVERT(numeric(2,1), -5.34)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f31() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(2,1), -5.34)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v32 as (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p32 as (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f32() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v33 as (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal(2,1)))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p33 as (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal(2,1)))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f33() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(2,1), CAST(5.0 AS decimal(2,1)))); +END +GO + +-- Convert numeric invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v34 as (SELECT TRY_CONVERT(numeric(2,1), 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p34 as (SELECT TRY_CONVERT(numeric(2,1), 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f34() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(2,1), 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v35 as (SELECT TRY_CONVERT(numeric(2,1), CAST('13:01:59' AS time))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p35 as (SELECT TRY_CONVERT(numeric(2,1), CAST('13:01:59' AS time))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f35() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(2,1), CAST('13:01:59' AS time))); +END +GO + + +CREATE PROCEDURE BABEL_3486_vu_prepare_p35_2 as (SELECT TRY_CONVERT(numeric(1,2), CAST(5.0 AS decimal))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f35_2() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(1,2), CAST(5.0 AS decimal))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v36 as (SELECT TRY_CONVERT(numeric(1,1), CAST(5.0 AS decimal))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p36 as (SELECT TRY_CONVERT(numeric(1,1), CAST(5.0 AS decimal))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f36() +RETURNS numeric AS +BEGIN +RETURN (SELECT TRY_CONVERT(numeric(1,1), CAST(5.0 AS decimal))); +END +GO + +-- Convert decimal valid operations +CREATE VIEW BABEL_3486_vu_prepare_v37 as (SELECT TRY_CONVERT(decimal(3,2), 5.33)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p37 as (SELECT TRY_CONVERT(decimal(3,2), 5.33)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f37() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal(3,2), 5.33)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v38 as (SELECT TRY_CONVERT(decimal(1,0), -5.34)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p38 as (SELECT TRY_CONVERT(decimal(1,0), -5.34)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f38() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal(1,0), -5.34)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v39 as (SELECT TRY_CONVERT(decimal(1,0), CAST(5.0 AS numeric(2,1)))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p39 as (SELECT TRY_CONVERT(decimal(1,0), CAST(5.0 AS numeric(2,1)))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f39() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal(1,0), CAST(5.0 AS numeric(2,1)))); +END +GO + +-- Convert decimal invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v40 as (SELECT TRY_CONVERT(decimal, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p40 as (SELECT TRY_CONVERT(decimal, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f40() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v41 as (SELECT TRY_CONVERT(decimal(1,1), -5.34)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p41 as (SELECT TRY_CONVERT(decimal(1,1), -5.34)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f41() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal(1,1), -5.34)); +END +GO + + +CREATE PROCEDURE BABEL_3486_vu_prepare_p42 as (SELECT TRY_CONVERT(decimal(1,2), CAST(5.0 AS numeric(2,1)))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f42() +RETURNS decimal AS +BEGIN +RETURN (SELECT TRY_CONVERT(decimal(1,2), CAST(5.0 AS numeric(2,1)))); +END +GO + + +-- Convert money valid operations +CREATE VIEW BABEL_3486_vu_prepare_v43 as (SELECT TRY_CONVERT(MONEY, 5.33)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p43 as (SELECT TRY_CONVERT(MONEY, 5.33)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f43() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, 5.33)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v44 as (SELECT TRY_CONVERT(MONEY, 5.335432)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p44 as (SELECT TRY_CONVERT(MONEY, 5.335432)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f44() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, 5.335432)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v45 as (SELECT TRY_CONVERT(MONEY, -5.33)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p45 as (SELECT TRY_CONVERT(MONEY, -5.33)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f45() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, -5.33)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v46 as (SELECT TRY_CONVERT(MONEY, '-5.33')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p46 as (SELECT TRY_CONVERT(MONEY, '-5.33')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f46() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, '-5.33')); +END +GO + +-- Convert money invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v47 as (SELECT TRY_CONVERT(MONEY, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p47 as (SELECT TRY_CONVERT(MONEY, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f47() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v47_2 as (SELECT TRY_CONVERT(MONEY, CAST('2017-08-25' AS date))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p47_2 as (SELECT TRY_CONVERT(MONEY, CAST('2017-08-25' AS date))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f47_2() +RETURNS MONEY AS +BEGIN +RETURN (SELECT TRY_CONVERT(MONEY, CAST('2017-08-25' AS date))); +END +GO + +-- Convert float valid operations +CREATE VIEW BABEL_3486_vu_prepare_v48 as (SELECT TRY_CONVERT(float, 5.33)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p48 as (SELECT TRY_CONVERT(float, 5.33)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f48() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, 5.33)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v49 as (SELECT TRY_CONVERT(float, -5.335432)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p49 as (SELECT TRY_CONVERT(float, -5.335432)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f49() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, -5.335432)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v50 as (SELECT TRY_CONVERT(float, CAST(5.0 AS numeric(2,0)))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p50 as (SELECT TRY_CONVERT(float, CAST(5.0 AS numeric(2,0)))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f50() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, CAST(5.0 AS numeric(2,0)))); +END +GO + +-- Convert float invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v51 as (SELECT TRY_CONVERT(float, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p51 as (SELECT TRY_CONVERT(float, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f51() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v52 as (SELECT TRY_CONVERT(float, CAST('2017-08-25' AS date))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p52 as (SELECT TRY_CONVERT(float, CAST('2017-08-25' AS date))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f52() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, CAST('2017-08-25' AS date))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v53 as (SELECT TRY_CONVERT(float, CAST('13:01:59' AS time))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p53 as (SELECT TRY_CONVERT(float, CAST('13:01:59' AS time))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f53() +RETURNS float AS +BEGIN +RETURN (SELECT TRY_CONVERT(float, CAST('13:01:59' AS time))); +END +GO + +-- Convert varchar valid operations +CREATE VIEW BABEL_3486_vu_prepare_v54 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS MONEY))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p54 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS MONEY))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f54() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5 AS MONEY), 1)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v55 as (SELECT TRY_CONVERT(varchar(30), CAST('13:01:59' AS time), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p55 as (SELECT TRY_CONVERT(varchar(30), CAST('13:01:59' AS time), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f55() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST('13:01:59' AS time), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v56 as (SELECT TRY_CONVERT(varchar(2), CAST('13:01:59' AS time), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p56 as (SELECT TRY_CONVERT(varchar(2), CAST('13:01:59' AS time), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f56() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(2), CAST('13:01:59' AS time), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v57 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS bigint), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p57 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS bigint), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f57() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5 AS bigint), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v58 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS smallint), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p58 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS smallint), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f58() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5 AS smallint), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v59 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS int), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p59 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS int), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f59() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5 AS int), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v60 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS numeric), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p60 as (SELECT TRY_CONVERT(varchar(30), CAST(5 AS numeric), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f60() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5 AS numeric), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v61 as (SELECT TRY_CONVERT(varchar(30), CAST(5.0 AS decimal), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p61 as (SELECT TRY_CONVERT(varchar(30), CAST(5.0 AS decimal), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f61() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(5.0 AS decimal), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v62 as (SELECT TRY_CONVERT(varchar(30), CAST(1 AS bit), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p62 as (SELECT TRY_CONVERT(varchar(30), CAST(1 AS bit), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f62() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST(1 AS bit), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v63 as (SELECT TRY_CONVERT(varchar(30), CAST(1 AS smallmoney), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p63 as ((SELECT TRY_CONVERT(varchar(30), CAST(1 AS smallmoney), 8))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f63() +RETURNS varchar AS +BEGIN +RETURN ((SELECT TRY_CONVERT(varchar(30), CAST(1 AS smallmoney), 8))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v64 as (SELECT TRY_CONVERT(varchar(30), 'test', 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p64 as (SELECT TRY_CONVERT(varchar(30), 'test', 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f64() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), 'test', 8)); +END +GO + +-- Convert Varchar invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v65 as (SELECT TRY_CONVERT(varchar(30), CAST('2017-08-25' AS date), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p65 as (SELECT TRY_CONVERT(varchar(30), CAST('2017-08-25' AS date), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f65() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(varchar(30), CAST('2017-08-25' AS date), 8)); +END +GO + +-- Convert text valid operations +CREATE VIEW BABEL_3486_vu_prepare_v66 as (SELECT TRY_CONVERT(text, CAST(5 AS MONEY), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p66 as (SELECT TRY_CONVERT(text, CAST(5 AS MONEY), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f66() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5 AS MONEY), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v67 as (SELECT TRY_CONVERT(text, CAST('2017-08-25' AS date), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p67 as (SELECT TRY_CONVERT(text, CAST('2017-08-25' AS date), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f67() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST('2017-08-25' AS date), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v68 as (SELECT TRY_CONVERT(text, CAST(5 AS bigint), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p68 as (SELECT TRY_CONVERT(text, CAST(5 AS bigint), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f68() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5 AS bigint), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v69 as (SELECT TRY_CONVERT(text, CAST(5 AS smallint), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p69 as (SELECT TRY_CONVERT(text, CAST(5 AS smallint), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f69() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5 AS smallint), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v70 as (SELECT TRY_CONVERT(text, CAST(5 AS int), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p70 as (SELECT TRY_CONVERT(text, CAST(5 AS int), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f70() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5 AS int), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v71 as (SELECT TRY_CONVERT(text, CAST(5 AS numeric), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p71 as (SELECT TRY_CONVERT(text, CAST(5 AS numeric), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f71() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5 AS numeric), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v72 as (SELECT TRY_CONVERT(text, CAST(5.0 AS decimal), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p72 as (SELECT TRY_CONVERT(text, CAST(5.0 AS decimal), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f72() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(5.0 AS decimal), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v73 as (SELECT TRY_CONVERT(text, CAST(1 AS bit), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p73 as (SELECT TRY_CONVERT(text, CAST(1 AS bit), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f73() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(1 AS bit), 8)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v74 as (SELECT TRY_CONVERT(text, CAST(1 AS smallmoney), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p74 as (SELECT TRY_CONVERT(text, CAST(1 AS smallmoney), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f74() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, CAST(1 AS smallmoney), 8)); +END +GO + +create table test(col varchar(10)) +GO +insert into test values ('1'),('2'),('3'),('4') +GO + +-- Convert text invalid operations +CREATE VIEW BABEL_3486_vu_prepare_v75 as (SELECT TRY_CONVERT(text, (select * from test), 8)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p75 as (SELECT TRY_CONVERT(text, (select * from test), 8)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f75() +RETURNS varchar AS +BEGIN +RETURN (SELECT TRY_CONVERT(text, (select * from test), 8)); +END +GO + +-- Convert date valid +CREATE VIEW BABEL_3486_vu_prepare_v76 as (SELECT TRY_CONVERT(date, '2017-08-25')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p76 as (SELECT TRY_CONVERT(date, '2017-08-25')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f76() +RETURNS date AS +BEGIN +RETURN (SELECT TRY_CONVERT(date, '2017-08-25')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v77 as (SELECT TRY_CONVERT(date, '9999-08-25')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p77 as (SELECT TRY_CONVERT(date, '9999-08-25')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f77() +RETURNS date AS +BEGIN +RETURN (SELECT TRY_CONVERT(date, '9999-08-25')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v78 as (SELECT TRY_CONVERT(date, '13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p78 as (SELECT TRY_CONVERT(date, '13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f78() +RETURNS date AS +BEGIN +RETURN (SELECT TRY_CONVERT(date, '13:01:59')); +END +GO + +-- Convert date invalid +CREATE VIEW BABEL_3486_vu_prepare_v79 as (SELECT TRY_CONVERT(date, '10000-08-25')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p79 as (SELECT TRY_CONVERT(date, '10000-08-25')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f79() +RETURNS date AS +BEGIN +RETURN (SELECT TRY_CONVERT(date, '10000-08-25')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v80 as (SELECT TRY_CONVERT(date, '5000-082-253')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p80 as (SELECT TRY_CONVERT(date, '5000-082-253')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f80() +RETURNS date AS +BEGIN +RETURN (SELECT TRY_CONVERT(date, '5000-082-253')); +END +GO + +-- Convert time valid +CREATE VIEW BABEL_3486_vu_prepare_v81 as (SELECT TRY_CONVERT(time, '13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p81 as (SELECT TRY_CONVERT(time, '13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f81() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '13:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v82 as (SELECT TRY_CONVERT(time, '00:00:00')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p82 as (SELECT TRY_CONVERT(time, '00:00:00')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f82() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '00:00:00')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v83 as (SELECT TRY_CONVERT(time, '1:1:1')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p83 as (SELECT TRY_CONVERT(time, '1:1:1')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f83() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '1:1:1')); +END +GO + +-- Convert time invalid +CREATE VIEW BABEL_3486_vu_prepare_v84 as (SELECT TRY_CONVERT(time, '9999-08-25')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p84 as (SELECT TRY_CONVERT(time, '9999-08-25')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f84() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '9999-08-25')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v85 as (SELECT TRY_CONVERT(time, '28:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p85 as (SELECT TRY_CONVERT(time, '28:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f85() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '28:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v86 as (SELECT TRY_CONVERT(time, '::59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p86 as (SELECT TRY_CONVERT(time, '::59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f86() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '::59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v87 as (SELECT TRY_CONVERT(time, '20:013:593')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p87 as (SELECT TRY_CONVERT(time, '20:013:593')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f87() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, '20:013:593')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v88 as (SELECT TRY_CONVERT(time, 'abc')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p88 as (SELECT TRY_CONVERT(time, 'abc')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f88() +RETURNS time AS +BEGIN +RETURN (SELECT TRY_CONVERT(time, 'abc')); +END +GO + +-- Convert smalldatetime valid +CREATE VIEW BABEL_3486_vu_prepare_v89 as (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p89 as (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f89() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v90 as (SELECT TRY_CONVERT(smalldatetime, '13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p90 as (SELECT TRY_CONVERT(smalldatetime, '13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f90() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(smalldatetime, '13:01:59')); +END +GO + +-- Convert smalldatetime invalid +CREATE VIEW BABEL_3486_vu_prepare_v91 as (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 26:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p91 as (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 26:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f91() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(smalldatetime, '2017-08-25 26:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v92 as (SELECT TRY_CONVERT(smalldatetime, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p92 as (SELECT TRY_CONVERT(smalldatetime, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f92() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(smalldatetime, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v93 as (SELECT TRY_CONVERT(smalldatetime, '1')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p93 as (SELECT TRY_CONVERT(smalldatetime, '1')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f93() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(smalldatetime, '1')); +END +GO + +-- Convert datetime valid +CREATE VIEW BABEL_3486_vu_prepare_v94 as (SELECT TRY_CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p94 as (SELECT TRY_CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f94() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v95 as (SELECT TRY_CONVERT(datetime, '13:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p95 as (SELECT TRY_CONVERT(datetime, '13:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f95() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, '13:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v96 as (SELECT TRY_CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p96 as (SELECT TRY_CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f96() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, '1753-01-01 0:01:59')); +END +GO + +-- Convert datetime invalid +CREATE VIEW BABEL_3486_vu_prepare_v97 as (SELECT TRY_CONVERT(datetime, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p97 as (SELECT TRY_CONVERT(datetime, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f97() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, 'a')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v98 as (SELECT TRY_CONVERT(datetime, '1752-01-01 0:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p98 as (SELECT TRY_CONVERT(datetime, '1752-01-01 0:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f98() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, '1752-01-01 0:01:59')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v99 as (SELECT TRY_CONVERT(datetime, '0001-01-01 0:01:59')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p99 as (SELECT TRY_CONVERT(datetime, '0001-01-01 0:01:59')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f99() +RETURNS datetime AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime, '0001-01-01 0:01:59')); +END +GO + +-- Convert datetime2 valid +CREATE VIEW BABEL_3486_vu_prepare_v100 as (SELECT TRY_CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p100 as (SELECT TRY_CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f100() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v101 as (SELECT TRY_CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p101 as (SELECT TRY_CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f101() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v102 as (SELECT TRY_CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p102 as (SELECT TRY_CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f102() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime2, '13:01:59')); +END +GO + +CREATE PROCEDURE BABEL_3486_vu_prepare_p102_2 as (SELECT TRY_CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f102_2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +END +GO + +-- Convert datetime2 invalid +CREATE VIEW BABEL_3486_vu_prepare_v103 as (SELECT TRY_CONVERT(datetime2, 'a')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p103 as (SELECT TRY_CONVERT(datetime2, 'a')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f103() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetime2, 'a')); +END +GO + +-- Convert datetimeoffset valid +CREATE VIEW BABEL_3486_vu_prepare_v104 as (SELECT TRY_CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p104 as (SELECT TRY_CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f104() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v105 as (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p105 as (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f105() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +12:15')); +END +GO + +-- Convert datetimeoffset invalid +CREATE VIEW BABEL_3486_vu_prepare_v106 as (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +25')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p106 as (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +25')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f106() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT TRY_CONVERT(datetimeoffset, '13:01:59 +25')); +END +GO + +-- Convert sql_variant valid +CREATE VIEW BABEL_3486_vu_prepare_v107 as (SELECT TRY_CONVERT(sql_variant, 1)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p107 as (SELECT TRY_CONVERT(sql_variant, 1)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f107() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, 1)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v108 as (SELECT TRY_CONVERT(sql_variant, 'test')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p108 as (SELECT TRY_CONVERT(sql_variant, 'test')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f108() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, 'test')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v109 as (SELECT TRY_CONVERT(sql_variant, CAST(1 as MONEY))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p109 as (SELECT TRY_CONVERT(sql_variant, CAST(1 as MONEY))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f109() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, CAST(1 as MONEY))); +END +GO + +-- This test case returns 2017-08-25 13:01:59.0 where SQL Server JDBC returns 2017-08-25 13:01:59 +CREATE VIEW BABEL_3486_vu_prepare_v110 as (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p110 as (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f110() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59' AS datetime))); +END +GO + +-- Results in error due to outdated JDBC version +-- Change when BABEL-2871 is resolved +CREATE VIEW BABEL_3486_vu_prepare_v111 as (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59 +12:15' AS datetimeoffset))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p111 as (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59 +12:15' AS datetimeoffset))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f111() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, CAST('2017-08-25 13:01:59 +12:15' AS datetimeoffset))); +END +GO + +-- Convert sql_variant invalid + +CREATE VIEW BABEL_3486_vu_prepare_v113 as (SELECT TRY_CONVERT(sql_variant, CAST('test' AS text))); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p113 as (SELECT TRY_CONVERT(sql_variant, CAST('test' AS text))); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f113() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(sql_variant, CAST('test' AS text))); +END +GO + +-- Valid uniqueidentifier +CREATE VIEW BABEL_3486_vu_prepare_v114 as (SELECT TRY_CONVERT(uniqueidentifier, '6F9619FF-8B86-D011-B42D-00C04FC964FF')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p114 as (SELECT TRY_CONVERT(uniqueidentifier, '6F9619FF-8B86-D011-B42D-00C04FC964FF')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f114() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(uniqueidentifier, '6F9619FF-8B86-D011-B42D-00C04FC964FF')); +END +GO + +-- Invalid uniqueidentifier +CREATE VIEW BABEL_3486_vu_prepare_v116 as (SELECT TRY_CONVERT(uniqueidentifier, 'unique')); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p116 as (SELECT TRY_CONVERT(uniqueidentifier, 'unique')); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f116() +RETURNS sql_variant AS +BEGIN +RETURN (SELECT TRY_CONVERT(uniqueidentifier, 'unique')); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v117 as (SELECT TRY_CAST(TRY_CAST (TRY_CONVERT(XML, '1990-01-01') as text) as date)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p117 as (SELECT TRY_CAST(TRY_CAST (TRY_CONVERT(XML, '1990-01-01') as text) as date)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f117() +RETURNS DATE AS +BEGIN +RETURN (SELECT TRY_CAST(TRY_CAST (TRY_CONVERT(XML, '1990-01-01') as text) as date)); +END +GO + +CREATE VIEW BABEL_3486_vu_prepare_v118 as (SELECT TRY_CAST(TRY_CONVERT(DATETIME, CAST('1990-01-01' AS DATE)) AS TIME)); +GO +CREATE PROCEDURE BABEL_3486_vu_prepare_p118 as (SELECT TRY_CAST(TRY_CONVERT(DATETIME, CAST('1990-01-01' AS DATE)) AS TIME)); +GO +CREATE FUNCTION BABEL_3486_vu_prepare_f118() +RETURNS TIME AS +BEGIN +RETURN (SELECT TRY_CAST(TRY_CONVERT(DATETIME, CAST('1990-01-01' AS DATE)) AS TIME)); +END +GO diff --git a/test/JDBC/input/BABEL-3486-before-17_3-vu-verify.sql b/test/JDBC/input/BABEL-3486-before-17_3-vu-verify.sql new file mode 100644 index 0000000000..79ca938924 --- /dev/null +++ b/test/JDBC/input/BABEL-3486-before-17_3-vu-verify.sql @@ -0,0 +1,1607 @@ +-- sla 50000 +SELECT * FROM BABEL_3486_vu_prepare_v13 +GO +DROP VIEW BABEL_3486_vu_prepare_v13 +GO + +EXEC BABEL_3486_vu_prepare_p13 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p13 +GO + +SELECT BABEL_3486_vu_prepare_f13() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f13() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v14 +GO +DROP VIEW BABEL_3486_vu_prepare_v14 +GO + +EXEC BABEL_3486_vu_prepare_p14 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p14 +GO + +SELECT BABEL_3486_vu_prepare_f14() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f14() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v15 +GO +DROP VIEW BABEL_3486_vu_prepare_v15 +GO + +EXEC BABEL_3486_vu_prepare_p15 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p15 +GO + +SELECT BABEL_3486_vu_prepare_f15() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f15() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v16 +GO +DROP VIEW BABEL_3486_vu_prepare_v16 +GO + +EXEC BABEL_3486_vu_prepare_p16 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p16 +GO + +SELECT BABEL_3486_vu_prepare_f16() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f16() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v17 +GO +DROP VIEW BABEL_3486_vu_prepare_v17 +GO + +EXEC BABEL_3486_vu_prepare_p17 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p17 +GO + +SELECT BABEL_3486_vu_prepare_f17() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f17() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v18 +GO +DROP VIEW BABEL_3486_vu_prepare_v18 +GO + +EXEC BABEL_3486_vu_prepare_p18 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p18 +GO + +SELECT BABEL_3486_vu_prepare_f18() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f18() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v19 +GO +DROP VIEW BABEL_3486_vu_prepare_v19 +GO + +EXEC BABEL_3486_vu_prepare_p19 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p19 +GO + +SELECT BABEL_3486_vu_prepare_f19() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f19() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v20 +GO +DROP VIEW BABEL_3486_vu_prepare_v20 +GO + +EXEC BABEL_3486_vu_prepare_p20 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p20 +GO + +SELECT BABEL_3486_vu_prepare_f20() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f20() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v21 +GO +DROP VIEW BABEL_3486_vu_prepare_v21 +GO + +EXEC BABEL_3486_vu_prepare_p21 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p21 +GO + +SELECT BABEL_3486_vu_prepare_f21() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f21() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v22 +GO +DROP VIEW BABEL_3486_vu_prepare_v22 +GO + +EXEC BABEL_3486_vu_prepare_p22 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p22 +GO + +SELECT BABEL_3486_vu_prepare_f22() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f22() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v23 +GO +DROP VIEW BABEL_3486_vu_prepare_v23 +GO + +EXEC BABEL_3486_vu_prepare_p23 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p23 +GO + +SELECT BABEL_3486_vu_prepare_f23() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f23() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v24 +GO +DROP VIEW BABEL_3486_vu_prepare_v24 +GO + +EXEC BABEL_3486_vu_prepare_p24 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p24 +GO + +SELECT BABEL_3486_vu_prepare_f24() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f24() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v25 +GO +DROP VIEW BABEL_3486_vu_prepare_v25 +GO + +EXEC BABEL_3486_vu_prepare_p25 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p25 +GO + +SELECT BABEL_3486_vu_prepare_f25() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f25() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v26 +GO +DROP VIEW BABEL_3486_vu_prepare_v26 +GO + +EXEC BABEL_3486_vu_prepare_p26 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p26 +GO + +SELECT BABEL_3486_vu_prepare_f26() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f26() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v27 +GO +DROP VIEW BABEL_3486_vu_prepare_v27 +GO + +EXEC BABEL_3486_vu_prepare_p27 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p27 +GO + +SELECT BABEL_3486_vu_prepare_f27() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f27() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v28 +GO +DROP VIEW BABEL_3486_vu_prepare_v28 +GO + +EXEC BABEL_3486_vu_prepare_p28 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p28 +GO + +SELECT BABEL_3486_vu_prepare_f28() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f28() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v29 +GO +DROP VIEW BABEL_3486_vu_prepare_v29 +GO + +EXEC BABEL_3486_vu_prepare_p29 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p29 +GO + +SELECT BABEL_3486_vu_prepare_f29() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f29() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v29_2 +GO +DROP VIEW BABEL_3486_vu_prepare_v29_2 +GO + +EXEC BABEL_3486_vu_prepare_p29_2 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p29_2 +GO + +SELECT BABEL_3486_vu_prepare_f29_2() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f29_2() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v30 +GO +DROP VIEW BABEL_3486_vu_prepare_v30 +GO + +EXEC BABEL_3486_vu_prepare_p30 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p30 +GO + +SELECT BABEL_3486_vu_prepare_f30() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f30() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v31 +GO +DROP VIEW BABEL_3486_vu_prepare_v31 +GO + +EXEC BABEL_3486_vu_prepare_p31 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p31 +GO + +SELECT BABEL_3486_vu_prepare_f31() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f31() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v32 +GO +DROP VIEW BABEL_3486_vu_prepare_v32 +GO + +EXEC BABEL_3486_vu_prepare_p32 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p32 +GO + +SELECT BABEL_3486_vu_prepare_f32() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f32() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v33 +GO +DROP VIEW BABEL_3486_vu_prepare_v33 +GO + +EXEC BABEL_3486_vu_prepare_p33 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p33 +GO + +SELECT BABEL_3486_vu_prepare_f33() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f33() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v34 +GO +DROP VIEW BABEL_3486_vu_prepare_v34 +GO + +EXEC BABEL_3486_vu_prepare_p34 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p34 +GO + +SELECT BABEL_3486_vu_prepare_f34() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f34() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v35 +GO +DROP VIEW BABEL_3486_vu_prepare_v35 +GO + +EXEC BABEL_3486_vu_prepare_p35 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p35 +GO + +SELECT BABEL_3486_vu_prepare_f35() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f35() +GO + +EXEC BABEL_3486_vu_prepare_p35_2 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p35_2 +GO + +SELECT BABEL_3486_vu_prepare_f35_2() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f35_2() + +SELECT * FROM BABEL_3486_vu_prepare_v36 +GO +DROP VIEW BABEL_3486_vu_prepare_v36 +GO + +EXEC BABEL_3486_vu_prepare_p36 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p36 +GO + +SELECT BABEL_3486_vu_prepare_f36() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f36() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v37 +GO +DROP VIEW BABEL_3486_vu_prepare_v37 +GO + +EXEC BABEL_3486_vu_prepare_p37 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p37 +GO + +SELECT BABEL_3486_vu_prepare_f37() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f37() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v38 +GO +DROP VIEW BABEL_3486_vu_prepare_v38 +GO + +EXEC BABEL_3486_vu_prepare_p38 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p38 +GO + +SELECT BABEL_3486_vu_prepare_f38() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f38() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v39 +GO +DROP VIEW BABEL_3486_vu_prepare_v39 +GO + +EXEC BABEL_3486_vu_prepare_p39 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p39 +GO + +SELECT BABEL_3486_vu_prepare_f39() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f39() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v40 +GO +DROP VIEW BABEL_3486_vu_prepare_v40 +GO + +EXEC BABEL_3486_vu_prepare_p40 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p40 +GO + +SELECT BABEL_3486_vu_prepare_f40() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f40() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v41 +GO +DROP VIEW BABEL_3486_vu_prepare_v41 +GO + +EXEC BABEL_3486_vu_prepare_p41 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p41 +GO + +SELECT BABEL_3486_vu_prepare_f41() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f41() +GO + +EXEC BABEL_3486_vu_prepare_p42 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p42 +GO + +SELECT BABEL_3486_vu_prepare_f42() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f42() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v43 +GO +DROP VIEW BABEL_3486_vu_prepare_v43 +GO + +EXEC BABEL_3486_vu_prepare_p43 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p43 +GO + +SELECT BABEL_3486_vu_prepare_f43() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f43() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v44 +GO +DROP VIEW BABEL_3486_vu_prepare_v44 +GO + +EXEC BABEL_3486_vu_prepare_p44 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p44 +GO + +SELECT BABEL_3486_vu_prepare_f44() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f44() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v45 +GO +DROP VIEW BABEL_3486_vu_prepare_v45 +GO + +EXEC BABEL_3486_vu_prepare_p45 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p45 +GO + +SELECT BABEL_3486_vu_prepare_f45() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f45() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v46 +GO +DROP VIEW BABEL_3486_vu_prepare_v46 +GO + +EXEC BABEL_3486_vu_prepare_p46 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p46 +GO + +SELECT BABEL_3486_vu_prepare_f46() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f46() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v47 +GO +DROP VIEW BABEL_3486_vu_prepare_v47 +GO + +EXEC BABEL_3486_vu_prepare_p47 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p47 +GO + +SELECT BABEL_3486_vu_prepare_f47() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f47() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v47_2 +GO +DROP VIEW BABEL_3486_vu_prepare_v47_2 +GO + +EXEC BABEL_3486_vu_prepare_p47_2 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p47_2 +GO + +SELECT BABEL_3486_vu_prepare_f47_2() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f47_2() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v48 +GO +DROP VIEW BABEL_3486_vu_prepare_v48 +GO + +EXEC BABEL_3486_vu_prepare_p48 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p48 +GO + +SELECT BABEL_3486_vu_prepare_f48() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f48() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v49 +GO +DROP VIEW BABEL_3486_vu_prepare_v49 +GO + +EXEC BABEL_3486_vu_prepare_p49 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p49 +GO + +SELECT BABEL_3486_vu_prepare_f49() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f49() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v50 +GO +DROP VIEW BABEL_3486_vu_prepare_v50 +GO + +EXEC BABEL_3486_vu_prepare_p50 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p50 +GO + +SELECT BABEL_3486_vu_prepare_f50() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f50() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v51 +GO +DROP VIEW BABEL_3486_vu_prepare_v51 +GO + +EXEC BABEL_3486_vu_prepare_p51 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p51 +GO + +SELECT BABEL_3486_vu_prepare_f51() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f51() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v52 +GO +DROP VIEW BABEL_3486_vu_prepare_v52 +GO + +EXEC BABEL_3486_vu_prepare_p52 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p52 +GO + +SELECT BABEL_3486_vu_prepare_f52() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f52() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v53 +GO +DROP VIEW BABEL_3486_vu_prepare_v53 +GO + +EXEC BABEL_3486_vu_prepare_p53 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p53 +GO + +SELECT BABEL_3486_vu_prepare_f53() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f53() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v54 +GO +DROP VIEW BABEL_3486_vu_prepare_v54 +GO + +EXEC BABEL_3486_vu_prepare_p54 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p54 +GO + +SELECT BABEL_3486_vu_prepare_f54() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f54() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v55 +GO +DROP VIEW BABEL_3486_vu_prepare_v55 +GO + +EXEC BABEL_3486_vu_prepare_p55 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p55 +GO + +SELECT BABEL_3486_vu_prepare_f55() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f55() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v56 +GO +DROP VIEW BABEL_3486_vu_prepare_v56 +GO + +EXEC BABEL_3486_vu_prepare_p56 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p56 +GO + +SELECT BABEL_3486_vu_prepare_f56() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f56() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v57 +GO +DROP VIEW BABEL_3486_vu_prepare_v57 +GO + +EXEC BABEL_3486_vu_prepare_p57 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p57 +GO + +SELECT BABEL_3486_vu_prepare_f57() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f57() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v58 +GO +DROP VIEW BABEL_3486_vu_prepare_v58 +GO + +EXEC BABEL_3486_vu_prepare_p58 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p58 +GO + +SELECT BABEL_3486_vu_prepare_f58() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f58() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v59 +GO +DROP VIEW BABEL_3486_vu_prepare_v59 +GO + +EXEC BABEL_3486_vu_prepare_p59 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p59 +GO + +SELECT BABEL_3486_vu_prepare_f59() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f59() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v60 +GO +DROP VIEW BABEL_3486_vu_prepare_v60 +GO + +EXEC BABEL_3486_vu_prepare_p60 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p60 +GO + +SELECT BABEL_3486_vu_prepare_f60() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f60() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v61 +GO +DROP VIEW BABEL_3486_vu_prepare_v61 +GO + +EXEC BABEL_3486_vu_prepare_p61 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p61 +GO + +SELECT BABEL_3486_vu_prepare_f61() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f61() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v62 +GO +DROP VIEW BABEL_3486_vu_prepare_v62 +GO + +EXEC BABEL_3486_vu_prepare_p62 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p62 +GO + +SELECT BABEL_3486_vu_prepare_f62() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f62() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v63 +GO +DROP VIEW BABEL_3486_vu_prepare_v63 +GO + +EXEC BABEL_3486_vu_prepare_p63 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p63 +GO + +SELECT BABEL_3486_vu_prepare_f63() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f63() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v64 +GO +DROP VIEW BABEL_3486_vu_prepare_v64 +GO + +EXEC BABEL_3486_vu_prepare_p64 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p64 +GO + +SELECT BABEL_3486_vu_prepare_f64() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f64() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v65 +GO +DROP VIEW BABEL_3486_vu_prepare_v65 +GO + +EXEC BABEL_3486_vu_prepare_p65 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p65 +GO + +SELECT BABEL_3486_vu_prepare_f65() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f65() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v66 +GO +DROP VIEW BABEL_3486_vu_prepare_v66 +GO + +EXEC BABEL_3486_vu_prepare_p66 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p66 +GO + +SELECT BABEL_3486_vu_prepare_f66() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f66() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v67 +GO +DROP VIEW BABEL_3486_vu_prepare_v67 +GO + +EXEC BABEL_3486_vu_prepare_p67 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p67 +GO + +SELECT BABEL_3486_vu_prepare_f67() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f67() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v68 +GO +DROP VIEW BABEL_3486_vu_prepare_v68 +GO + +EXEC BABEL_3486_vu_prepare_p68 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p68 +GO + +SELECT BABEL_3486_vu_prepare_f68() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f68() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v69 +GO +DROP VIEW BABEL_3486_vu_prepare_v69 +GO + +EXEC BABEL_3486_vu_prepare_p69 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p69 +GO + +SELECT BABEL_3486_vu_prepare_f69() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f69() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v70 +GO +DROP VIEW BABEL_3486_vu_prepare_v70 +GO + +EXEC BABEL_3486_vu_prepare_p70 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p70 +GO + +SELECT BABEL_3486_vu_prepare_f70() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f70() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v71 +GO +DROP VIEW BABEL_3486_vu_prepare_v71 +GO + +EXEC BABEL_3486_vu_prepare_p71 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p71 +GO + +SELECT BABEL_3486_vu_prepare_f71() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f71() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v72 +GO +DROP VIEW BABEL_3486_vu_prepare_v72 +GO + +EXEC BABEL_3486_vu_prepare_p72 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p72 +GO + +SELECT BABEL_3486_vu_prepare_f72() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f72() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v73 +GO +DROP VIEW BABEL_3486_vu_prepare_v73 +GO + +EXEC BABEL_3486_vu_prepare_p73 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p73 +GO + +SELECT BABEL_3486_vu_prepare_f73() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f73() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v74 +GO +DROP VIEW BABEL_3486_vu_prepare_v74 +GO + +EXEC BABEL_3486_vu_prepare_p74 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p74 +GO + +SELECT BABEL_3486_vu_prepare_f74() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f74() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v75 +GO +DROP VIEW BABEL_3486_vu_prepare_v75 +GO + +EXEC BABEL_3486_vu_prepare_p75 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p75 +GO + +SELECT BABEL_3486_vu_prepare_f75() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f75() +GO + +drop table test +GO + +SELECT * FROM BABEL_3486_vu_prepare_v76 +GO +DROP VIEW BABEL_3486_vu_prepare_v76 +GO + +EXEC BABEL_3486_vu_prepare_p76 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p76 +GO + +SELECT BABEL_3486_vu_prepare_f76() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f76() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v77 +GO +DROP VIEW BABEL_3486_vu_prepare_v77 +GO + +EXEC BABEL_3486_vu_prepare_p77 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p77 +GO + +SELECT BABEL_3486_vu_prepare_f77() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f77() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v78 +GO +DROP VIEW BABEL_3486_vu_prepare_v78 +GO + +EXEC BABEL_3486_vu_prepare_p78 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p78 +GO + +SELECT BABEL_3486_vu_prepare_f78() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f78() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v79 +GO +DROP VIEW BABEL_3486_vu_prepare_v79 +GO + +EXEC BABEL_3486_vu_prepare_p79 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p79 +GO + +SELECT BABEL_3486_vu_prepare_f79() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f79() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v80 +GO +DROP VIEW BABEL_3486_vu_prepare_v80 +GO + +EXEC BABEL_3486_vu_prepare_p80 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p80 +GO + +SELECT BABEL_3486_vu_prepare_f80() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f80() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v81 +GO +DROP VIEW BABEL_3486_vu_prepare_v81 +GO + +EXEC BABEL_3486_vu_prepare_p81 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p81 +GO + +SELECT BABEL_3486_vu_prepare_f81() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f81() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v82 +GO +DROP VIEW BABEL_3486_vu_prepare_v82 +GO + +EXEC BABEL_3486_vu_prepare_p82 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p82 +GO + +SELECT BABEL_3486_vu_prepare_f82() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f82() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v83 +GO +DROP VIEW BABEL_3486_vu_prepare_v83 +GO + +EXEC BABEL_3486_vu_prepare_p83 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p83 +GO + +SELECT BABEL_3486_vu_prepare_f83() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f83() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v84 +GO +DROP VIEW BABEL_3486_vu_prepare_v84 +GO + +EXEC BABEL_3486_vu_prepare_p84 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p84 +GO + +SELECT BABEL_3486_vu_prepare_f84() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f84() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v85 +GO +DROP VIEW BABEL_3486_vu_prepare_v85 +GO + +EXEC BABEL_3486_vu_prepare_p85 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p85 +GO + +SELECT BABEL_3486_vu_prepare_f85() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f85() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v86 +GO +DROP VIEW BABEL_3486_vu_prepare_v86 +GO + +EXEC BABEL_3486_vu_prepare_p86 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p86 +GO + +SELECT BABEL_3486_vu_prepare_f86() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f86() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v87 +GO +DROP VIEW BABEL_3486_vu_prepare_v87 +GO + +EXEC BABEL_3486_vu_prepare_p87 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p87 +GO + +SELECT BABEL_3486_vu_prepare_f87() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f87() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v88 +GO +DROP VIEW BABEL_3486_vu_prepare_v88 +GO + +EXEC BABEL_3486_vu_prepare_p88 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p88 +GO + +SELECT BABEL_3486_vu_prepare_f88() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f88() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v89 +GO +DROP VIEW BABEL_3486_vu_prepare_v89 +GO + +EXEC BABEL_3486_vu_prepare_p89 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p89 +GO + +SELECT BABEL_3486_vu_prepare_f89() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f89() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v90 +GO +DROP VIEW BABEL_3486_vu_prepare_v90 +GO + +EXEC BABEL_3486_vu_prepare_p90 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p90 +GO + +SELECT BABEL_3486_vu_prepare_f90() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f90() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v91 +GO +DROP VIEW BABEL_3486_vu_prepare_v91 +GO + +EXEC BABEL_3486_vu_prepare_p91 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p91 +GO + +SELECT BABEL_3486_vu_prepare_f91() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f91() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v92 +GO +DROP VIEW BABEL_3486_vu_prepare_v92 +GO + +EXEC BABEL_3486_vu_prepare_p92 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p92 +GO + +SELECT BABEL_3486_vu_prepare_f92() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f92() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v93 +GO +DROP VIEW BABEL_3486_vu_prepare_v93 +GO + +EXEC BABEL_3486_vu_prepare_p93 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p93 +GO + +SELECT BABEL_3486_vu_prepare_f93() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f93() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v94 +GO +DROP VIEW BABEL_3486_vu_prepare_v94 +GO + +EXEC BABEL_3486_vu_prepare_p94 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p94 +GO + +SELECT BABEL_3486_vu_prepare_f94() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f94() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v95 +GO +DROP VIEW BABEL_3486_vu_prepare_v95 +GO + +EXEC BABEL_3486_vu_prepare_p95 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p95 +GO + +SELECT BABEL_3486_vu_prepare_f95() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f95() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v96 +GO +DROP VIEW BABEL_3486_vu_prepare_v96 +GO + +EXEC BABEL_3486_vu_prepare_p96 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p96 +GO + +SELECT BABEL_3486_vu_prepare_f96() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f96() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v97 +GO +DROP VIEW BABEL_3486_vu_prepare_v97 +GO + +EXEC BABEL_3486_vu_prepare_p97 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p97 +GO + +SELECT BABEL_3486_vu_prepare_f97() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f97() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v98 +GO +DROP VIEW BABEL_3486_vu_prepare_v98 +GO + +EXEC BABEL_3486_vu_prepare_p98 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p98 +GO + +SELECT BABEL_3486_vu_prepare_f98() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f98() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v99 +GO +DROP VIEW BABEL_3486_vu_prepare_v99 +GO + +EXEC BABEL_3486_vu_prepare_p99 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p99 +GO + +SELECT BABEL_3486_vu_prepare_f99() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f99() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v100 +GO +DROP VIEW BABEL_3486_vu_prepare_v100 +GO + +EXEC BABEL_3486_vu_prepare_p100 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p100 +GO + +SELECT BABEL_3486_vu_prepare_f100() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f100() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v101 +GO +DROP VIEW BABEL_3486_vu_prepare_v101 +GO + +EXEC BABEL_3486_vu_prepare_p101 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p101 +GO + +SELECT BABEL_3486_vu_prepare_f101() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f101() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v102 +GO +DROP VIEW BABEL_3486_vu_prepare_v102 +GO + +EXEC BABEL_3486_vu_prepare_p102 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p102 +GO + +SELECT BABEL_3486_vu_prepare_f102() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f102() +GO + +EXEC BABEL_3486_vu_prepare_p102_2 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p102_2 +GO + +SELECT BABEL_3486_vu_prepare_f102_2() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f102_2() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v103 +GO +DROP VIEW BABEL_3486_vu_prepare_v103 +GO + +EXEC BABEL_3486_vu_prepare_p103 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p103 +GO + +SELECT BABEL_3486_vu_prepare_f103() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f103() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v104 +GO +DROP VIEW BABEL_3486_vu_prepare_v104 +GO + +EXEC BABEL_3486_vu_prepare_p104 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p104 +GO + +SELECT BABEL_3486_vu_prepare_f104() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f104() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v105 +GO +DROP VIEW BABEL_3486_vu_prepare_v105 +GO + +EXEC BABEL_3486_vu_prepare_p105 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p105 +GO + +SELECT BABEL_3486_vu_prepare_f105() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f105() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v106 +GO +DROP VIEW BABEL_3486_vu_prepare_v106 +GO + +EXEC BABEL_3486_vu_prepare_p106 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p106 +GO + +SELECT BABEL_3486_vu_prepare_f106() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f106() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v107 +GO +DROP VIEW BABEL_3486_vu_prepare_v107 +GO + +EXEC BABEL_3486_vu_prepare_p107 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p107 +GO + +SELECT BABEL_3486_vu_prepare_f107() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f107() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v108 +GO +DROP VIEW BABEL_3486_vu_prepare_v108 +GO + +EXEC BABEL_3486_vu_prepare_p108 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p108 +GO + +SELECT BABEL_3486_vu_prepare_f108() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f108() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v109 +GO +DROP VIEW BABEL_3486_vu_prepare_v109 +GO + +EXEC BABEL_3486_vu_prepare_p109 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p109 +GO + +SELECT BABEL_3486_vu_prepare_f109() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f109() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v110 +GO +DROP VIEW BABEL_3486_vu_prepare_v110 +GO + +EXEC BABEL_3486_vu_prepare_p110 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p110 +GO + +SELECT BABEL_3486_vu_prepare_f110() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f110() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v111 +GO +DROP VIEW BABEL_3486_vu_prepare_v111 +GO + +EXEC BABEL_3486_vu_prepare_p111 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p111 +GO + +SELECT BABEL_3486_vu_prepare_f111() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f111() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v113 +GO +DROP VIEW BABEL_3486_vu_prepare_v113 +GO + +EXEC BABEL_3486_vu_prepare_p113 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p113 +GO + +SELECT BABEL_3486_vu_prepare_f113() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f113() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v114 +GO +DROP VIEW BABEL_3486_vu_prepare_v114 +GO + +EXEC BABEL_3486_vu_prepare_p114 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p114 +GO + +SELECT BABEL_3486_vu_prepare_f114() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f114() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v116 +GO +DROP VIEW BABEL_3486_vu_prepare_v116 +GO + +EXEC BABEL_3486_vu_prepare_p116 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p116 +GO + +SELECT BABEL_3486_vu_prepare_f116() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f116() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v117 +GO +DROP VIEW BABEL_3486_vu_prepare_v117 +GO + +EXEC BABEL_3486_vu_prepare_p117 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p117 +GO + +SELECT BABEL_3486_vu_prepare_f117() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f117() +GO + +SELECT * FROM BABEL_3486_vu_prepare_v118 +GO +DROP VIEW BABEL_3486_vu_prepare_v118 +GO + +EXEC BABEL_3486_vu_prepare_p118 +GO +DROP PROCEDURE BABEL_3486_vu_prepare_p118 +GO + +SELECT BABEL_3486_vu_prepare_f118() +GO +DROP FUNCTION BABEL_3486_vu_prepare_f118() +GO diff --git a/test/JDBC/input/BABEL-3614-before-17_3-vu-prepare.sql b/test/JDBC/input/BABEL-3614-before-17_3-vu-prepare.sql new file mode 100644 index 0000000000..93547a6b62 --- /dev/null +++ b/test/JDBC/input/BABEL-3614-before-17_3-vu-prepare.sql @@ -0,0 +1,184 @@ +CREATE VIEW BABEL_3614_vu_prepare_v1 as (SELECT TRY_CONVERT(DATETIME2(5), '2017-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p1 as (SELECT TRY_CONVERT(DATETIME2(5), '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f1() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(5), '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v2 as (SELECT TRY_CONVERT(DATETIME2(3), '2017-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p2 as (SELECT TRY_CONVERT(DATETIME2(3), '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(3), '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v3 as (SELECT TRY_CONVERT(DATETIME2(1), '2017-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p3 as (SELECT TRY_CONVERT(DATETIME2(1), '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f3() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(1), '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v4 as (SELECT TRY_CONVERT(DATETIME2(7), '2017-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p4 as (SELECT TRY_CONVERT(DATETIME2(7), '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f4() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(7), '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE PROCEDURE BABEL_3614_vu_prepare_p5 as (SELECT TRY_CONVERT(DATETIME2(80), '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f5() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(80), '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v6 as (SELECT TRY_CONVERT(DATETIME2, '2017-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p6 as (SELECT TRY_CONVERT(DATETIME2, '2017-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f6() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, '2017-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v7 as (SELECT TRY_CONVERT(DATETIME2, CAST(5.0 AS decimal))); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p7 as (SELECT TRY_CONVERT(DATETIME2, CAST(5.0 AS decimal))); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f7() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, CAST(5.0 AS decimal))); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v8 as (SELECT TRY_CONVERT(DATETIME2, CAST('2017-08-25' AS DATE))); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p8 as (SELECT TRY_CONVERT(DATETIME2, CAST('2017-08-25' AS DATE))); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f8() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, CAST('2017-08-25' AS DATE))); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v9 as (SELECT sys.datetime2scale(CAST('2017-08-25 13:01:10.1234567' AS DATETIME2(5)), 2)); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p9 as (SELECT sys.datetime2scale(CAST('2017-08-25 13:01:10.1234567' AS DATETIME2(5)), 2)); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f9() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT sys.datetime2scale(CAST('2017-08-25 13:01:10.1234567' AS DATETIME2(5)), 2)); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v10 as (SELECT TRY_CONVERT(datetime2(7), '9999-12-31 23:59:59.9999999')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p10 as (SELECT TRY_CONVERT(DATETIME2(7), '9999-12-31 23:59:59.9999999')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f10() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(7), '9999-12-31 23:59:59.9999999')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v11 as (SELECT TRY_CONVERT(DATETIME2, '0001-01-01')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p11 as (SELECT TRY_CONVERT(DATETIME2, '0001-01-01')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f11() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, '0001-01-01')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v12 as (SELECT TRY_CONVERT(DATETIME2, '1600-08-25 13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p12 as (SELECT TRY_CONVERT(DATETIME2, '1600-08-25 13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f12() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, '1600-08-25 13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v13 as (SELECT TRY_CONVERT(DATETIME2, '13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p13 as (SELECT TRY_CONVERT(DATETIME2, '13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f13() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2, '13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v14 as (SELECT TRY_CONVERT(DATETIME2(2), '13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p14 as (SELECT TRY_CONVERT(DATETIME2(2), '13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f14() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(2), '13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v15 as (SELECT TRY_CONVERT(DATETIME2(0), '13:01:10.1234567')); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p15 as (SELECT TRY_CONVERT(DATETIME2(0), '13:01:10.1234567')); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f15() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT TRY_CONVERT(DATETIME2(0), '13:01:10.1234567')); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v16 as (SELECT babelfish_try_cast_to_datetime2(CAST ('1900-01-01' as xml), CAST(2 as INTEGER))); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p16 as (SELECT babelfish_try_cast_to_datetime2(CAST ('1900-01-01' as xml), CAST(2 as INTEGER))); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f16() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT babelfish_try_cast_to_datetime2(CAST ('1900-01-01' as xml), CAST(2 as INTEGER))); +END +GO + +CREATE VIEW BABEL_3614_vu_prepare_v17 as (SELECT babelfish_try_cast_to_datetime2('1900-01-01', CAST(2 as INTEGER))); +GO +CREATE PROCEDURE BABEL_3614_vu_prepare_p17 as (SELECT babelfish_try_cast_to_datetime2('1900-01-01', CAST(2 as INTEGER))); +GO +CREATE FUNCTION BABEL_3614_vu_prepare_f17() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT babelfish_try_cast_to_datetime2('1900-01-01', CAST(2 as INTEGER))); +END +GO diff --git a/test/JDBC/input/BABEL-3614-before-17_3-vu-verify.sql b/test/JDBC/input/BABEL-3614-before-17_3-vu-verify.sql new file mode 100644 index 0000000000..c944f7a650 --- /dev/null +++ b/test/JDBC/input/BABEL-3614-before-17_3-vu-verify.sql @@ -0,0 +1,249 @@ +SELECT * FROM BABEL_3614_vu_prepare_v1 +GO +DROP VIEW BABEL_3614_vu_prepare_v1 +GO + +EXEC BABEL_3614_vu_prepare_p1 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p1 +GO + +SELECT BABEL_3614_vu_prepare_f1() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f1() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v2 +GO +DROP VIEW BABEL_3614_vu_prepare_v2 +GO + +EXEC BABEL_3614_vu_prepare_p2 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p2 +GO + +SELECT BABEL_3614_vu_prepare_f2() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f2() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v3 +GO +DROP VIEW BABEL_3614_vu_prepare_v3 +GO + +EXEC BABEL_3614_vu_prepare_p3 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p3 +GO + +SELECT BABEL_3614_vu_prepare_f3() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f3() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v4 +GO +DROP VIEW BABEL_3614_vu_prepare_v4 +GO + +EXEC BABEL_3614_vu_prepare_p4 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p4 +GO + +SELECT BABEL_3614_vu_prepare_f4() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f4() +GO + +EXEC BABEL_3614_vu_prepare_p5 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p5 +GO + +SELECT BABEL_3614_vu_prepare_f5() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f5() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v6 +GO +DROP VIEW BABEL_3614_vu_prepare_v6 +GO + +EXEC BABEL_3614_vu_prepare_p6 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p6 +GO + +SELECT BABEL_3614_vu_prepare_f6() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f6() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v7 +GO +DROP VIEW BABEL_3614_vu_prepare_v7 +GO + +EXEC BABEL_3614_vu_prepare_p7 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p7 +GO + +SELECT BABEL_3614_vu_prepare_f7() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f7() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v8 +GO +DROP VIEW BABEL_3614_vu_prepare_v8 +GO + +EXEC BABEL_3614_vu_prepare_p8 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p8 +GO + +SELECT BABEL_3614_vu_prepare_f8() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f8() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v9 +GO +DROP VIEW BABEL_3614_vu_prepare_v9 +GO + +EXEC BABEL_3614_vu_prepare_p9 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p9 +GO + +SELECT BABEL_3614_vu_prepare_f9() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f9() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v10 +GO +DROP VIEW BABEL_3614_vu_prepare_v10 +GO + +EXEC BABEL_3614_vu_prepare_p10 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p10 +GO + +SELECT BABEL_3614_vu_prepare_f10() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f10() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v11 +GO +DROP VIEW BABEL_3614_vu_prepare_v11 +GO + +EXEC BABEL_3614_vu_prepare_p11 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p11 +GO + +SELECT BABEL_3614_vu_prepare_f11() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f11() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v12 +GO +DROP VIEW BABEL_3614_vu_prepare_v12 +GO + +EXEC BABEL_3614_vu_prepare_p12 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p12 +GO + +SELECT BABEL_3614_vu_prepare_f12() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f12() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v13 +GO +DROP VIEW BABEL_3614_vu_prepare_v13 +GO + +EXEC BABEL_3614_vu_prepare_p13 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p13 +GO + +SELECT BABEL_3614_vu_prepare_f13() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f13() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v14 +GO +DROP VIEW BABEL_3614_vu_prepare_v14 +GO + +EXEC BABEL_3614_vu_prepare_p14 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p14 +GO + +SELECT BABEL_3614_vu_prepare_f14() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f14() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v15 +GO +DROP VIEW BABEL_3614_vu_prepare_v15 +GO + +EXEC BABEL_3614_vu_prepare_p15 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p15 +GO + +SELECT BABEL_3614_vu_prepare_f15() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f15() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v16 +GO +DROP VIEW BABEL_3614_vu_prepare_v16 +GO + +EXEC BABEL_3614_vu_prepare_p16 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p16 +GO + +SELECT BABEL_3614_vu_prepare_f16() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f16() +GO + +SELECT * FROM BABEL_3614_vu_prepare_v17 +GO +DROP VIEW BABEL_3614_vu_prepare_v17 +GO + +EXEC BABEL_3614_vu_prepare_p17 +GO +DROP PROCEDURE BABEL_3614_vu_prepare_p17 +GO + +SELECT BABEL_3614_vu_prepare_f17() +GO +DROP FUNCTION BABEL_3614_vu_prepare_f17() +GO \ No newline at end of file diff --git a/test/JDBC/input/BABEL-5031-vu-verify.sql b/test/JDBC/input/BABEL-5031-vu-verify.sql new file mode 100644 index 0000000000..8a5678087c --- /dev/null +++ b/test/JDBC/input/BABEL-5031-vu-verify.sql @@ -0,0 +1,72 @@ +-- Customer case +CREATE TABLE [dbo].[babel_5031_MemberValues]( + [Id] [uniqueidentifier] NOT NULL, + [PanelId] [uniqueidentifier] NOT NULL, + [EndEffectiveDate] [datetime2](7) NOT NULL +); +GO + +CREATE NONCLUSTERED INDEX [babel_5031_IDX_MBRVAL_SHARED_LATEST_FILT] ON [dbo].[babel_5031_MemberValues] ([PanelId] ASC) +WHERE ([EndEffectiveDate]=CONVERT([datetime2](7),'9999-12-31 23:59:59.9999999')); +GO + +DROP TABLE babel_5031_MemberValues +GO + +-- Using convert function for converting from string to date/datetime/datetime2/datetimeoffset/smalldatetime/time +-- in computed column of table +CREATE TABLE babel_5031_t1(col_string VARCHAR(100), + col_date AS CONVERT(date, col_string), + col_datetime AS CONVERT(datetime, col_string), + col_datetime2 AS CONVERT(datetime2, col_string), + col_dateoffset AS CONVERT(datetimeoffset, col_string), + col_smalldatetime AS CONVERT(smalldatetime, col_string), + col_time AS CONVERT(time, col_string)); +GO + +INSERT INTO babel_5031_t1 VALUES('2026-12-31 23:59:59.99'); +GO + +INSERT INTO babel_5031_t1 VALUES('11.12.2024'); +GO + +INSERT INTO babel_5031_t1 VALUES('2022-10-30T03:00:00.123'); +GO + +INSERT INTO babel_5031_t1 VALUES('20240129 03:00:00'); +GO + +SELECT * FROM babel_5031_t1 +GO + +DROP TABLE babel_5031_t1 +GO + +-- Using convert function for converting from string to date/datetime/datetime2/datetimeoffset/smalldatetime/time +-- in check constraint of table +CREATE TABLE babel_5031_t2(col_string VARCHAR(100), + CHECK (CONVERT(date, col_string) > CONVERT(date, '03-05-2023')), + CHECK (CONVERT(datetime, col_string) > CONVERT(datetime, '03-05-2023')), + CHECK (CONVERT(datetime2, col_string) > CONVERT(datetime2, '03-05-2023')), + CHECK (CONVERT(datetimeoffset, col_string) > CONVERT(datetimeoffset, '03-05-2023')), + CHECK (CONVERT(smalldatetime, col_string) > CONVERT(smalldatetime, '03-05-2023')), + CHECK (CONVERT(time, col_string) > CONVERT(time, '03-05-2023'))); +GO + +INSERT INTO babel_5031_t2 VALUES('2026-12-31 23:59:59.99'); +GO + +INSERT INTO babel_5031_t2 VALUES('11.12.2024'); +GO + +INSERT INTO babel_5031_t2 VALUES('2022-10-30T03:00:00.123'); +GO + +INSERT INTO babel_5031_t2 VALUES('20240129 03:00:00'); +GO + +SELECT * FROM babel_5031_t2 +GO + +DROP TABLE babel_5031_t2 +GO \ No newline at end of file diff --git a/test/JDBC/input/datatypes/TestDatetime-numeric-dateaddfunction-before-17_3-vu-prepare.sql b/test/JDBC/input/datatypes/TestDatetime-numeric-dateaddfunction-before-17_3-vu-prepare.sql new file mode 100644 index 0000000000..477cbfe71c --- /dev/null +++ b/test/JDBC/input/datatypes/TestDatetime-numeric-dateaddfunction-before-17_3-vu-prepare.sql @@ -0,0 +1,406 @@ +CREATE VIEW Datetime_view3 +AS( + SELECT + CONVERT(DATETIME, CAST(2.5 as BIT)) as re1, + CONVERT(DATETIME, CAST(2.5 as DECIMAL))as re2, + CONVERT(DATETIME, CAST(2.5 as NUMERIC(30,8)))as re3, + CONVERT(DATETIME, CAST(2.5 as FLOAT))as re4, + CONVERT(DATETIME, CAST(2.5 as REAL))as re5, + CONVERT(DATETIME, CAST(2.5 as INT))as re6, + CONVERT(DATETIME, CAST(2.5 as BIGINT))as re7, + CONVERT(DATETIME, CAST(2.5 as SMALLINT))as re8, + CONVERT(DATETIME, CAST(2.5 as TINYINT))as re9, + CONVERT(DATETIME, CAST(2.5 as MONEY))as re10, + CONVERT(DATETIME, CAST(2.5 as SMALLMONEY))as re11, + CONVERT(DATETIME, CAST(-2.5 as BIT)) as re12, + CONVERT(DATETIME, CAST(-2.5 as DECIMAL))as re13, + CONVERT(DATETIME, CAST(-2.5 as NUMERIC(30,8)))as re14, + CONVERT(DATETIME, CAST(-2.5 as FLOAT))as re15, + CONVERT(DATETIME, CAST(-2.5 as REAL))as re16, + CONVERT(DATETIME, CAST(-2.5 as INT))as re17, + CONVERT(DATETIME, CAST(-2.5 as BIGINT))as re18, + CONVERT(DATETIME, CAST(-2.5 as SMALLINT))as re19, + CONVERT(DATETIME, CAST(-2.5 as MONEY))as re20, + CONVERT(DATETIME, CAST(-2.5 as SMALLMONEY))as re21, + CONVERT(DATETIME, NULL)as res22 +); +GO + +CREATE VIEW Datetime_view4 +AS( + SELECT + CONVERT(SMALLDATETIME, CAST(2.5 as BIT)) as re1, + CONVERT(SMALLDATETIME, CAST(2.5 as DECIMAL)) as re2, + CONVERT(SMALLDATETIME, CAST(2.5 as NUMERIC(30,8))) as re3, + CONVERT(SMALLDATETIME, CAST(2.5 as FLOAT)) as re4, + CONVERT(SMALLDATETIME, CAST(2.5 as REAL)) as re5, + CONVERT(SMALLDATETIME, CAST(2.5 as INT)) as re6, + CONVERT(SMALLDATETIME, CAST(2.5 as BIGINT)) as re7, + CONVERT(SMALLDATETIME, CAST(2.5 as SMALLINT)) as re8, + CONVERT(SMALLDATETIME, CAST(2.5 as TINYINT)) as re9, + CONVERT(SMALLDATETIME, CAST(2.5 as MONEY)) as re10, + CONVERT(SMALLDATETIME, CAST(2.5 as SMALLMONEY)) as re11, + CONVERT(SMALLDATETIME, CAST(-2.5 as BIT)) as re12, + CONVERT(SMALLDATETIME, NULL) as res13 +); +GO + +-- Should all fail +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as DECIMAL)) +GO +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as NUMERIC(30,8))) +GO +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as FLOAT)) +GO +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as REAL)) +GO +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as INT)) +GO +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as BIGINT)) +GO +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as SMALLINT)) +GO +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as MONEY)) +GO +SELECT CONVERT(SMALLDATETIME, CAST(-2.5 as SMALLMONEY)) +GO + +-- Should all fail +SELECT CONVERT(DATETIME2, CAST(-2.5 as DECIMAL)) +GO +SELECT CONVERT(DATETIME2, CAST(-2.5 as NUMERIC(30,8))) +GO +SELECT CONVERT(DATETIME2, CAST(-2.5 as FLOAT)) +GO +SELECT CONVERT(DATETIME2, CAST(-2.5 as REAL)) +GO +SELECT CONVERT(DATETIME2, CAST(-2.5 as INT)) +GO +SELECT CONVERT(DATETIME2, CAST(-2.5 as BIGINT)) +GO +SELECT CONVERT(DATETIME2, CAST(-2.5 as SMALLINT)) +GO +SELECT CONVERT(DATETIME2, CAST(-2.5 as MONEY)) +GO +SELECT CONVERT(DATETIME2, CAST(-2.5 as SMALLMONEY)) +GO + +-- Should all fail +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as DECIMAL)) +GO +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as NUMERIC(30,8))) +GO +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as FLOAT)) +GO +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as REAL)) +GO +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as INT)) +GO +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as BIGINT)) +GO +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as SMALLINT)) +GO +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as MONEY)) +GO +SELECT CONVERT(DATETIMEOFFSET, CAST(-2.5 as SMALLMONEY)) +GO + +-- Should all fail +SELECT CONVERT(DATE, CAST(-2.5 as DECIMAL)) +GO +SELECT CONVERT(DATE, CAST(-2.5 as NUMERIC(30,8))) +GO +SELECT CONVERT(DATE, CAST(-2.5 as FLOAT)) +GO +SELECT CONVERT(DATE, CAST(-2.5 as REAL)) +GO +SELECT CONVERT(DATE, CAST(-2.5 as INT)) +GO +SELECT CONVERT(DATE, CAST(-2.5 as BIGINT)) +GO +SELECT CONVERT(DATE, CAST(-2.5 as SMALLINT)) +GO +SELECT CONVERT(DATE, CAST(-2.5 as MONEY)) +GO +SELECT CONVERT(DATE, CAST(-2.5 as SMALLMONEY)) +GO + +-- Should all fail +SELECT CONVERT(TIME, CAST(-2.5 as DECIMAL)) +GO +SELECT CONVERT(TIME, CAST(-2.5 as NUMERIC(30,8))) +GO +SELECT CONVERT(TIME, CAST(-2.5 as FLOAT)) +GO +SELECT CONVERT(TIME, CAST(-2.5 as REAL)) +GO +SELECT CONVERT(TIME, CAST(-2.5 as INT)) +GO +SELECT CONVERT(TIME, CAST(-2.5 as BIGINT)) +GO +SELECT CONVERT(TIME, CAST(-2.5 as SMALLINT)) +GO +SELECT CONVERT(TIME, CAST(-2.5 as MONEY)) +GO +SELECT CONVERT(TIME, CAST(-2.5 as SMALLMONEY)) +GO + +CREATE VIEW Datetime_view5 as ( + SELECT + DATEADD(minute, 1, CAST(2.5 as DECIMAL)) as re1, + DATEADD(minute, 1, CAST(2.5 as NUMERIC(30,8))) as re2, + DATEADD(minute, 1, CAST(2.5 as FLOAT)) as re3, + DATEADD(minute, 1, CAST(2.5 as REAL)) as re4, + DATEADD(minute, 1, CAST(2.5 as INT)) as re5, + DATEADD(minute, 1, CAST(2.5 as BIGINT)) as re6, + DATEADD(minute, 1, CAST(2.5 as SMALLINT)) as re7, + DATEADD(minute, 1, CAST(2.5 as TINYINT)) as re8, + DATEADD(minute, 1, CAST(2.5 as MONEY)) as re9, + DATEADD(minute, 1, CAST(2.5 as SMALLMONEY)) as re10, + DATEADD(minute, 1, CAST(-2.5 as BIT)) as re11, + DATEADD(minute, 1, CAST(-2.5 as DECIMAL)) as re12, + DATEADD(minute, 1, CAST(-2.5 as NUMERIC(30,8))) as re13, + DATEADD(minute, 1, CAST(-2.5 as FLOAT)) as re14, + DATEADD(minute, 1, CAST(-2.5 as REAL)) as re15, + DATEADD(minute, 1, CAST(-2.5 as INT)) as re16, + DATEADD(minute, 1, CAST(-2.5 as BIGINT)) as re17, + DATEADD(minute, 1, CAST(-2.5 as SMALLINT)) as re18, + DATEADD(minute, 1, CAST(-2.5 as MONEY)) as re19, + DATEADD(minute, 1, CAST(-2.5 as SMALLMONEY)) as re20, + DATEADD(minute, 1, CAST(-2.5 as BIT)) as re21 +); +GO + +CREATE VIEW Datetime_view7 as ( + SELECT + DATENAME(day, CAST(2.5 as DECIMAL)) as re1, + DATENAME(day, CAST(2.5 as NUMERIC(30,8))) as re2, + DATENAME(day, CAST(2.5 as FLOAT)) as re3, + DATENAME(day, CAST(2.5 as REAL)) as re4, + DATENAME(day, CAST(2.5 as INT)) as re5, + DATENAME(day, CAST(2.5 as BIGINT)) as re6, + DATENAME(day, CAST(2.5 as SMALLINT)) as re7, + DATENAME(day, CAST(2.5 as TINYINT)) as re8, + DATENAME(day, CAST(2.5 as MONEY)) as re9, + DATENAME(day, CAST(2.5 as SMALLMONEY)) as re10, + DATENAME(day, CAST(2.5 as BIT)) as re11, + DATENAME(day, CAST(-2.5 as DECIMAL)) as re12, + DATENAME(day, CAST(-2.5 as NUMERIC(30,8))) as re13, + DATENAME(day, CAST(-2.5 as FLOAT)) as re14, + DATENAME(day, CAST(-2.5 as REAL)) as re15, + DATENAME(day, CAST(-2.5 as INT)) as re16, + DATENAME(day, CAST(-2.5 as BIGINT)) as re17, + DATENAME(day, CAST(-2.5 as SMALLINT)) as re18, + DATENAME(day, CAST(-2.5 as MONEY)) as re19, + DATENAME(day, CAST(-2.5 as SMALLMONEY)) as re20, + DATENAME(day, CAST(-2.5 as BIT)) as re21 +); +GO + +CREATE VIEW Datetime_view8 as ( + SELECT + DATEPART(day, CAST(2.5 as DECIMAL)) as re1, + DATEPART(day, CAST(2.5 as NUMERIC(30,8))) as re2, + DATEPART(day, CAST(2.5 as FLOAT)) as re3, + DATEPART(day, CAST(2.5 as REAL)) as re4, + DATEPART(day, CAST(2.5 as INT)) as re5, + DATEPART(day, CAST(2.5 as BIGINT)) as re6, + DATEPART(day, CAST(2.5 as SMALLINT)) as re7, + DATEPART(day, CAST(2.5 as TINYINT)) as re8, + DATEPART(day, CAST(2.5 as MONEY)) as re9, + DATEPART(day, CAST(2.5 as SMALLMONEY)) as re10, + DATEPART(day, CAST(2.5 as BIT)) as re11, + DATEPART(day, CAST(-2.5 as DECIMAL)) as re12, + DATEPART(day, CAST(-2.5 as NUMERIC(30,8))) as re13, + DATEPART(day, CAST(-2.5 as FLOAT)) as re14, + DATEPART(day, CAST(-2.5 as REAL)) as re15, + DATEPART(day, CAST(-2.5 as INT)) as re16, + DATEPART(day, CAST(-2.5 as BIGINT)) as re17, + DATEPART(day, CAST(-2.5 as SMALLINT)) as re18, + DATEPART(day, CAST(-2.5 as MONEY)) as re19, + DATEPART(day, CAST(-2.5 as SMALLMONEY)) as re20, + DATEPART(day, CAST(-2.5 as BIT)) as re21 +); +GO + +CREATE PROCEDURE Datetime_proc1 (@a DATETIME, @b BIT) AS +BEGIN + DECLARE @c DATETIME = @b; + SELECT (CASE WHEN @a = @c THEN 'pass' ELSE 'fail' END) as result; +END +GO + +CREATE PROCEDURE SMALLDatetime_proc1 (@a SMALLDATETIME, @b BIT) AS +BEGIN + DECLARE @c SMALLDATETIME = @b; + SELECT (CASE WHEN @a = @c THEN 'pass' ELSE 'fail' END) as result; +END +GO + +CREATE VIEW dateadd_numeric_representation_helper_year_view AS +SELECT +dateadd_numeric_representation_helper('year',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('year',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('year',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('year',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('year',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('year',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('year',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('year',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('year',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_quarter_view AS +SELECT +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('quarter',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_month_view AS +SELECT +dateadd_numeric_representation_helper('month',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('month',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('month',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('month',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('month',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('month',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('month',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('month',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('month',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_dayofyear_view AS +SELECT +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('dayofyear',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_day_view AS +SELECT +dateadd_numeric_representation_helper('day',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('day',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('day',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('day',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('day',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('day',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('day',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('day',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('day',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_week_view AS +SELECT +dateadd_numeric_representation_helper('week',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('week',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('week',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('week',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('week',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('week',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('week',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('week',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('week',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_weekday_view AS +SELECT +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('weekday',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_hour_view AS +SELECT +dateadd_numeric_representation_helper('hour',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('hour',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_minute_view AS +SELECT +dateadd_numeric_representation_helper('minute',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('minute',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_second_view AS +SELECT +dateadd_numeric_representation_helper('second',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('second',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('second',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('second',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('second',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('second',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('second',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('second',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('second',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + +CREATE VIEW dateadd_numeric_representation_helper_millisecond_view AS +SELECT +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as BIGINT)) AS BIT_INT, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as INT)) AS REG_INT, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as SMALLINT)) AS SMALL_INT, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as TINYINT)) AS TINY_INT, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as NUMERIC)) AS NUMERIC_REP, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as FLOAT)) AS FLOAT_REP, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as REAL)) AS REAL_REP, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as MONEY)) AS MONEY_REP, +dateadd_numeric_representation_helper('millisecond',1,cast(1.5 as SMALLMONEY)) AS SMALLMONEY_REP +GO + + +CREATE VIEW dateadd_view_1 AS +SELECT * FROM sys.dateadd('year',1,cast(1.5 as REAL)) +GO + +CREATE VIEW dateadd_view_2 AS +SELECT * FROM sys.dateadd('year',1,cast(1.5 as NUMERIC(30,8))) +GO + +CREATE VIEW dateadd_view_3 AS +SELECT * FROM sys.dateadd('year',1,cast(1.5 as DECIMAL)) +GO + +CREATE VIEW dateadd_view_4 AS +SELECT * FROM sys.dateadd('year',1,cast(1 as BIT)) +GO + +CREATE VIEW dateadd_view_5 AS +SELECT * FROM sys.dateadd('year',1,cast(1.5 as FLOAT)) +GO + +CREATE VIEW dateadd_view_6 AS +SELECT * FROM sys.dateadd('year',1,cast(1.5 as FLOAT)) +GO diff --git a/test/JDBC/input/datatypes/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.sql b/test/JDBC/input/datatypes/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.sql new file mode 100644 index 0000000000..b5e047af3e --- /dev/null +++ b/test/JDBC/input/datatypes/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.sql @@ -0,0 +1,159 @@ +-- output from SQL Server : +-- 1900-01-02 00:00:00.000 1900-01-04 00:00:00.000 1900-01-03 12:00:00.000 1900-01-03 12:00:00.000 1900-01-03 12:00:00.000 1900-01-03 00:00:00.000 1900-01-03 00:00:00.000 1900-01-03 00:00:00.000 1900-01-03 00:00:00.000 1900-01-03 12:00:00.000 1900-01-03 12:00:00.000 1900-01-02 00:00:00.000 1899-12-29 00:00:00.000 1899-12-29 12:00:00.000 1899-12-29 12:00:00.000 1899-12-29 12:00:00.000 1899-12-30 00:00:00.000 1899-12-30 00:00:00.000 1899-12-30 00:00:00.000 1899-12-29 12:00:00.000 1899-12-29 12:00:00.000 null +SELECT * FROM Datetime_view3 +GO +DROP VIEW Datetime_view3 +GO + +-- output from SQL Server : +-- 1900-01-02 00:00 1900-01-04 00:00 1900-01-03 12:00 1900-01-03 12:00 1900-01-03 12:00 1900-01-03 00:00 1900-01-03 00:00 1900-01-03 00:00 1900-01-03 00:00 1900-01-03 12:00 1900-01-03 12:00 1900-01-02 00:00 null +SELECT * FROM Datetime_view4 +GO +DROP VIEW Datetime_view4 +GO + +-- output from SQL Server : +-- 1900-01-04 00:01:00.000 1900-01-03 12:01:00.000 1900-01-03 12:01:00.000 1900-01-03 12:01:00.000 1900-01-03 00:01:00.000 1900-01-03 00:01:00.000 1900-01-03 00:01:00.000 1900-01-03 00:01:00.000 1900-01-03 12:01:00.000 1900-01-03 12:01:00.000 1899-12-28 23:59:00.000 1899-12-29 11:59:00.000 1899-12-29 11:59:00.000 1899-12-29 11:59:00.000 1899-12-29 23:59:00.000 1899-12-29 23:59:00.000 1899-12-29 23:59:00.000 1899-12-29 11:59:00.000 1899-12-29 11:59:00.000 +SELECT * FROM Datetime_view5 +GO +DROP VIEW Datetime_view5 +GO + +-- output from SQL Server : +-- 4 3 3 3 3 3 3 3 3 3 2 29 29 29 29 30 30 30 29 29 2 +SELECT * FROM Datetime_view7 +GO +DROP VIEW Datetime_view7 +GO + +-- output from SQL Server : +-- 4 3 3 3 3 3 3 3 3 3 2 29 29 29 29 30 30 30 29 29 2 +SELECT * FROM Datetime_view8 +GO +DROP VIEW Datetime_view8 +GO + +-- Procedures +EXEC Datetime_proc1 '1900-01-02 00:00:00', 3.1 +GO +EXEC Datetime_proc1 '1900-01-02 00:00:00', 2 +GO +EXEC Datetime_proc1 '1900-01-01 00:00:00', 0 +GO +EXEC Datetime_proc1 '1900-01-02 00:00:00', -3.1 +GO +DROP PROCEDURE Datetime_proc1 +GO + +EXEC SMALLDatetime_proc1 '1900-01-02 00:00:00', 3.1 +GO +EXEC SMALLDatetime_proc1 '1900-01-02 00:00:00', 2 +GO +EXEC SMALLDatetime_proc1 '1900-01-01 00:00:00', 0 +GO +EXEC SMALLDatetime_proc1 '1900-01-02 00:00:00', -3.1 +GO +DROP PROCEDURE SMALLDatetime_proc1 +GO + +SELECT * FROM dateadd_numeric_representation_helper_year_view +GO + +DROP VIEW dateadd_numeric_representation_helper_year_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_quarter_view +GO + +DROP VIEW dateadd_numeric_representation_helper_quarter_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_month_view +GO + +DROP VIEW dateadd_numeric_representation_helper_month_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_dayofyear_view +GO + +DROP VIEW dateadd_numeric_representation_helper_dayofyear_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_day_view +GO + +DROP VIEW dateadd_numeric_representation_helper_day_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_week_view +GO + +DROP VIEW dateadd_numeric_representation_helper_week_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_weekday_view +GO + +DROP VIEW dateadd_numeric_representation_helper_weekday_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_hour_view +GO + +DROP VIEW dateadd_numeric_representation_helper_hour_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_minute_view +GO + +DROP VIEW dateadd_numeric_representation_helper_minute_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_second_view +GO + +DROP VIEW dateadd_numeric_representation_helper_second_view +GO + +SELECT * FROM dateadd_numeric_representation_helper_millisecond_view +GO + +DROP VIEW dateadd_numeric_representation_helper_millisecond_view +GO + +SELECT * FROM dateadd_view_1 +GO + +DROP VIEW dateadd_view_1 +GO + +SELECT * FROM dateadd_view_2 +GO + +DROP VIEW dateadd_view_2 +GO + +SELECT * FROM dateadd_view_3 +GO + +DROP VIEW dateadd_view_3 +GO + +SELECT * FROM dateadd_view_4 +GO + +DROP VIEW dateadd_view_4 +GO + +SELECT * FROM dateadd_view_5 +GO + +DROP VIEW dateadd_view_5 +GO + +SELECT * FROM dateadd_view_6 +GO + +DROP VIEW dateadd_view_6 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-cleanup.sql new file mode 100644 index 0000000000..c6ca5aedf4 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-cleanup.sql @@ -0,0 +1,71 @@ +DROP VIEW test_conv_string_to_date_v1 +GO +DROP PROCEDURE test_conv_string_to_date_p1 +GO +DROP FUNCTION test_conv_string_to_date_f1() +GO + +DROP VIEW test_conv_string_to_date_v2 +GO +DROP PROCEDURE test_conv_string_to_date_p2 +GO +DROP FUNCTION test_conv_string_to_date_f2() +GO + +DROP VIEW test_conv_string_to_date_v3 +GO +DROP PROCEDURE test_conv_string_to_date_p3 +GO +DROP FUNCTION test_conv_string_to_date_f3() +GO + +DROP VIEW test_conv_string_to_date_v4 +GO +DROP PROCEDURE test_conv_string_to_date_p4 +GO +DROP FUNCTION test_conv_string_to_date_f4() +GO + +DROP VIEW test_conv_string_to_date_v5 +GO +DROP PROCEDURE test_conv_string_to_date_p5 +GO +DROP FUNCTION test_conv_string_to_date_f5() +GO + +DROP VIEW test_conv_string_to_date_v6 +GO +DROP PROCEDURE test_conv_string_to_date_p6 +GO +DROP FUNCTION test_conv_string_to_date_f6() +GO + +DROP VIEW test_conv_string_to_date_v7 +GO +DROP PROCEDURE test_conv_string_to_date_p7 +GO +DROP FUNCTION test_conv_string_to_date_f7() +GO + +DROP VIEW test_conv_string_to_date_v8 +GO +DROP PROCEDURE test_conv_string_to_date_p8 +GO +DROP FUNCTION test_conv_string_to_date_f8() +GO + +DROP VIEW test_conv_string_to_date_v9 +GO +DROP PROCEDURE test_conv_string_to_date_p9 +GO +DROP FUNCTION test_conv_string_to_date_f9() +GO + +DROP VIEW test_conv_string_to_date_v10 +GO + +DROP VIEW test_conv_string_to_date_v11 +GO + +DROP VIEW test_conv_string_to_date_v12 +GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-prepare.sql new file mode 100644 index 0000000000..7791067ede --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-prepare.sql @@ -0,0 +1,107 @@ +CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f1() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '2017-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f2() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '9999-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_date_f3() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE FUNCTION test_conv_string_to_date_f4() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f5() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f6() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f7() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_date_f8() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f9() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +GO + +CREATE VIEW test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); +GO + +CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-verify.sql new file mode 100644 index 0000000000..c937660ad3 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-verify.sql @@ -0,0 +1,1481 @@ +-- Only DATE string +-- Empty string, should return default values +SELECT CONVERT(DATE, '') +GO + +SELECT CONVERT(DATE, '', 130) +GO + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATE, '3-2-4') +GO + +SELECT CONVERT(DATE, '3-12-4') +GO + +SELECT CONVERT(DATE, '3-12-24') +GO + +SELECT CONVERT(DATE, '3-12-2024') +GO + +SELECT CONVERT(DATE, '11-12-2024') +GO + +SELECT CONVERT(DATE, '3 - 12 - 2024') +GO + +SELECT CONVERT(DATE, '3.2.4') +GO + +SELECT CONVERT(DATE, '3.12.4') +GO + +SELECT CONVERT(DATE, '3.12.24') +GO + +SELECT CONVERT(DATE, '3.12.2024') +GO + +SELECT CONVERT(DATE, '11.12.2024') +GO + +SELECT CONVERT(DATE, '3 . 12 . 2024') +GO + +SELECT CONVERT(DATE, '3/2/4') +GO + +SELECT CONVERT(DATE, '3/12/4') +GO + +SELECT CONVERT(DATE, '3/12/24') +GO + +SELECT CONVERT(DATE, '3/12/2024') +GO + +SELECT CONVERT(DATE, '11/12/2024') +GO + +SELECT CONVERT(DATE, '3 / 12 / 2024') +GO + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATE, '3-4-2') +GO + +SELECT CONVERT(DATE, '3-4-12') +GO + +SELECT CONVERT(DATE, '3-24-12') +GO + +SELECT CONVERT(DATE, '3-2024-12') +GO + +SELECT CONVERT(DATE, '11-2024-12') +GO + +SELECT CONVERT(DATE, '3 - 2024 - 12') +GO + +SELECT CONVERT(DATE, '3.4.2') +GO + +SELECT CONVERT(DATE, '3.4.12') +GO + +SELECT CONVERT(DATE, '3.24.12') +GO + +SELECT CONVERT(DATE, '3.2024.12') +GO + +SELECT CONVERT(DATE, '11.2024.12') +GO + +SELECT CONVERT(DATE, '3 . 2024 . 12') +GO + +SELECT CONVERT(DATE, '3/4/2') +GO + +SELECT CONVERT(DATE, '3/4/12') +GO + +SELECT CONVERT(DATE, '3/24/12') +GO + +SELECT CONVERT(DATE, '3/2024/12') +GO + +SELECT CONVERT(DATE, '11/2024/12') +GO + +SELECT CONVERT(DATE, '3 / 2024 / 12') +GO + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '12-3-4') +GO + +SELECT CONVERT(DATE, '12-3-24') +GO + +SELECT CONVERT(DATE, '12-3-2024') +GO + +SELECT CONVERT(DATE, '12-11-2024') +GO + +SELECT CONVERT(DATE, '12 - 3 - 2024') +GO + +SELECT CONVERT(DATE, '2.3.4') +GO + +SELECT CONVERT(DATE, '12.3.4') +GO + +SELECT CONVERT(DATE, '12.3.24') +GO + +SELECT CONVERT(DATE, '12.3.2024') +GO + +SELECT CONVERT(DATE, '12.11.2024') +GO + +SELECT CONVERT(DATE, '12 . 3 . 2024') +GO + +SELECT CONVERT(DATE, '2/3/4') +GO + +SELECT CONVERT(DATE, '12/3/4') +GO + +SELECT CONVERT(DATE, '12/3/24') +GO + +SELECT CONVERT(DATE, '12/3/2024') +GO + +SELECT CONVERT(DATE, '12/11/2024') +GO + +SELECT CONVERT(DATE, '12 / 3 / 2024') +GO + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATE, '2-4-3') +GO + +SELECT CONVERT(DATE, '12-4-3') +GO + +SELECT CONVERT(DATE, '12-24-3') +GO + +SELECT CONVERT(DATE, '12-2024-3') +GO + +SELECT CONVERT(DATE, '12-2024-11') +GO + +SELECT CONVERT(DATE, '12 - 2024 - 3') +GO + +SELECT CONVERT(DATE, '2.4.3') +GO + +SELECT CONVERT(DATE, '12.4.3') +GO + +SELECT CONVERT(DATE, '12.24.3') +GO + +SELECT CONVERT(DATE, '12.2024.3') +GO + +SELECT CONVERT(DATE, '12.2024.11') +GO + +SELECT CONVERT(DATE, '12 . 2024 . 3') +GO + +SELECT CONVERT(DATE, '2/4/3') +GO + +SELECT CONVERT(DATE, '12/4/3') +GO + +SELECT CONVERT(DATE, '12/24/3') +GO + +SELECT CONVERT(DATE, '12/2024/3') +GO + +SELECT CONVERT(DATE, '12/2024/11') +GO + +SELECT CONVERT(DATE, '12 / 2024 / 3') +GO + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATE, '4-3-2') +GO + +SELECT CONVERT(DATE, '4-3-12') +GO + +SELECT CONVERT(DATE, '24-3-12') +GO + +SELECT CONVERT(DATE, '2024-3-12') +GO + +SELECT CONVERT(DATE, '2024-11-12') +GO + +SELECT CONVERT(DATE, '2024 - 3 - 12') +GO + +SELECT CONVERT(DATE, '4.3.2') +GO + +SELECT CONVERT(DATE, '4.3.12') +GO + +SELECT CONVERT(DATE, '24.3.12') +GO + +SELECT CONVERT(DATE, '2024.3.12') +GO + +SELECT CONVERT(DATE, '2024.11.12') +GO + +SELECT CONVERT(DATE, '2024 . 3 . 12') +GO + +SELECT CONVERT(DATE, '4/3/2') +GO + +SELECT CONVERT(DATE, '4/3/12') +GO + +SELECT CONVERT(DATE, '24/3/12') +GO + +SELECT CONVERT(DATE, '2024/3/12') +GO + +SELECT CONVERT(DATE, '2024/11/12') +GO + +SELECT CONVERT(DATE, '2024 / 3 / 12') +GO + +-- invalid syntax +SELECT CONVERT(DATE, '3 12 2024') +GO + +SELECT CONVERT(DATE, '3#12#2024') +GO + +SELECT CONVERT(DATE, '3/12.2024') +GO + +-- cut off year +SELECT CONVERT(DATE, '11-12-49') +GO + +SELECT CONVERT(DATE, '11-12-50') +GO + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '03-22-2024') +GO + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '22-03-2024') +GO + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '2024-03-22') +GO + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '03-2024-22') +GO + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '22-2024-03') +GO + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATE, Hence following query should throw error +SELECT CONVERT(DATE, '2-3-4') +GO + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATE, '2024-22-03') +GO + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- -- Boundary values +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999') +GO + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.99999999') +GO + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.999999999') +GO + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.99999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.999999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999999') +GO + +SELECT CONVERT(DATE,'2022-10-00') +GO + +SELECT CONVERT(DATE,'0000-10-01') +GO + +SELECT CONVERT(DATE,'2023-00-01') +GO + +SELECT CONVERT(DATE,'0000-00-00') +GO + +SELECT CONVERT(DATE,'1752-01-01') +GO + +SELECT CONVERT(DATE,'1753-01-01') +GO + +SELECT CONVERT(DATE,'1899-01-01') +GO + +SELECT CONVERT(DATE,'1900-01-01') +GO + +SELECT CONVERT(DATE,'2079-06-06') +GO + +SELECT CONVERT(DATE,'2079-06-07') +GO + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATE, 'Apr 12,2000') +GO + +SELECT CONVERT(DATE, 'Apr 12 2000') +GO + +SELECT CONVERT(DATE, 'Apr 1,2000') +GO + +SELECT CONVERT(DATE, 'Apr 1 2000') +GO + +SELECT CONVERT(DATE, 'Apr,2000') +GO + +SELECT CONVERT(DATE, 'Apr 2000') +GO + +SELECT CONVERT(DATE, 'Apr12,2000') +GO + +SELECT CONVERT(DATE, 'Apr12 2000') +GO + +SELECT CONVERT(DATE, 'Apr1,2000') +GO + +SELECT CONVERT(DATE, 'Apr1 2000') +GO + +SELECT CONVERT(DATE, 'Apr,2000') +GO + +SELECT CONVERT(DATE, 'Apr2000') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATE, 'Apr 12, 24') +GO + +SELECT CONVERT(DATE, 'Apr 12 24') +GO + +SELECT CONVERT(DATE, 'Apr 12, 4') +GO + +SELECT CONVERT(DATE, 'Apr 12 4') +GO + +SELECT CONVERT(DATE, 'Apr 12,') +GO + +SELECT CONVERT(DATE, 'Apr 12') +GO + +SELECT CONVERT(DATE, 'Apr 1, 24') +GO + +SELECT CONVERT(DATE, 'Apr 1 24') +GO + +SELECT CONVERT(DATE, 'Apr 1, 4') +GO + +SELECT CONVERT(DATE, 'Apr 1 4') +GO + +SELECT CONVERT(DATE, 'Apr 1,') +GO + +SELECT CONVERT(DATE, 'Apr 1') +GO + +SELECT CONVERT(DATE, 'Apr12, 24') +GO + +SELECT CONVERT(DATE, 'Apr12 24') +GO + +SELECT CONVERT(DATE, 'Apr12, 4') +GO + +SELECT CONVERT(DATE, 'Apr12 4') +GO + +SELECT CONVERT(DATE, 'Apr12,') +GO + +SELECT CONVERT(DATE, 'Apr12') +GO + +SELECT CONVERT(DATE, 'Apr1, 24') +GO + +SELECT CONVERT(DATE, 'Apr1 24') +GO + +SELECT CONVERT(DATE, 'Apr1, 4') +GO + +SELECT CONVERT(DATE, 'Apr1 4') +GO + +SELECT CONVERT(DATE, 'Apr1,') +GO + +SELECT CONVERT(DATE, 'Apr1') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12,', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1,', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1', 130) +GO + +SELECT CONVERT(DATE, N'محرم12, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم12 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم12, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم12 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم12,', 130) +GO + +SELECT CONVERT(DATE, N'محرم12', 130) +GO + +SELECT CONVERT(DATE, N'محرم1, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم1 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم1, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم1 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم1,', 130) +GO + +SELECT CONVERT(DATE, N'محرم1', 130) +GO + +--- mon yyyy [dd] +SELECT CONVERT(DATE, 'Apr 2024 22') +GO + +SELECT CONVERT(DATE, 'Apr 2024 2') +GO + +SELECT CONVERT(DATE, 'Apr 2024') +GO + +SELECT CONVERT(DATE, 'Apr2024 22') +GO + +SELECT CONVERT(DATE, 'Apr2024 2') +GO + +SELECT CONVERT(DATE, 'Apr2024') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 2024 22', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2024 2', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024 22', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024 2', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATE, '24 Apr, 2024') +GO + +SELECT CONVERT(DATE, '24 Apr 2024') +GO + +SELECT CONVERT(DATE, '4 Apr, 2024') +GO + +SELECT CONVERT(DATE, '4 Apr 2024') +GO + +SELECT CONVERT(DATE, 'Apr, 2024') +GO + +SELECT CONVERT(DATE, 'Apr 2024') +GO + +SELECT CONVERT(DATE, '24Apr, 2024') +GO + +SELECT CONVERT(DATE, '24Apr2024') +GO + +SELECT CONVERT(DATE, '4Apr, 2024') +GO + +SELECT CONVERT(DATE, '4Apr2024') +GO + +SELECT CONVERT(DATE, 'Apr, 2024') +GO + +SELECT CONVERT(DATE, 'Apr2024') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATE, N'24 محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'24 محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'4 محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'4 محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'24محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'24محرم2024', 130) +GO + +SELECT CONVERT(DATE, N'4محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'4محرم2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO + +--- dd mon[,][yy]yy +SELECT CONVERT(DATE, '12 Apr, 2024') +GO + +SELECT CONVERT(DATE, '12 Apr 2024') +GO + +SELECT CONVERT(DATE, '12 Apr, 24') +GO + +SELECT CONVERT(DATE, '12 Apr 24') +GO + +SELECT CONVERT(DATE, '12 Apr, 4') +GO + +SELECT CONVERT(DATE, '12 Apr 4') +GO + +SELECT CONVERT(DATE, '12 Apr,') +GO + +SELECT CONVERT(DATE, '12 Apr') +GO + +SELECT CONVERT(DATE, '12Apr, 2024') +GO + +SELECT CONVERT(DATE, '12Apr2024') +GO + +SELECT CONVERT(DATE, '12Apr, 24') +GO + +SELECT CONVERT(DATE, '12Apr24') +GO + +SELECT CONVERT(DATE, '12Apr, 4') +GO + +SELECT CONVERT(DATE, '12Apr4') +GO + +SELECT CONVERT(DATE, '12Apr,') +GO + +SELECT CONVERT(DATE, '12Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATE, N'12 محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم, 24', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم 24', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم, 4', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم 4', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم,', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'12محرم2024', 130) +GO + +SELECT CONVERT(DATE, N'12محرم, 24', 130) +GO + +SELECT CONVERT(DATE, N'12محرم24', 130) +GO + +SELECT CONVERT(DATE, N'12محرم, 4', 130) +GO + +SELECT CONVERT(DATE, N'12محرم4', 130) +GO + +SELECT CONVERT(DATE, N'12محرم,', 130) +GO + +SELECT CONVERT(DATE, N'12محرم', 130) +GO + +--- dd [yy]yy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO + +SELECT CONVERT(DATE, '12 24 Apr') +GO + +SELECT CONVERT(DATE, '12 2024Apr') +GO + +SELECT CONVERT(DATE, '12 24Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 24 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 24محرم', 130) +GO + +--- [dd] yyyy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO + +SELECT CONVERT(DATE, '2 2024 Apr') +GO + +SELECT CONVERT(DATE, '2024 Apr') +GO + +SELECT CONVERT(DATE, '12 2024Apr') +GO + +SELECT CONVERT(DATE, '2 2024Apr') +GO + +SELECT CONVERT(DATE, '2024Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2 2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO + +SELECT CONVERT(DATE, N'2 2024محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO + +--- yyyy mon [dd] +SELECT CONVERT(DATE, '2024 Apr 12') +GO + +SELECT CONVERT(DATE, '2024 Apr 2') +GO + +SELECT CONVERT(DATE, '2024 Apr') +GO + +SELECT CONVERT(DATE, '2024Apr12') +GO + +SELECT CONVERT(DATE, '2024Apr2') +GO + +SELECT CONVERT(DATE, '2024Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 محرم 12', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم 2', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم12', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم2', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO + +--- yyyy [dd] mon +SELECT CONVERT(DATE, '2024 12 Apr') +GO + +SELECT CONVERT(DATE, '2024 2 Apr') +GO + +SELECT CONVERT(DATE, '2024 Apr') +GO + +SELECT CONVERT(DATE, '2024 12Apr') +GO + +SELECT CONVERT(DATE, '2024 2Apr') +GO + +SELECT CONVERT(DATE, '2024Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 12 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 2 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 12محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 2محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO + +-- ISO 8601 +SELECT CONVERT(DATE, '2023-11-27') +GO + +SELECT CONVERT(DATE, '2023-2-29') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-1-22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-2T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T3:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:4:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:1.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345678') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456789') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567891') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.15') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123-11:11') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123Z') +GO + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATE, '2022-10-22T13 :34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10 -22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22 T 13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 Z') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 -11:11') +GO + +-- -- rounding +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999995') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999994') +GO + +-- DATE with typmod +SELECT CONVERT(DATE(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATE(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATE(3), '01/01/98 23:59:59.123') +GO + +-- Unseparated +SELECT CONVERT(DATE, '20240129') +GO + +SELECT CONVERT(DATE, '20790606') +GO + +SELECT CONVERT(DATE, '20790607') +GO + +SELECT CONVERT(DATE, '240129') +GO + +SELECT CONVERT(DATE, '241329') +GO + +SELECT CONVERT(DATE, '2001') +GO + +SELECT CONVERT(DATE, '0001') +GO + +SELECT CONVERT(DATE, '1753') +GO + +SELECT CONVERT(DATE, '1900') +GO + +-- for styles 130 and 131, the DATE ranges (for example, number of days in a month) are different compared to other styles +SELECT CONVERT(DATE, '20231229', 130) +GO + +SELECT CONVERT(DATE, '20231230', 130) +GO + +SELECT CONVERT(DATE, '20231129', 130) +GO + +SELECT CONVERT(DATE, '20231130', 130) +GO + +SELECT CONVERT(DATE, '20231229', 131) +GO + +SELECT CONVERT(DATE, '20231230', 131) +GO + +SELECT CONVERT(DATE, '20231129', 131) +GO + +SELECT CONVERT(DATE, '20231130', 131) +GO + +-- -- hijri leap year only contains 29 days in 12th month (for style 130 and 131) +SELECT CONVERT(DATE, '20241230', 130) +GO + +SELECT CONVERT(DATE, '20241230', 131) +GO + +SELECT CONVERT(DATE, '20241229', 130) +GO + +SELECT CONVERT(DATE, '20241229', 131) +GO + +-- -- invalid syntax +SELECT CONVERT(DATE, '0') +GO + +SELECT CONVERT(DATE, '1') +GO + +SELECT CONVERT(DATE, '11') +GO + +SELECT CONVERT(DATE, '111') +GO + +SELECT CONVERT(DATE, '11111') +GO + +SELECT CONVERT(DATE, '1111111') +GO + +-- W3C XML format +SELECT CONVERT(DATE, '2024-04-22-05:12') +GO + +SELECT CONVERT(DATE, '2024-04-22+05:12') +GO + +SELECT CONVERT(DATE, '2024-04-22-14:00') +GO + +SELECT CONVERT(DATE, '2024-04-22+14:00') +GO + +SELECT CONVERT(DATE, '2024-04-22-14:10') +GO + +SELECT CONVERT(DATE, '2024-04-22+14:10') +GO + +SELECT CONVERT(DATE, '2024-04-22Z') +GO + +SELECT CONVERT(DATE, '24-04-22Z') +GO + +SELECT CONVERT(DATE, '2024-4-22Z') +GO + +SELECT CONVERT(DATE, '2024-04-2Z') +GO + +-- hijri +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 131) +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(DATE, '02/12/21', 1) +GO + +SELECT CONVERT(DATE, '21.02.12', 2) +GO + +SELECT CONVERT(DATE, '12/02/21', 3) +GO + +SELECT CONVERT(DATE, '12.02.21', 4) +GO + +SELECT CONVERT(DATE, '12-02-21', 5) +GO + +SELECT CONVERT(DATE, '12 Apr 21', 6) +GO + +SELECT CONVERT(DATE, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(DATE, '10:13:14', 8) +GO + +SELECT CONVERT(DATE, '10:13:14', 24) +GO + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(DATE, '02-12-21', 10) +GO + +SELECT CONVERT(DATE, '21/02/12', 11) +GO + +SELECT CONVERT(DATE, '210212', 12) +GO + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(DATE, '15:13:14:123', 14) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(DATE, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(DATE, '2021-02-12', 23) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(DATE, '02/12/2021', 101) +GO + +SELECT CONVERT(DATE, '2021.02.12', 102) +GO + +SELECT CONVERT(DATE, '12/02/2021', 103) +GO + +SELECT CONVERT(DATE, '12.02.2021', 104) +GO + +SELECT CONVERT(DATE, '12-02-2021', 105) +GO + +SELECT CONVERT(DATE, '12 Apr 2021', 106) +GO + +SELECT CONVERT(DATE, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(DATE, '10:13:14', 108) +GO + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(DATE, '02-12-2021', 110) +GO + +SELECT CONVERT(DATE, '2021/02/12', 111) +GO + +SELECT CONVERT(DATE, '20210212', 112) +GO + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(DATE, '15:13:14:123', 114) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 127) +GO + +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATE, N'22 April 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATE, '12/02/2021 15:13:14:123 PM', 131) +GO + +-- -- misc +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATE, '2020') +GO + +SELECT CONVERT(DATE, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(DATE, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATE, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATE, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(DATE, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(DATE, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(DATE, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATE, '2020') +GO + +SELECT CONVERT(DATE, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATE, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATE, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_date_v1 +GO +EXEC test_conv_string_to_date_p1 +GO +SELECT test_conv_string_to_date_f1() +GO + +SELECT * FROM test_conv_string_to_date_v2 +GO +EXEC test_conv_string_to_date_p2 +GO +SELECT test_conv_string_to_date_f2() +GO + +SELECT * FROM test_conv_string_to_date_v3 +GO +EXEC test_conv_string_to_date_p3 +GO +SELECT test_conv_string_to_date_f3() +GO + +SELECT * FROM test_conv_string_to_date_v4 +GO +EXEC test_conv_string_to_date_p4 +GO +SELECT test_conv_string_to_date_f4() +GO + +SELECT * FROM test_conv_string_to_date_v5 +GO +EXEC test_conv_string_to_date_p5 +GO +SELECT test_conv_string_to_date_f5() +GO + +SELECT * FROM test_conv_string_to_date_v6 +GO +EXEC test_conv_string_to_date_p6 +GO +SELECT test_conv_string_to_date_f6() +GO + +SELECT * FROM test_conv_string_to_date_v7 +GO +EXEC test_conv_string_to_date_p7 +GO +SELECT test_conv_string_to_date_f7() +GO + +SELECT * FROM test_conv_string_to_date_v8 +GO +EXEC test_conv_string_to_date_p8 +GO +SELECT test_conv_string_to_date_f8() +GO + +SELECT * FROM test_conv_string_to_date_v9 +GO +EXEC test_conv_string_to_date_p9 +GO +SELECT test_conv_string_to_date_f9() +GO + +SELECT * FROM test_conv_string_to_date_v10 +GO + +SELECT * FROM test_conv_string_to_date_v11 +GO + +SELECT * FROM test_conv_string_to_date_v12 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-cleanup.sql new file mode 100644 index 0000000000..cee7023fa0 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-cleanup.sql @@ -0,0 +1,68 @@ +DROP VIEW test_conv_string_to_date_v1 +GO +DROP PROCEDURE test_conv_string_to_date_p1 +GO +DROP FUNCTION test_conv_string_to_date_f1() +GO + +DROP VIEW test_conv_string_to_date_v2 +GO +DROP PROCEDURE test_conv_string_to_date_p2 +GO +DROP FUNCTION test_conv_string_to_date_f2() +GO + +DROP VIEW test_conv_string_to_date_v3 +GO +DROP PROCEDURE test_conv_string_to_date_p3 +GO +DROP FUNCTION test_conv_string_to_date_f3() +GO + +DROP VIEW test_conv_string_to_date_v4 +GO +DROP PROCEDURE test_conv_string_to_date_p4 +GO +DROP FUNCTION test_conv_string_to_date_f4() +GO + +DROP VIEW test_conv_string_to_date_v5 +GO +DROP PROCEDURE test_conv_string_to_date_p5 +GO +DROP FUNCTION test_conv_string_to_date_f5() +GO + +DROP VIEW test_conv_string_to_date_v6 +GO +DROP PROCEDURE test_conv_string_to_date_p6 +GO +DROP FUNCTION test_conv_string_to_date_f6() +GO + +DROP VIEW test_conv_string_to_date_v7 +GO +DROP PROCEDURE test_conv_string_to_date_p7 +GO +DROP FUNCTION test_conv_string_to_date_f7() +GO + +DROP VIEW test_conv_string_to_date_v8 +GO +DROP PROCEDURE test_conv_string_to_date_p8 +GO +DROP FUNCTION test_conv_string_to_date_f8() +GO + +DROP VIEW test_conv_string_to_date_v9 +GO +DROP PROCEDURE test_conv_string_to_date_p9 +GO +DROP FUNCTION test_conv_string_to_date_f9() +GO + +DROP VIEW test_conv_string_to_date_v10 +GO + +DROP VIEW test_conv_string_to_date_v12 +GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-prepare.sql new file mode 100644 index 0000000000..bec661977b --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-prepare.sql @@ -0,0 +1,104 @@ +CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f1() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '2017-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f2() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '9999-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_date_f3() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE FUNCTION test_conv_string_to_date_f4() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f5() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f6() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f7() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_date_f8() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f9() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +GO + +CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-verify.sql new file mode 100644 index 0000000000..dfd5cd1a7f --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-verify.sql @@ -0,0 +1,1478 @@ +-- Only DATE string +-- Empty string, should return default values +SELECT CONVERT(DATE, '') +GO + +SELECT CONVERT(DATE, '', 130) +GO + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATE, '3-2-4') +GO + +SELECT CONVERT(DATE, '3-12-4') +GO + +SELECT CONVERT(DATE, '3-12-24') +GO + +SELECT CONVERT(DATE, '3-12-2024') +GO + +SELECT CONVERT(DATE, '11-12-2024') +GO + +SELECT CONVERT(DATE, '3 - 12 - 2024') +GO + +SELECT CONVERT(DATE, '3.2.4') +GO + +SELECT CONVERT(DATE, '3.12.4') +GO + +SELECT CONVERT(DATE, '3.12.24') +GO + +SELECT CONVERT(DATE, '3.12.2024') +GO + +SELECT CONVERT(DATE, '11.12.2024') +GO + +SELECT CONVERT(DATE, '3 . 12 . 2024') +GO + +SELECT CONVERT(DATE, '3/2/4') +GO + +SELECT CONVERT(DATE, '3/12/4') +GO + +SELECT CONVERT(DATE, '3/12/24') +GO + +SELECT CONVERT(DATE, '3/12/2024') +GO + +SELECT CONVERT(DATE, '11/12/2024') +GO + +SELECT CONVERT(DATE, '3 / 12 / 2024') +GO + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATE, '3-4-2') +GO + +SELECT CONVERT(DATE, '3-4-12') +GO + +SELECT CONVERT(DATE, '3-24-12') +GO + +SELECT CONVERT(DATE, '3-2024-12') +GO + +SELECT CONVERT(DATE, '11-2024-12') +GO + +SELECT CONVERT(DATE, '3 - 2024 - 12') +GO + +SELECT CONVERT(DATE, '3.4.2') +GO + +SELECT CONVERT(DATE, '3.4.12') +GO + +SELECT CONVERT(DATE, '3.24.12') +GO + +SELECT CONVERT(DATE, '3.2024.12') +GO + +SELECT CONVERT(DATE, '11.2024.12') +GO + +SELECT CONVERT(DATE, '3 . 2024 . 12') +GO + +SELECT CONVERT(DATE, '3/4/2') +GO + +SELECT CONVERT(DATE, '3/4/12') +GO + +SELECT CONVERT(DATE, '3/24/12') +GO + +SELECT CONVERT(DATE, '3/2024/12') +GO + +SELECT CONVERT(DATE, '11/2024/12') +GO + +SELECT CONVERT(DATE, '3 / 2024 / 12') +GO + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '12-3-4') +GO + +SELECT CONVERT(DATE, '12-3-24') +GO + +SELECT CONVERT(DATE, '12-3-2024') +GO + +SELECT CONVERT(DATE, '12-11-2024') +GO + +SELECT CONVERT(DATE, '12 - 3 - 2024') +GO + +SELECT CONVERT(DATE, '2.3.4') +GO + +SELECT CONVERT(DATE, '12.3.4') +GO + +SELECT CONVERT(DATE, '12.3.24') +GO + +SELECT CONVERT(DATE, '12.3.2024') +GO + +SELECT CONVERT(DATE, '12.11.2024') +GO + +SELECT CONVERT(DATE, '12 . 3 . 2024') +GO + +SELECT CONVERT(DATE, '2/3/4') +GO + +SELECT CONVERT(DATE, '12/3/4') +GO + +SELECT CONVERT(DATE, '12/3/24') +GO + +SELECT CONVERT(DATE, '12/3/2024') +GO + +SELECT CONVERT(DATE, '12/11/2024') +GO + +SELECT CONVERT(DATE, '12 / 3 / 2024') +GO + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATE, '2-4-3') +GO + +SELECT CONVERT(DATE, '12-4-3') +GO + +SELECT CONVERT(DATE, '12-24-3') +GO + +SELECT CONVERT(DATE, '12-2024-3') +GO + +SELECT CONVERT(DATE, '12-2024-11') +GO + +SELECT CONVERT(DATE, '12 - 2024 - 3') +GO + +SELECT CONVERT(DATE, '2.4.3') +GO + +SELECT CONVERT(DATE, '12.4.3') +GO + +SELECT CONVERT(DATE, '12.24.3') +GO + +SELECT CONVERT(DATE, '12.2024.3') +GO + +SELECT CONVERT(DATE, '12.2024.11') +GO + +SELECT CONVERT(DATE, '12 . 2024 . 3') +GO + +SELECT CONVERT(DATE, '2/4/3') +GO + +SELECT CONVERT(DATE, '12/4/3') +GO + +SELECT CONVERT(DATE, '12/24/3') +GO + +SELECT CONVERT(DATE, '12/2024/3') +GO + +SELECT CONVERT(DATE, '12/2024/11') +GO + +SELECT CONVERT(DATE, '12 / 2024 / 3') +GO + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATE, '4-3-2') +GO + +SELECT CONVERT(DATE, '4-3-12') +GO + +SELECT CONVERT(DATE, '24-3-12') +GO + +SELECT CONVERT(DATE, '2024-3-12') +GO + +SELECT CONVERT(DATE, '2024-11-12') +GO + +SELECT CONVERT(DATE, '2024 - 3 - 12') +GO + +SELECT CONVERT(DATE, '4.3.2') +GO + +SELECT CONVERT(DATE, '4.3.12') +GO + +SELECT CONVERT(DATE, '24.3.12') +GO + +SELECT CONVERT(DATE, '2024.3.12') +GO + +SELECT CONVERT(DATE, '2024.11.12') +GO + +SELECT CONVERT(DATE, '2024 . 3 . 12') +GO + +SELECT CONVERT(DATE, '4/3/2') +GO + +SELECT CONVERT(DATE, '4/3/12') +GO + +SELECT CONVERT(DATE, '24/3/12') +GO + +SELECT CONVERT(DATE, '2024/3/12') +GO + +SELECT CONVERT(DATE, '2024/11/12') +GO + +SELECT CONVERT(DATE, '2024 / 3 / 12') +GO + +-- invalid syntax +SELECT CONVERT(DATE, '3 12 2024') +GO + +SELECT CONVERT(DATE, '3#12#2024') +GO + +SELECT CONVERT(DATE, '3/12.2024') +GO + +-- cut off year +SELECT CONVERT(DATE, '11-12-49') +GO + +SELECT CONVERT(DATE, '11-12-50') +GO + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '03-22-2024') +GO + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '22-03-2024') +GO + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '2024-03-22') +GO + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '03-2024-22') +GO + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '22-2024-03') +GO + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATE, Hence following query should throw error +SELECT CONVERT(DATE, '2-3-4') +GO + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATE, '2024-22-03') +GO + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- -- Boundary values +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999') +GO + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.99999999') +GO + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.999999999') +GO + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.99999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.999999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999999') +GO + +SELECT CONVERT(DATE,'2022-10-00') +GO + +SELECT CONVERT(DATE,'0000-10-01') +GO + +SELECT CONVERT(DATE,'2023-00-01') +GO + +SELECT CONVERT(DATE,'0000-00-00') +GO + +SELECT CONVERT(DATE,'1752-01-01') +GO + +SELECT CONVERT(DATE,'1753-01-01') +GO + +SELECT CONVERT(DATE,'1899-01-01') +GO + +SELECT CONVERT(DATE,'1900-01-01') +GO + +SELECT CONVERT(DATE,'2079-06-06') +GO + +SELECT CONVERT(DATE,'2079-06-07') +GO + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATE, 'Apr 12,2000') +GO + +SELECT CONVERT(DATE, 'Apr 12 2000') +GO + +SELECT CONVERT(DATE, 'Apr 1,2000') +GO + +SELECT CONVERT(DATE, 'Apr 1 2000') +GO + +SELECT CONVERT(DATE, 'Apr,2000') +GO + +SELECT CONVERT(DATE, 'Apr 2000') +GO + +SELECT CONVERT(DATE, 'Apr12,2000') +GO + +SELECT CONVERT(DATE, 'Apr12 2000') +GO + +SELECT CONVERT(DATE, 'Apr1,2000') +GO + +SELECT CONVERT(DATE, 'Apr1 2000') +GO + +SELECT CONVERT(DATE, 'Apr,2000') +GO + +SELECT CONVERT(DATE, 'Apr2000') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATE, 'Apr 12, 24') +GO + +SELECT CONVERT(DATE, 'Apr 12 24') +GO + +SELECT CONVERT(DATE, 'Apr 12, 4') +GO + +SELECT CONVERT(DATE, 'Apr 12 4') +GO + +SELECT CONVERT(DATE, 'Apr 12,') +GO + +SELECT CONVERT(DATE, 'Apr 12') +GO + +SELECT CONVERT(DATE, 'Apr 1, 24') +GO + +SELECT CONVERT(DATE, 'Apr 1 24') +GO + +SELECT CONVERT(DATE, 'Apr 1, 4') +GO + +SELECT CONVERT(DATE, 'Apr 1 4') +GO + +SELECT CONVERT(DATE, 'Apr 1,') +GO + +SELECT CONVERT(DATE, 'Apr 1') +GO + +SELECT CONVERT(DATE, 'Apr12, 24') +GO + +SELECT CONVERT(DATE, 'Apr12 24') +GO + +SELECT CONVERT(DATE, 'Apr12, 4') +GO + +SELECT CONVERT(DATE, 'Apr12 4') +GO + +SELECT CONVERT(DATE, 'Apr12,') +GO + +SELECT CONVERT(DATE, 'Apr12') +GO + +SELECT CONVERT(DATE, 'Apr1, 24') +GO + +SELECT CONVERT(DATE, 'Apr1 24') +GO + +SELECT CONVERT(DATE, 'Apr1, 4') +GO + +SELECT CONVERT(DATE, 'Apr1 4') +GO + +SELECT CONVERT(DATE, 'Apr1,') +GO + +SELECT CONVERT(DATE, 'Apr1') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12,', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1,', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1', 130) +GO + +SELECT CONVERT(DATE, N'محرم12, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم12 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم12, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم12 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم12,', 130) +GO + +SELECT CONVERT(DATE, N'محرم12', 130) +GO + +SELECT CONVERT(DATE, N'محرم1, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم1 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم1, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم1 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم1,', 130) +GO + +SELECT CONVERT(DATE, N'محرم1', 130) +GO + +--- mon yyyy [dd] +SELECT CONVERT(DATE, 'Apr 2024 22') +GO + +SELECT CONVERT(DATE, 'Apr 2024 2') +GO + +SELECT CONVERT(DATE, 'Apr 2024') +GO + +SELECT CONVERT(DATE, 'Apr2024 22') +GO + +SELECT CONVERT(DATE, 'Apr2024 2') +GO + +SELECT CONVERT(DATE, 'Apr2024') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 2024 22', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2024 2', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024 22', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024 2', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATE, '24 Apr, 2024') +GO + +SELECT CONVERT(DATE, '24 Apr 2024') +GO + +SELECT CONVERT(DATE, '4 Apr, 2024') +GO + +SELECT CONVERT(DATE, '4 Apr 2024') +GO + +SELECT CONVERT(DATE, 'Apr, 2024') +GO + +SELECT CONVERT(DATE, 'Apr 2024') +GO + +SELECT CONVERT(DATE, '24Apr, 2024') +GO + +SELECT CONVERT(DATE, '24Apr2024') +GO + +SELECT CONVERT(DATE, '4Apr, 2024') +GO + +SELECT CONVERT(DATE, '4Apr2024') +GO + +SELECT CONVERT(DATE, 'Apr, 2024') +GO + +SELECT CONVERT(DATE, 'Apr2024') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATE, N'24 محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'24 محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'4 محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'4 محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'24محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'24محرم2024', 130) +GO + +SELECT CONVERT(DATE, N'4محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'4محرم2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO + +--- dd mon[,][yy]yy +SELECT CONVERT(DATE, '12 Apr, 2024') +GO + +SELECT CONVERT(DATE, '12 Apr 2024') +GO + +SELECT CONVERT(DATE, '12 Apr, 24') +GO + +SELECT CONVERT(DATE, '12 Apr 24') +GO + +SELECT CONVERT(DATE, '12 Apr, 4') +GO + +SELECT CONVERT(DATE, '12 Apr 4') +GO + +SELECT CONVERT(DATE, '12 Apr,') +GO + +SELECT CONVERT(DATE, '12 Apr') +GO + +SELECT CONVERT(DATE, '12Apr, 2024') +GO + +SELECT CONVERT(DATE, '12Apr2024') +GO + +SELECT CONVERT(DATE, '12Apr, 24') +GO + +SELECT CONVERT(DATE, '12Apr24') +GO + +SELECT CONVERT(DATE, '12Apr, 4') +GO + +SELECT CONVERT(DATE, '12Apr4') +GO + +SELECT CONVERT(DATE, '12Apr,') +GO + +SELECT CONVERT(DATE, '12Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATE, N'12 محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم, 24', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم 24', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم, 4', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم 4', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم,', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'12محرم2024', 130) +GO + +SELECT CONVERT(DATE, N'12محرم, 24', 130) +GO + +SELECT CONVERT(DATE, N'12محرم24', 130) +GO + +SELECT CONVERT(DATE, N'12محرم, 4', 130) +GO + +SELECT CONVERT(DATE, N'12محرم4', 130) +GO + +SELECT CONVERT(DATE, N'12محرم,', 130) +GO + +SELECT CONVERT(DATE, N'12محرم', 130) +GO + +--- dd [yy]yy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO + +SELECT CONVERT(DATE, '12 24 Apr') +GO + +SELECT CONVERT(DATE, '12 2024Apr') +GO + +SELECT CONVERT(DATE, '12 24Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 24 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 24محرم', 130) +GO + +--- [dd] yyyy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO + +SELECT CONVERT(DATE, '2 2024 Apr') +GO + +SELECT CONVERT(DATE, '2024 Apr') +GO + +SELECT CONVERT(DATE, '12 2024Apr') +GO + +SELECT CONVERT(DATE, '2 2024Apr') +GO + +SELECT CONVERT(DATE, '2024Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2 2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO + +SELECT CONVERT(DATE, N'2 2024محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO + +--- yyyy mon [dd] +SELECT CONVERT(DATE, '2024 Apr 12') +GO + +SELECT CONVERT(DATE, '2024 Apr 2') +GO + +SELECT CONVERT(DATE, '2024 Apr') +GO + +SELECT CONVERT(DATE, '2024Apr12') +GO + +SELECT CONVERT(DATE, '2024Apr2') +GO + +SELECT CONVERT(DATE, '2024Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 محرم 12', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم 2', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم12', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم2', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO + +--- yyyy [dd] mon +SELECT CONVERT(DATE, '2024 12 Apr') +GO + +SELECT CONVERT(DATE, '2024 2 Apr') +GO + +SELECT CONVERT(DATE, '2024 Apr') +GO + +SELECT CONVERT(DATE, '2024 12Apr') +GO + +SELECT CONVERT(DATE, '2024 2Apr') +GO + +SELECT CONVERT(DATE, '2024Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 12 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 2 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 12محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 2محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO + +-- ISO 8601 +SELECT CONVERT(DATE, '2023-11-27') +GO + +SELECT CONVERT(DATE, '2023-2-29') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-1-22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-2T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T3:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:4:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:1.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345678') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456789') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567891') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.15') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123-11:11') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123Z') +GO + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATE, '2022-10-22T13 :34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10 -22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22 T 13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 Z') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 -11:11') +GO + +-- -- rounding +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999995') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999994') +GO + +-- DATE with typmod +SELECT CONVERT(DATE(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATE(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATE(3), '01/01/98 23:59:59.123') +GO + +-- Unseparated +SELECT CONVERT(DATE, '20240129') +GO + +SELECT CONVERT(DATE, '20790606') +GO + +SELECT CONVERT(DATE, '20790607') +GO + +SELECT CONVERT(DATE, '240129') +GO + +SELECT CONVERT(DATE, '241329') +GO + +SELECT CONVERT(DATE, '2001') +GO + +SELECT CONVERT(DATE, '0001') +GO + +SELECT CONVERT(DATE, '1753') +GO + +SELECT CONVERT(DATE, '1900') +GO + +-- for styles 130 and 131, the DATE ranges (for example, number of days in a month) are different compared to other styles +SELECT CONVERT(DATE, '20231229', 130) +GO + +SELECT CONVERT(DATE, '20231230', 130) +GO + +SELECT CONVERT(DATE, '20231129', 130) +GO + +SELECT CONVERT(DATE, '20231130', 130) +GO + +SELECT CONVERT(DATE, '20231229', 131) +GO + +SELECT CONVERT(DATE, '20231230', 131) +GO + +SELECT CONVERT(DATE, '20231129', 131) +GO + +SELECT CONVERT(DATE, '20231130', 131) +GO + +-- -- hijri leap year only contains 29 days in 12th month (for style 130 and 131) +SELECT CONVERT(DATE, '20241230', 130) +GO + +SELECT CONVERT(DATE, '20241230', 131) +GO + +SELECT CONVERT(DATE, '20241229', 130) +GO + +SELECT CONVERT(DATE, '20241229', 131) +GO + +-- -- invalid syntax +SELECT CONVERT(DATE, '0') +GO + +SELECT CONVERT(DATE, '1') +GO + +SELECT CONVERT(DATE, '11') +GO + +SELECT CONVERT(DATE, '111') +GO + +SELECT CONVERT(DATE, '11111') +GO + +SELECT CONVERT(DATE, '1111111') +GO + +-- W3C XML format +SELECT CONVERT(DATE, '2024-04-22-05:12') +GO + +SELECT CONVERT(DATE, '2024-04-22+05:12') +GO + +SELECT CONVERT(DATE, '2024-04-22-14:00') +GO + +SELECT CONVERT(DATE, '2024-04-22+14:00') +GO + +SELECT CONVERT(DATE, '2024-04-22-14:10') +GO + +SELECT CONVERT(DATE, '2024-04-22+14:10') +GO + +SELECT CONVERT(DATE, '2024-04-22Z') +GO + +SELECT CONVERT(DATE, '24-04-22Z') +GO + +SELECT CONVERT(DATE, '2024-4-22Z') +GO + +SELECT CONVERT(DATE, '2024-04-2Z') +GO + +-- hijri +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 131) +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(DATE, '02/12/21', 1) +GO + +SELECT CONVERT(DATE, '21.02.12', 2) +GO + +SELECT CONVERT(DATE, '12/02/21', 3) +GO + +SELECT CONVERT(DATE, '12.02.21', 4) +GO + +SELECT CONVERT(DATE, '12-02-21', 5) +GO + +SELECT CONVERT(DATE, '12 Apr 21', 6) +GO + +SELECT CONVERT(DATE, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(DATE, '10:13:14', 8) +GO + +SELECT CONVERT(DATE, '10:13:14', 24) +GO + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(DATE, '02-12-21', 10) +GO + +SELECT CONVERT(DATE, '21/02/12', 11) +GO + +SELECT CONVERT(DATE, '210212', 12) +GO + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(DATE, '15:13:14:123', 14) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(DATE, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(DATE, '2021-02-12', 23) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(DATE, '02/12/2021', 101) +GO + +SELECT CONVERT(DATE, '2021.02.12', 102) +GO + +SELECT CONVERT(DATE, '12/02/2021', 103) +GO + +SELECT CONVERT(DATE, '12.02.2021', 104) +GO + +SELECT CONVERT(DATE, '12-02-2021', 105) +GO + +SELECT CONVERT(DATE, '12 Apr 2021', 106) +GO + +SELECT CONVERT(DATE, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(DATE, '10:13:14', 108) +GO + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(DATE, '02-12-2021', 110) +GO + +SELECT CONVERT(DATE, '2021/02/12', 111) +GO + +SELECT CONVERT(DATE, '20210212', 112) +GO + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(DATE, '15:13:14:123', 114) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 127) +GO + +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATE, N'22 April 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATE, '12/02/2021 15:13:14:123 PM', 131) +GO + +-- -- misc +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATE, '2020') +GO + +SELECT CONVERT(DATE, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(DATE, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATE, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATE, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(DATE, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(DATE, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(DATE, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATE, '2020') +GO + +SELECT CONVERT(DATE, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATE, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATE, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_date_v1 +GO +EXEC test_conv_string_to_date_p1 +GO +SELECT test_conv_string_to_date_f1() +GO + +SELECT * FROM test_conv_string_to_date_v2 +GO +EXEC test_conv_string_to_date_p2 +GO +SELECT test_conv_string_to_date_f2() +GO + +SELECT * FROM test_conv_string_to_date_v3 +GO +EXEC test_conv_string_to_date_p3 +GO +SELECT test_conv_string_to_date_f3() +GO + +SELECT * FROM test_conv_string_to_date_v4 +GO +EXEC test_conv_string_to_date_p4 +GO +SELECT test_conv_string_to_date_f4() +GO + +SELECT * FROM test_conv_string_to_date_v5 +GO +EXEC test_conv_string_to_date_p5 +GO +SELECT test_conv_string_to_date_f5() +GO + +SELECT * FROM test_conv_string_to_date_v6 +GO +EXEC test_conv_string_to_date_p6 +GO +SELECT test_conv_string_to_date_f6() +GO + +SELECT * FROM test_conv_string_to_date_v7 +GO +EXEC test_conv_string_to_date_p7 +GO +SELECT test_conv_string_to_date_f7() +GO + +SELECT * FROM test_conv_string_to_date_v8 +GO +EXEC test_conv_string_to_date_p8 +GO +SELECT test_conv_string_to_date_f8() +GO + +SELECT * FROM test_conv_string_to_date_v9 +GO +EXEC test_conv_string_to_date_p9 +GO +SELECT test_conv_string_to_date_f9() +GO + +SELECT * FROM test_conv_string_to_date_v10 +GO + +SELECT * FROM test_conv_string_to_date_v12 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_date-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_date-vu-cleanup.sql new file mode 100644 index 0000000000..c6ca5aedf4 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_date-vu-cleanup.sql @@ -0,0 +1,71 @@ +DROP VIEW test_conv_string_to_date_v1 +GO +DROP PROCEDURE test_conv_string_to_date_p1 +GO +DROP FUNCTION test_conv_string_to_date_f1() +GO + +DROP VIEW test_conv_string_to_date_v2 +GO +DROP PROCEDURE test_conv_string_to_date_p2 +GO +DROP FUNCTION test_conv_string_to_date_f2() +GO + +DROP VIEW test_conv_string_to_date_v3 +GO +DROP PROCEDURE test_conv_string_to_date_p3 +GO +DROP FUNCTION test_conv_string_to_date_f3() +GO + +DROP VIEW test_conv_string_to_date_v4 +GO +DROP PROCEDURE test_conv_string_to_date_p4 +GO +DROP FUNCTION test_conv_string_to_date_f4() +GO + +DROP VIEW test_conv_string_to_date_v5 +GO +DROP PROCEDURE test_conv_string_to_date_p5 +GO +DROP FUNCTION test_conv_string_to_date_f5() +GO + +DROP VIEW test_conv_string_to_date_v6 +GO +DROP PROCEDURE test_conv_string_to_date_p6 +GO +DROP FUNCTION test_conv_string_to_date_f6() +GO + +DROP VIEW test_conv_string_to_date_v7 +GO +DROP PROCEDURE test_conv_string_to_date_p7 +GO +DROP FUNCTION test_conv_string_to_date_f7() +GO + +DROP VIEW test_conv_string_to_date_v8 +GO +DROP PROCEDURE test_conv_string_to_date_p8 +GO +DROP FUNCTION test_conv_string_to_date_f8() +GO + +DROP VIEW test_conv_string_to_date_v9 +GO +DROP PROCEDURE test_conv_string_to_date_p9 +GO +DROP FUNCTION test_conv_string_to_date_f9() +GO + +DROP VIEW test_conv_string_to_date_v10 +GO + +DROP VIEW test_conv_string_to_date_v11 +GO + +DROP VIEW test_conv_string_to_date_v12 +GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_date-vu-prepare.sql new file mode 100644 index 0000000000..7791067ede --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_date-vu-prepare.sql @@ -0,0 +1,107 @@ +CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f1() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '2017-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +GO +CREATE FUNCTION test_conv_string_to_date_f2() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '9999-08-25')); +END +GO + +CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_date_f3() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +GO +CREATE FUNCTION test_conv_string_to_date_f4() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f5() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f6() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f7() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_date_f8() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_date_f9() +RETURNS date AS +BEGIN +RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +GO + +CREATE VIEW test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); +GO + +CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_date-vu-verify.sql new file mode 100644 index 0000000000..7e2bc354aa --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_date-vu-verify.sql @@ -0,0 +1,1482 @@ +-- sla 100000 +-- Only DATE string +-- Empty string, should return default values +SELECT CONVERT(DATE, '') +GO + +SELECT CONVERT(DATE, '', 130) +GO + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATE, '3-2-4') +GO + +SELECT CONVERT(DATE, '3-12-4') +GO + +SELECT CONVERT(DATE, '3-12-24') +GO + +SELECT CONVERT(DATE, '3-12-2024') +GO + +SELECT CONVERT(DATE, '11-12-2024') +GO + +SELECT CONVERT(DATE, '3 - 12 - 2024') +GO + +SELECT CONVERT(DATE, '3.2.4') +GO + +SELECT CONVERT(DATE, '3.12.4') +GO + +SELECT CONVERT(DATE, '3.12.24') +GO + +SELECT CONVERT(DATE, '3.12.2024') +GO + +SELECT CONVERT(DATE, '11.12.2024') +GO + +SELECT CONVERT(DATE, '3 . 12 . 2024') +GO + +SELECT CONVERT(DATE, '3/2/4') +GO + +SELECT CONVERT(DATE, '3/12/4') +GO + +SELECT CONVERT(DATE, '3/12/24') +GO + +SELECT CONVERT(DATE, '3/12/2024') +GO + +SELECT CONVERT(DATE, '11/12/2024') +GO + +SELECT CONVERT(DATE, '3 / 12 / 2024') +GO + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATE, '3-4-2') +GO + +SELECT CONVERT(DATE, '3-4-12') +GO + +SELECT CONVERT(DATE, '3-24-12') +GO + +SELECT CONVERT(DATE, '3-2024-12') +GO + +SELECT CONVERT(DATE, '11-2024-12') +GO + +SELECT CONVERT(DATE, '3 - 2024 - 12') +GO + +SELECT CONVERT(DATE, '3.4.2') +GO + +SELECT CONVERT(DATE, '3.4.12') +GO + +SELECT CONVERT(DATE, '3.24.12') +GO + +SELECT CONVERT(DATE, '3.2024.12') +GO + +SELECT CONVERT(DATE, '11.2024.12') +GO + +SELECT CONVERT(DATE, '3 . 2024 . 12') +GO + +SELECT CONVERT(DATE, '3/4/2') +GO + +SELECT CONVERT(DATE, '3/4/12') +GO + +SELECT CONVERT(DATE, '3/24/12') +GO + +SELECT CONVERT(DATE, '3/2024/12') +GO + +SELECT CONVERT(DATE, '11/2024/12') +GO + +SELECT CONVERT(DATE, '3 / 2024 / 12') +GO + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '12-3-4') +GO + +SELECT CONVERT(DATE, '12-3-24') +GO + +SELECT CONVERT(DATE, '12-3-2024') +GO + +SELECT CONVERT(DATE, '12-11-2024') +GO + +SELECT CONVERT(DATE, '12 - 3 - 2024') +GO + +SELECT CONVERT(DATE, '2.3.4') +GO + +SELECT CONVERT(DATE, '12.3.4') +GO + +SELECT CONVERT(DATE, '12.3.24') +GO + +SELECT CONVERT(DATE, '12.3.2024') +GO + +SELECT CONVERT(DATE, '12.11.2024') +GO + +SELECT CONVERT(DATE, '12 . 3 . 2024') +GO + +SELECT CONVERT(DATE, '2/3/4') +GO + +SELECT CONVERT(DATE, '12/3/4') +GO + +SELECT CONVERT(DATE, '12/3/24') +GO + +SELECT CONVERT(DATE, '12/3/2024') +GO + +SELECT CONVERT(DATE, '12/11/2024') +GO + +SELECT CONVERT(DATE, '12 / 3 / 2024') +GO + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATE, '2-4-3') +GO + +SELECT CONVERT(DATE, '12-4-3') +GO + +SELECT CONVERT(DATE, '12-24-3') +GO + +SELECT CONVERT(DATE, '12-2024-3') +GO + +SELECT CONVERT(DATE, '12-2024-11') +GO + +SELECT CONVERT(DATE, '12 - 2024 - 3') +GO + +SELECT CONVERT(DATE, '2.4.3') +GO + +SELECT CONVERT(DATE, '12.4.3') +GO + +SELECT CONVERT(DATE, '12.24.3') +GO + +SELECT CONVERT(DATE, '12.2024.3') +GO + +SELECT CONVERT(DATE, '12.2024.11') +GO + +SELECT CONVERT(DATE, '12 . 2024 . 3') +GO + +SELECT CONVERT(DATE, '2/4/3') +GO + +SELECT CONVERT(DATE, '12/4/3') +GO + +SELECT CONVERT(DATE, '12/24/3') +GO + +SELECT CONVERT(DATE, '12/2024/3') +GO + +SELECT CONVERT(DATE, '12/2024/11') +GO + +SELECT CONVERT(DATE, '12 / 2024 / 3') +GO + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATE, '4-3-2') +GO + +SELECT CONVERT(DATE, '4-3-12') +GO + +SELECT CONVERT(DATE, '24-3-12') +GO + +SELECT CONVERT(DATE, '2024-3-12') +GO + +SELECT CONVERT(DATE, '2024-11-12') +GO + +SELECT CONVERT(DATE, '2024 - 3 - 12') +GO + +SELECT CONVERT(DATE, '4.3.2') +GO + +SELECT CONVERT(DATE, '4.3.12') +GO + +SELECT CONVERT(DATE, '24.3.12') +GO + +SELECT CONVERT(DATE, '2024.3.12') +GO + +SELECT CONVERT(DATE, '2024.11.12') +GO + +SELECT CONVERT(DATE, '2024 . 3 . 12') +GO + +SELECT CONVERT(DATE, '4/3/2') +GO + +SELECT CONVERT(DATE, '4/3/12') +GO + +SELECT CONVERT(DATE, '24/3/12') +GO + +SELECT CONVERT(DATE, '2024/3/12') +GO + +SELECT CONVERT(DATE, '2024/11/12') +GO + +SELECT CONVERT(DATE, '2024 / 3 / 12') +GO + +-- invalid syntax +SELECT CONVERT(DATE, '3 12 2024') +GO + +SELECT CONVERT(DATE, '3#12#2024') +GO + +SELECT CONVERT(DATE, '3/12.2024') +GO + +-- cut off year +SELECT CONVERT(DATE, '11-12-49') +GO + +SELECT CONVERT(DATE, '11-12-50') +GO + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '03-22-2024') +GO + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '22-03-2024') +GO + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '2024-03-22') +GO + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '03-2024-22') +GO + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATE, '2-3-4') +GO + +SELECT CONVERT(DATE, '22-2024-03') +GO + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATE, Hence following query should throw error +SELECT CONVERT(DATE, '2-3-4') +GO + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATE, '2024-22-03') +GO + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- -- Boundary values +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999') +GO + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.99999999') +GO + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.999999999') +GO + +SELECT CONVERT(DATE, '9999-12-30 23:59:59.9999999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.99999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.999999999') +GO + +SELECT CONVERT(DATE, '9999-12-31 23:59:59.9999999999') +GO + +SELECT CONVERT(DATE,'2022-10-00') +GO + +SELECT CONVERT(DATE,'0000-10-01') +GO + +SELECT CONVERT(DATE,'2023-00-01') +GO + +SELECT CONVERT(DATE,'0000-00-00') +GO + +SELECT CONVERT(DATE,'1752-01-01') +GO + +SELECT CONVERT(DATE,'1753-01-01') +GO + +SELECT CONVERT(DATE,'1899-01-01') +GO + +SELECT CONVERT(DATE,'1900-01-01') +GO + +SELECT CONVERT(DATE,'2079-06-06') +GO + +SELECT CONVERT(DATE,'2079-06-07') +GO + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATE, 'Apr 12,2000') +GO + +SELECT CONVERT(DATE, 'Apr 12 2000') +GO + +SELECT CONVERT(DATE, 'Apr 1,2000') +GO + +SELECT CONVERT(DATE, 'Apr 1 2000') +GO + +SELECT CONVERT(DATE, 'Apr,2000') +GO + +SELECT CONVERT(DATE, 'Apr 2000') +GO + +SELECT CONVERT(DATE, 'Apr12,2000') +GO + +SELECT CONVERT(DATE, 'Apr12 2000') +GO + +SELECT CONVERT(DATE, 'Apr1,2000') +GO + +SELECT CONVERT(DATE, 'Apr1 2000') +GO + +SELECT CONVERT(DATE, 'Apr,2000') +GO + +SELECT CONVERT(DATE, 'Apr2000') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم ,2000', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2000', 130) +GO + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATE, 'Apr 12, 24') +GO + +SELECT CONVERT(DATE, 'Apr 12 24') +GO + +SELECT CONVERT(DATE, 'Apr 12, 4') +GO + +SELECT CONVERT(DATE, 'Apr 12 4') +GO + +SELECT CONVERT(DATE, 'Apr 12,') +GO + +SELECT CONVERT(DATE, 'Apr 12') +GO + +SELECT CONVERT(DATE, 'Apr 1, 24') +GO + +SELECT CONVERT(DATE, 'Apr 1 24') +GO + +SELECT CONVERT(DATE, 'Apr 1, 4') +GO + +SELECT CONVERT(DATE, 'Apr 1 4') +GO + +SELECT CONVERT(DATE, 'Apr 1,') +GO + +SELECT CONVERT(DATE, 'Apr 1') +GO + +SELECT CONVERT(DATE, 'Apr12, 24') +GO + +SELECT CONVERT(DATE, 'Apr12 24') +GO + +SELECT CONVERT(DATE, 'Apr12, 4') +GO + +SELECT CONVERT(DATE, 'Apr12 4') +GO + +SELECT CONVERT(DATE, 'Apr12,') +GO + +SELECT CONVERT(DATE, 'Apr12') +GO + +SELECT CONVERT(DATE, 'Apr1, 24') +GO + +SELECT CONVERT(DATE, 'Apr1 24') +GO + +SELECT CONVERT(DATE, 'Apr1, 4') +GO + +SELECT CONVERT(DATE, 'Apr1 4') +GO + +SELECT CONVERT(DATE, 'Apr1,') +GO + +SELECT CONVERT(DATE, 'Apr1') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 12, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12,', 130) +GO + +SELECT CONVERT(DATE, N'محرم 12', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1,', 130) +GO + +SELECT CONVERT(DATE, N'محرم 1', 130) +GO + +SELECT CONVERT(DATE, N'محرم12, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم12 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم12, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم12 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم12,', 130) +GO + +SELECT CONVERT(DATE, N'محرم12', 130) +GO + +SELECT CONVERT(DATE, N'محرم1, 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم1 24', 130) +GO + +SELECT CONVERT(DATE, N'محرم1, 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم1 4', 130) +GO + +SELECT CONVERT(DATE, N'محرم1,', 130) +GO + +SELECT CONVERT(DATE, N'محرم1', 130) +GO + +--- mon yyyy [dd] +SELECT CONVERT(DATE, 'Apr 2024 22') +GO + +SELECT CONVERT(DATE, 'Apr 2024 2') +GO + +SELECT CONVERT(DATE, 'Apr 2024') +GO + +SELECT CONVERT(DATE, 'Apr2024 22') +GO + +SELECT CONVERT(DATE, 'Apr2024 2') +GO + +SELECT CONVERT(DATE, 'Apr2024') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'محرم 2024 22', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2024 2', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024 22', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024 2', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATE, '24 Apr, 2024') +GO + +SELECT CONVERT(DATE, '24 Apr 2024') +GO + +SELECT CONVERT(DATE, '4 Apr, 2024') +GO + +SELECT CONVERT(DATE, '4 Apr 2024') +GO + +SELECT CONVERT(DATE, 'Apr, 2024') +GO + +SELECT CONVERT(DATE, 'Apr 2024') +GO + +SELECT CONVERT(DATE, '24Apr, 2024') +GO + +SELECT CONVERT(DATE, '24Apr2024') +GO + +SELECT CONVERT(DATE, '4Apr, 2024') +GO + +SELECT CONVERT(DATE, '4Apr2024') +GO + +SELECT CONVERT(DATE, 'Apr, 2024') +GO + +SELECT CONVERT(DATE, 'Apr2024') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATE, N'24 محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'24 محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'4 محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'4 محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'24محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'24محرم2024', 130) +GO + +SELECT CONVERT(DATE, N'4محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'4محرم2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'محرم2024', 130) +GO + +--- dd mon[,][yy]yy +SELECT CONVERT(DATE, '12 Apr, 2024') +GO + +SELECT CONVERT(DATE, '12 Apr 2024') +GO + +SELECT CONVERT(DATE, '12 Apr, 24') +GO + +SELECT CONVERT(DATE, '12 Apr 24') +GO + +SELECT CONVERT(DATE, '12 Apr, 4') +GO + +SELECT CONVERT(DATE, '12 Apr 4') +GO + +SELECT CONVERT(DATE, '12 Apr,') +GO + +SELECT CONVERT(DATE, '12 Apr') +GO + +SELECT CONVERT(DATE, '12Apr, 2024') +GO + +SELECT CONVERT(DATE, '12Apr2024') +GO + +SELECT CONVERT(DATE, '12Apr, 24') +GO + +SELECT CONVERT(DATE, '12Apr24') +GO + +SELECT CONVERT(DATE, '12Apr, 4') +GO + +SELECT CONVERT(DATE, '12Apr4') +GO + +SELECT CONVERT(DATE, '12Apr,') +GO + +SELECT CONVERT(DATE, '12Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATE, N'12 محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم 2024', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم, 24', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم 24', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم, 4', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم 4', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم,', 130) +GO + +SELECT CONVERT(DATE, N'12 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12محرم, 2024', 130) +GO + +SELECT CONVERT(DATE, N'12محرم2024', 130) +GO + +SELECT CONVERT(DATE, N'12محرم, 24', 130) +GO + +SELECT CONVERT(DATE, N'12محرم24', 130) +GO + +SELECT CONVERT(DATE, N'12محرم, 4', 130) +GO + +SELECT CONVERT(DATE, N'12محرم4', 130) +GO + +SELECT CONVERT(DATE, N'12محرم,', 130) +GO + +SELECT CONVERT(DATE, N'12محرم', 130) +GO + +--- dd [yy]yy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO + +SELECT CONVERT(DATE, '12 24 Apr') +GO + +SELECT CONVERT(DATE, '12 2024Apr') +GO + +SELECT CONVERT(DATE, '12 24Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 24 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 24محرم', 130) +GO + +--- [dd] yyyy mon +SELECT CONVERT(DATE, '12 2024 Apr') +GO + +SELECT CONVERT(DATE, '2 2024 Apr') +GO + +SELECT CONVERT(DATE, '2024 Apr') +GO + +SELECT CONVERT(DATE, '12 2024Apr') +GO + +SELECT CONVERT(DATE, '2 2024Apr') +GO + +SELECT CONVERT(DATE, '2024Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'12 2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2 2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'12 2024محرم', 130) +GO + +SELECT CONVERT(DATE, N'2 2024محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO + +--- yyyy mon [dd] +SELECT CONVERT(DATE, '2024 Apr 12') +GO + +SELECT CONVERT(DATE, '2024 Apr 2') +GO + +SELECT CONVERT(DATE, '2024 Apr') +GO + +SELECT CONVERT(DATE, '2024Apr12') +GO + +SELECT CONVERT(DATE, '2024Apr2') +GO + +SELECT CONVERT(DATE, '2024Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 محرم 12', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم 2', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم12', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم2', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO + +--- yyyy [dd] mon +SELECT CONVERT(DATE, '2024 12 Apr') +GO + +SELECT CONVERT(DATE, '2024 2 Apr') +GO + +SELECT CONVERT(DATE, '2024 Apr') +GO + +SELECT CONVERT(DATE, '2024 12Apr') +GO + +SELECT CONVERT(DATE, '2024 2Apr') +GO + +SELECT CONVERT(DATE, '2024Apr') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATE, N'2024 12 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 2 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 12محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024 2محرم', 130) +GO + +SELECT CONVERT(DATE, N'2024محرم', 130) +GO + +-- ISO 8601 +SELECT CONVERT(DATE, '2023-11-27') +GO + +SELECT CONVERT(DATE, '2023-2-29') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-1-22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-2T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T3:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:4:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:1.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.12345678') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123456789') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.1234567891') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.15') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123-11:11') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123Z') +GO + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATE, '2022-10-22T13 :34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10 -22T13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22 T 13:34:12.123') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 Z') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.123 -11:11') +GO + +-- -- rounding +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999995') +GO + +SELECT CONVERT(DATE, '2022-10-22T13:34:12.99999994') +GO + +-- DATE with typmod +SELECT CONVERT(DATE(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATE(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATE(3), '01/01/98 23:59:59.123') +GO + +-- Unseparated +SELECT CONVERT(DATE, '20240129') +GO + +SELECT CONVERT(DATE, '20790606') +GO + +SELECT CONVERT(DATE, '20790607') +GO + +SELECT CONVERT(DATE, '240129') +GO + +SELECT CONVERT(DATE, '241329') +GO + +SELECT CONVERT(DATE, '2001') +GO + +SELECT CONVERT(DATE, '0001') +GO + +SELECT CONVERT(DATE, '1753') +GO + +SELECT CONVERT(DATE, '1900') +GO + +-- for styles 130 and 131, the DATE ranges (for example, number of days in a month) are different compared to other styles +SELECT CONVERT(DATE, '20231229', 130) +GO + +SELECT CONVERT(DATE, '20231230', 130) +GO + +SELECT CONVERT(DATE, '20231129', 130) +GO + +SELECT CONVERT(DATE, '20231130', 130) +GO + +SELECT CONVERT(DATE, '20231229', 131) +GO + +SELECT CONVERT(DATE, '20231230', 131) +GO + +SELECT CONVERT(DATE, '20231129', 131) +GO + +SELECT CONVERT(DATE, '20231130', 131) +GO + +-- -- hijri leap year only contains 29 days in 12th month (for style 130 and 131) +SELECT CONVERT(DATE, '20241230', 130) +GO + +SELECT CONVERT(DATE, '20241230', 131) +GO + +SELECT CONVERT(DATE, '20241229', 130) +GO + +SELECT CONVERT(DATE, '20241229', 131) +GO + +-- -- invalid syntax +SELECT CONVERT(DATE, '0') +GO + +SELECT CONVERT(DATE, '1') +GO + +SELECT CONVERT(DATE, '11') +GO + +SELECT CONVERT(DATE, '111') +GO + +SELECT CONVERT(DATE, '11111') +GO + +SELECT CONVERT(DATE, '1111111') +GO + +-- W3C XML format +SELECT CONVERT(DATE, '2024-04-22-05:12') +GO + +SELECT CONVERT(DATE, '2024-04-22+05:12') +GO + +SELECT CONVERT(DATE, '2024-04-22-14:00') +GO + +SELECT CONVERT(DATE, '2024-04-22+14:00') +GO + +SELECT CONVERT(DATE, '2024-04-22-14:10') +GO + +SELECT CONVERT(DATE, '2024-04-22+14:10') +GO + +SELECT CONVERT(DATE, '2024-04-22Z') +GO + +SELECT CONVERT(DATE, '24-04-22Z') +GO + +SELECT CONVERT(DATE, '2024-4-22Z') +GO + +SELECT CONVERT(DATE, '2024-04-2Z') +GO + +-- hijri +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(DATE, '22/12/1440 1:39:17.090PM', 131) +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(DATE, '02/12/21', 1) +GO + +SELECT CONVERT(DATE, '21.02.12', 2) +GO + +SELECT CONVERT(DATE, '12/02/21', 3) +GO + +SELECT CONVERT(DATE, '12.02.21', 4) +GO + +SELECT CONVERT(DATE, '12-02-21', 5) +GO + +SELECT CONVERT(DATE, '12 Apr 21', 6) +GO + +SELECT CONVERT(DATE, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(DATE, '10:13:14', 8) +GO + +SELECT CONVERT(DATE, '10:13:14', 24) +GO + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(DATE, '02-12-21', 10) +GO + +SELECT CONVERT(DATE, '21/02/12', 11) +GO + +SELECT CONVERT(DATE, '210212', 12) +GO + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(DATE, '15:13:14:123', 14) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(DATE, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(DATE, '2021-02-12', 23) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(DATE, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(DATE, '02/12/2021', 101) +GO + +SELECT CONVERT(DATE, '2021.02.12', 102) +GO + +SELECT CONVERT(DATE, '12/02/2021', 103) +GO + +SELECT CONVERT(DATE, '12.02.2021', 104) +GO + +SELECT CONVERT(DATE, '12-02-2021', 105) +GO + +SELECT CONVERT(DATE, '12 Apr 2021', 106) +GO + +SELECT CONVERT(DATE, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(DATE, '10:13:14', 108) +GO + +SELECT CONVERT(DATE, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(DATE, '02-12-2021', 110) +GO + +SELECT CONVERT(DATE, '2021/02/12', 111) +GO + +SELECT CONVERT(DATE, '20210212', 112) +GO + +SELECT CONVERT(DATE, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(DATE, '15:13:14:123', 114) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(DATE, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(DATE, '2021-02-12T15:13:14.123', 127) +GO + +-- month in hijri is only supported for conversion to datetime and smalldatetime +SELECT CONVERT(DATE, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATE, N'22 April 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATE, '12/02/2021 15:13:14:123 PM', 131) +GO + +-- -- misc +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATE, '2020') +GO + +SELECT CONVERT(DATE, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(DATE, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATE, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATE, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(DATE, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(DATE, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(DATE, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(DATE,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATE, '2020') +GO + +SELECT CONVERT(DATE, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATE, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(DATE, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATE, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_date_v1 +GO +EXEC test_conv_string_to_date_p1 +GO +SELECT test_conv_string_to_date_f1() +GO + +SELECT * FROM test_conv_string_to_date_v2 +GO +EXEC test_conv_string_to_date_p2 +GO +SELECT test_conv_string_to_date_f2() +GO + +SELECT * FROM test_conv_string_to_date_v3 +GO +EXEC test_conv_string_to_date_p3 +GO +SELECT test_conv_string_to_date_f3() +GO + +SELECT * FROM test_conv_string_to_date_v4 +GO +EXEC test_conv_string_to_date_p4 +GO +SELECT test_conv_string_to_date_f4() +GO + +SELECT * FROM test_conv_string_to_date_v5 +GO +EXEC test_conv_string_to_date_p5 +GO +SELECT test_conv_string_to_date_f5() +GO + +SELECT * FROM test_conv_string_to_date_v6 +GO +EXEC test_conv_string_to_date_p6 +GO +SELECT test_conv_string_to_date_f6() +GO + +SELECT * FROM test_conv_string_to_date_v7 +GO +EXEC test_conv_string_to_date_p7 +GO +SELECT test_conv_string_to_date_f7() +GO + +SELECT * FROM test_conv_string_to_date_v8 +GO +EXEC test_conv_string_to_date_p8 +GO +SELECT test_conv_string_to_date_f8() +GO + +SELECT * FROM test_conv_string_to_date_v9 +GO +EXEC test_conv_string_to_date_p9 +GO +SELECT test_conv_string_to_date_f9() +GO + +SELECT * FROM test_conv_string_to_date_v10 +GO + +SELECT * FROM test_conv_string_to_date_v11 +GO + +SELECT * FROM test_conv_string_to_date_v12 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-cleanup.sql new file mode 100644 index 0000000000..eee79e360d --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-cleanup.sql @@ -0,0 +1,68 @@ +DROP VIEW test_conv_string_to_datetime_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime_p1 +GO +DROP FUNCTION test_conv_string_to_datetime_f1() +GO + +DROP VIEW test_conv_string_to_datetime_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime_p2 +GO +DROP FUNCTION test_conv_string_to_datetime_f2() +GO + +DROP VIEW test_conv_string_to_datetime_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime_p3 +GO +DROP FUNCTION test_conv_string_to_datetime_f3() +GO + +DROP VIEW test_conv_string_to_datetime_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime_p4 +GO +DROP FUNCTION test_conv_string_to_datetime_f4() +GO + +DROP VIEW test_conv_string_to_datetime_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime_p5 +GO +DROP FUNCTION test_conv_string_to_datetime_f5() +GO + +DROP VIEW test_conv_string_to_datetime_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime_p6 +GO +DROP FUNCTION test_conv_string_to_datetime_f6() +GO + +DROP VIEW test_conv_string_to_datetime_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime_p7 +GO +DROP FUNCTION test_conv_string_to_datetime_f7() +GO + +DROP VIEW test_conv_string_to_datetime_v8 +GO +DROP PROCEDURE test_conv_string_to_datetime_p8 +GO +DROP FUNCTION test_conv_string_to_datetime_f8() +GO + +DROP VIEW test_conv_string_to_datetime_v9 +GO +DROP PROCEDURE test_conv_string_to_datetime_p9 +GO +DROP FUNCTION test_conv_string_to_datetime_f9() +GO + +DROP VIEW test_conv_string_to_datetime_v10 +GO + +DROP VIEW test_conv_string_to_datetime_v11 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-prepare.sql new file mode 100644 index 0000000000..7194d7f94d --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-prepare.sql @@ -0,0 +1,104 @@ +CREATE VIEW test_conv_string_to_datetime_v1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f1() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f2() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f3() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f4() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f5() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f6() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f7() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f8() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f9() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v10 as (SELECT CONVERT(datetime, '20')); +GO + +CREATE VIEW test_conv_string_to_datetime_v11 as (SELECT CONVERT(datetime, CAST('20' AS INTEGER))); +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-verify.sql new file mode 100644 index 0000000000..fa376e8d09 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime-before-14_6-vu-verify.sql @@ -0,0 +1,1407 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIME, '') +GO + +SELECT CONVERT(DATETIME, '', 130) +GO + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATETIME, '3-2-4 14:30') +GO + +SELECT CONVERT(DATETIME, '3-12-4 14:30') +GO + +SELECT CONVERT(DATETIME, '3-12-24 14:30') +GO + +SELECT CONVERT(DATETIME, '3-12-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '11-12-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3 - 12 - 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3.2.4 14:30') +GO + +SELECT CONVERT(DATETIME, '3.12.4 14:30') +GO + +SELECT CONVERT(DATETIME, '3.12.24 14:30') +GO + +SELECT CONVERT(DATETIME, '3.12.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '11.12.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3 . 12 . 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3/2/4 14:30') +GO + +SELECT CONVERT(DATETIME, '3/12/4 14:30') +GO + +SELECT CONVERT(DATETIME, '3/12/24 14:30') +GO + +SELECT CONVERT(DATETIME, '3/12/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '11/12/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3 / 12 / 2024 14:30') +GO + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATETIME, '3-4-2 14:30') +GO + +SELECT CONVERT(DATETIME, '3-4-12 14:30') +GO + +SELECT CONVERT(DATETIME, '3-24-12 14:30') +GO + +SELECT CONVERT(DATETIME, '3-2024-12 14:30') +GO + +SELECT CONVERT(DATETIME, '11-2024-12 14:30') +GO + +SELECT CONVERT(DATETIME, '3 - 2024 - 12 14:30') +GO + +SELECT CONVERT(DATETIME, '3.4.2 14:30') +GO + +SELECT CONVERT(DATETIME, '3.4.12 14:30') +GO + +SELECT CONVERT(DATETIME, '3.24.12 14:30') +GO + +SELECT CONVERT(DATETIME, '3.2024.12 14:30') +GO + +SELECT CONVERT(DATETIME, '11.2024.12 14:30') +GO + +SELECT CONVERT(DATETIME, '3 . 2024 . 12 14:30') +GO + +SELECT CONVERT(DATETIME, '3/4/2 14:30') +GO + +SELECT CONVERT(DATETIME, '3/4/12 14:30') +GO + +SELECT CONVERT(DATETIME, '3/24/12 14:30') +GO + +SELECT CONVERT(DATETIME, '3/2024/12 14:30') +GO + +SELECT CONVERT(DATETIME, '11/2024/12 14:30') +GO + +SELECT CONVERT(DATETIME, '3 / 2024 / 12 14:30') +GO + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATETIME, '2-3-4 14:30') +GO + +SELECT CONVERT(DATETIME, '12-3-4 14:30') +GO + +SELECT CONVERT(DATETIME, '12-3-24 14:30') +GO + +SELECT CONVERT(DATETIME, '12-3-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12-11-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 - 3 - 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '2.3.4 14:30') +GO + +SELECT CONVERT(DATETIME, '12.3.4 14:30') +GO + +SELECT CONVERT(DATETIME, '12.3.24 14:30') +GO + +SELECT CONVERT(DATETIME, '12.3.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12.11.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 . 3 . 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '2/3/4 14:30') +GO + +SELECT CONVERT(DATETIME, '12/3/4 14:30') +GO + +SELECT CONVERT(DATETIME, '12/3/24 14:30') +GO + +SELECT CONVERT(DATETIME, '12/3/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12/11/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 / 3 / 2024 14:30') +GO + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATETIME, '2-4-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-4-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-24-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-2024-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-2024-11 14:30') +GO + +SELECT CONVERT(DATETIME, '12 - 2024 - 3 14:30') +GO + +SELECT CONVERT(DATETIME, '2.4.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.4.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.24.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.2024.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.2024.11 14:30') +GO + +SELECT CONVERT(DATETIME, '12 . 2024 . 3 14:30') +GO + +SELECT CONVERT(DATETIME, '2/4/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/4/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/24/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/2024/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/2024/11 14:30') +GO + +SELECT CONVERT(DATETIME, '12 / 2024 / 3 14:30') +GO + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATETIME, '4-3-2 14:30') +GO + +SELECT CONVERT(DATETIME, '4-3-12 14:30') +GO + +SELECT CONVERT(DATETIME, '24-3-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024-3-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024-11-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 - 3 - 12 14:30') +GO + +SELECT CONVERT(DATETIME, '4.3.2 14:30') +GO + +SELECT CONVERT(DATETIME, '4.3.12 14:30') +GO + +SELECT CONVERT(DATETIME, '24.3.12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.3.12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.11.12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 . 3 . 12 14:30') +GO + +SELECT CONVERT(DATETIME, '4/3/2 14:30') +GO + +SELECT CONVERT(DATETIME, '4/3/12 14:30') +GO + +SELECT CONVERT(DATETIME, '24/3/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024/3/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024/11/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 / 3 / 12 14:30') +GO + +-- combination of different seperator also works for DATETIME +SELECT CONVERT(DATETIME, '2024/11-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024-11/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.11/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.11-12 14:30') +GO + +-- invalid syntax +SELECT CONVERT(DATETIME, '3 12 2024') +GO + +SELECT CONVERT(DATETIME, '3#12#2024') +GO + +-- cut off year +SELECT CONVERT(DATETIME, '11-12-49') +GO + +SELECT CONVERT(DATETIME, '11-12-50') +GO + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '03-22-2024') +GO + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '22-03-2024') +GO + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '2024-03-22') +GO + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '03-2024-22') +GO + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '22-2024-03') +GO + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATETIME, Hence following query should throw error +SELECT CONVERT(DATETIME, '2-3-4') +GO + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATETIME, '2024-22-03') +GO + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATETIME, 'Apr 12,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2000 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATETIME, 'Apr 12, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1 14:30', 130) +GO + +--- mon yyyy [dd] +SELECT CONVERT(DATETIME, 'Apr 2024 22 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2024 2 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 22 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 2 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 2024 22 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2024 2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 22 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATETIME, '24 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '24 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '24Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '24Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATETIME, N'24 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'24 محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4 محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'24محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'24محرم2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4محرم2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO + +--- dd mon[,][yy]yy +SELECT CONVERT(DATETIME, '12 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr, 24 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 24 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr, 4 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 4 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr, 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 24 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr24 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 4 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr4 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATETIME, N'12 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم 14:30', 130) +GO + +--- dd [yy]yy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 24 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 24Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 24 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 24محرم 14:30', 130) +GO + +--- [dd] yyyy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2 2024Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2 2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2 2024محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO + +--- yyyy mon [dd] +SELECT CONVERT(DATETIME, '2024 Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 2 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr2 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 محرم 12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO + +--- yyyy [dd] mon +SELECT CONVERT(DATETIME, '2024 12 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 2 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 12Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 2Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 12 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 2 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 12محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 2محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO + +-- ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-1-22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-2T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T3:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:4:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:1.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.12') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1234') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.15') +GO + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13 :34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10 -22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22 T 13:34:12.123') +GO + +-- Unseparated +SELECT CONVERT(DATETIME, '20240129') +GO + +SELECT CONVERT(DATETIME, '20241329') +GO + +SELECT CONVERT(DATETIME, '240129') +GO + +SELECT CONVERT(DATETIME, '241329') +GO + +SELECT CONVERT(DATETIME, '2001') +GO + +SELECT CONVERT(DATETIME, '0001') +GO + +SELECT CONVERT(DATETIME, '20240129 03:00:00') +GO + +SELECT CONVERT(DATETIME, '20241329 03:00:00') +GO + +SELECT CONVERT(DATETIME, '240129 03:00') +GO + +SELECT CONVERT(DATETIME, '241329 03:00') +GO + +SELECT CONVERT(DATETIME, '2001 03:00:00.123') +GO + +SELECT CONVERT(DATETIME, '0001 03:00:00.421') +GO + +-- -- invalid syntax +SELECT CONVERT(DATETIME, '0') +GO + +SELECT CONVERT(DATETIME, '1') +GO + +SELECT CONVERT(DATETIME, '11') +GO + +SELECT CONVERT(DATETIME, '111') +GO + +SELECT CONVERT(DATETIME, '11111') +GO + +SELECT CONVERT(DATETIME, '1111111') +GO + +-- should return default DATETIME +SELECT CONVERT(DATETIME, '16:23:51') +GO + +SELECT CONVERT(DATETIME, '4:12:12:123') +GO + +SELECT CONVERT(DATETIME, '4:12:12:1234') +GO + +SELECT CONVERT(DATETIME, '4:12:12.1234') +GO + +-- hijri +SELECT CONVERT(DATETIME, '20231229', 130) +GO + +SELECT CONVERT(DATETIME, '20231230', 130) +GO + +SELECT CONVERT(DATETIME, '20231129', 130) +GO + +SELECT CONVERT(DATETIME, '20231130', 130) +GO + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 131) +GO + +-- -- hijri leap year +SELECT CONVERT(DATETIME, '20241230', 130) +GO + +-- rounding of DATETIME +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.999') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.998') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.997') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.996') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.995') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.994') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.993') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.992') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.991') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.990') +GO + +-- DATETIME with typmod +SELECT CONVERT(DATETIME(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME(3), '01/01/98 23:59:59.123') +GO + +-- boundary tests +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.999') +GO + +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.998') +GO + +-- -- out of bound values +SELECT CONVERT(DATETIME,'2022-10-00 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'0000-10-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'2023-00-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'0000-00-00 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'1742-10-01 23:59:59.990') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(DATETIME, '02/12/21', 1) +GO + +SELECT CONVERT(DATETIME, '21.02.12', 2) +GO + +SELECT CONVERT(DATETIME, '12/02/21', 3) +GO + +SELECT CONVERT(DATETIME, '12.02.21', 4) +GO + +SELECT CONVERT(DATETIME, '12-02-21', 5) +GO + +SELECT CONVERT(DATETIME, '12 Apr 21', 6) +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(DATETIME, '10:13:14', 8) +GO + +SELECT CONVERT(DATETIME, '10:13:14', 24) +GO + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(DATETIME, '02-12-21', 10) +GO + +SELECT CONVERT(DATETIME, '21/02/12', 11) +GO + +SELECT CONVERT(DATETIME, '210212', 12) +GO + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(DATETIME, '15:13:14:123', 14) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(DATETIME, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(DATETIME, '2021-02-12', 23) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(DATETIME, '02/12/2021', 101) +GO + +SELECT CONVERT(DATETIME, '2021.02.12', 102) +GO + +SELECT CONVERT(DATETIME, '12/02/2021', 103) +GO + +SELECT CONVERT(DATETIME, '12.02.2021', 104) +GO + +SELECT CONVERT(DATETIME, '12-02-2021', 105) +GO + +SELECT CONVERT(DATETIME, '12 Apr 2021', 106) +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(DATETIME, '10:13:14', 108) +GO + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(DATETIME, '02-12-2021', 110) +GO + +SELECT CONVERT(DATETIME, '2021/02/12', 111) +GO + +SELECT CONVERT(DATETIME, '20210212', 112) +GO + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(DATETIME, '15:13:14:123', 114) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME, '12/02/2021 15:13:14:123 PM', 131) +GO + +--- misc +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME, '2020') +GO + +SELECT CONVERT(DATETIME, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(DATETIME, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(DATETIME, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(DATETIME, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME, '2020') +GO + +SELECT CONVERT(DATETIME, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATETIME, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime_v1 +GO +EXEC test_conv_string_to_datetime_p1 +GO +SELECT test_conv_string_to_datetime_f1() +GO + +SELECT * FROM test_conv_string_to_datetime_v2 +GO +EXEC test_conv_string_to_datetime_p2 +GO +SELECT test_conv_string_to_datetime_f2() +GO + +SELECT * FROM test_conv_string_to_datetime_v3 +GO +EXEC test_conv_string_to_datetime_p3 +GO +SELECT test_conv_string_to_datetime_f3() +GO + +SELECT * FROM test_conv_string_to_datetime_v4 +GO +EXEC test_conv_string_to_datetime_p4 +GO +SELECT test_conv_string_to_datetime_f4() +GO + +SELECT * FROM test_conv_string_to_datetime_v5 +GO +EXEC test_conv_string_to_datetime_p5 +GO +SELECT test_conv_string_to_datetime_f5() +GO + +SELECT * FROM test_conv_string_to_datetime_v6 +GO +EXEC test_conv_string_to_datetime_p6 +GO +SELECT test_conv_string_to_datetime_f6() +GO + +SELECT * FROM test_conv_string_to_datetime_v7 +GO +EXEC test_conv_string_to_datetime_p7 +GO +SELECT test_conv_string_to_datetime_f7() +GO + +SELECT * FROM test_conv_string_to_datetime_v8 +GO +EXEC test_conv_string_to_datetime_p8 +GO +SELECT test_conv_string_to_datetime_f8() +GO + +SELECT * FROM test_conv_string_to_datetime_v9 +GO +EXEC test_conv_string_to_datetime_p9 +GO +SELECT test_conv_string_to_datetime_f9() +GO + +SELECT * FROM test_conv_string_to_datetime_v10 +GO + +SELECT * FROM test_conv_string_to_datetime_v11 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-cleanup.sql new file mode 100644 index 0000000000..eee79e360d --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-cleanup.sql @@ -0,0 +1,68 @@ +DROP VIEW test_conv_string_to_datetime_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime_p1 +GO +DROP FUNCTION test_conv_string_to_datetime_f1() +GO + +DROP VIEW test_conv_string_to_datetime_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime_p2 +GO +DROP FUNCTION test_conv_string_to_datetime_f2() +GO + +DROP VIEW test_conv_string_to_datetime_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime_p3 +GO +DROP FUNCTION test_conv_string_to_datetime_f3() +GO + +DROP VIEW test_conv_string_to_datetime_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime_p4 +GO +DROP FUNCTION test_conv_string_to_datetime_f4() +GO + +DROP VIEW test_conv_string_to_datetime_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime_p5 +GO +DROP FUNCTION test_conv_string_to_datetime_f5() +GO + +DROP VIEW test_conv_string_to_datetime_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime_p6 +GO +DROP FUNCTION test_conv_string_to_datetime_f6() +GO + +DROP VIEW test_conv_string_to_datetime_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime_p7 +GO +DROP FUNCTION test_conv_string_to_datetime_f7() +GO + +DROP VIEW test_conv_string_to_datetime_v8 +GO +DROP PROCEDURE test_conv_string_to_datetime_p8 +GO +DROP FUNCTION test_conv_string_to_datetime_f8() +GO + +DROP VIEW test_conv_string_to_datetime_v9 +GO +DROP PROCEDURE test_conv_string_to_datetime_p9 +GO +DROP FUNCTION test_conv_string_to_datetime_f9() +GO + +DROP VIEW test_conv_string_to_datetime_v10 +GO + +DROP VIEW test_conv_string_to_datetime_v11 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-prepare.sql new file mode 100644 index 0000000000..7194d7f94d --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-prepare.sql @@ -0,0 +1,104 @@ +CREATE VIEW test_conv_string_to_datetime_v1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f1() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f2() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f3() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f4() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f5() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f6() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f7() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f8() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f9() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v10 as (SELECT CONVERT(datetime, '20')); +GO + +CREATE VIEW test_conv_string_to_datetime_v11 as (SELECT CONVERT(datetime, CAST('20' AS INTEGER))); +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-verify.sql new file mode 100644 index 0000000000..fa376e8d09 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime-before-17_3-vu-verify.sql @@ -0,0 +1,1407 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIME, '') +GO + +SELECT CONVERT(DATETIME, '', 130) +GO + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATETIME, '3-2-4 14:30') +GO + +SELECT CONVERT(DATETIME, '3-12-4 14:30') +GO + +SELECT CONVERT(DATETIME, '3-12-24 14:30') +GO + +SELECT CONVERT(DATETIME, '3-12-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '11-12-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3 - 12 - 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3.2.4 14:30') +GO + +SELECT CONVERT(DATETIME, '3.12.4 14:30') +GO + +SELECT CONVERT(DATETIME, '3.12.24 14:30') +GO + +SELECT CONVERT(DATETIME, '3.12.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '11.12.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3 . 12 . 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3/2/4 14:30') +GO + +SELECT CONVERT(DATETIME, '3/12/4 14:30') +GO + +SELECT CONVERT(DATETIME, '3/12/24 14:30') +GO + +SELECT CONVERT(DATETIME, '3/12/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '11/12/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3 / 12 / 2024 14:30') +GO + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATETIME, '3-4-2 14:30') +GO + +SELECT CONVERT(DATETIME, '3-4-12 14:30') +GO + +SELECT CONVERT(DATETIME, '3-24-12 14:30') +GO + +SELECT CONVERT(DATETIME, '3-2024-12 14:30') +GO + +SELECT CONVERT(DATETIME, '11-2024-12 14:30') +GO + +SELECT CONVERT(DATETIME, '3 - 2024 - 12 14:30') +GO + +SELECT CONVERT(DATETIME, '3.4.2 14:30') +GO + +SELECT CONVERT(DATETIME, '3.4.12 14:30') +GO + +SELECT CONVERT(DATETIME, '3.24.12 14:30') +GO + +SELECT CONVERT(DATETIME, '3.2024.12 14:30') +GO + +SELECT CONVERT(DATETIME, '11.2024.12 14:30') +GO + +SELECT CONVERT(DATETIME, '3 . 2024 . 12 14:30') +GO + +SELECT CONVERT(DATETIME, '3/4/2 14:30') +GO + +SELECT CONVERT(DATETIME, '3/4/12 14:30') +GO + +SELECT CONVERT(DATETIME, '3/24/12 14:30') +GO + +SELECT CONVERT(DATETIME, '3/2024/12 14:30') +GO + +SELECT CONVERT(DATETIME, '11/2024/12 14:30') +GO + +SELECT CONVERT(DATETIME, '3 / 2024 / 12 14:30') +GO + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATETIME, '2-3-4 14:30') +GO + +SELECT CONVERT(DATETIME, '12-3-4 14:30') +GO + +SELECT CONVERT(DATETIME, '12-3-24 14:30') +GO + +SELECT CONVERT(DATETIME, '12-3-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12-11-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 - 3 - 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '2.3.4 14:30') +GO + +SELECT CONVERT(DATETIME, '12.3.4 14:30') +GO + +SELECT CONVERT(DATETIME, '12.3.24 14:30') +GO + +SELECT CONVERT(DATETIME, '12.3.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12.11.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 . 3 . 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '2/3/4 14:30') +GO + +SELECT CONVERT(DATETIME, '12/3/4 14:30') +GO + +SELECT CONVERT(DATETIME, '12/3/24 14:30') +GO + +SELECT CONVERT(DATETIME, '12/3/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12/11/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 / 3 / 2024 14:30') +GO + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATETIME, '2-4-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-4-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-24-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-2024-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-2024-11 14:30') +GO + +SELECT CONVERT(DATETIME, '12 - 2024 - 3 14:30') +GO + +SELECT CONVERT(DATETIME, '2.4.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.4.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.24.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.2024.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.2024.11 14:30') +GO + +SELECT CONVERT(DATETIME, '12 . 2024 . 3 14:30') +GO + +SELECT CONVERT(DATETIME, '2/4/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/4/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/24/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/2024/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/2024/11 14:30') +GO + +SELECT CONVERT(DATETIME, '12 / 2024 / 3 14:30') +GO + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATETIME, '4-3-2 14:30') +GO + +SELECT CONVERT(DATETIME, '4-3-12 14:30') +GO + +SELECT CONVERT(DATETIME, '24-3-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024-3-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024-11-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 - 3 - 12 14:30') +GO + +SELECT CONVERT(DATETIME, '4.3.2 14:30') +GO + +SELECT CONVERT(DATETIME, '4.3.12 14:30') +GO + +SELECT CONVERT(DATETIME, '24.3.12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.3.12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.11.12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 . 3 . 12 14:30') +GO + +SELECT CONVERT(DATETIME, '4/3/2 14:30') +GO + +SELECT CONVERT(DATETIME, '4/3/12 14:30') +GO + +SELECT CONVERT(DATETIME, '24/3/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024/3/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024/11/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 / 3 / 12 14:30') +GO + +-- combination of different seperator also works for DATETIME +SELECT CONVERT(DATETIME, '2024/11-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024-11/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.11/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.11-12 14:30') +GO + +-- invalid syntax +SELECT CONVERT(DATETIME, '3 12 2024') +GO + +SELECT CONVERT(DATETIME, '3#12#2024') +GO + +-- cut off year +SELECT CONVERT(DATETIME, '11-12-49') +GO + +SELECT CONVERT(DATETIME, '11-12-50') +GO + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '03-22-2024') +GO + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '22-03-2024') +GO + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '2024-03-22') +GO + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '03-2024-22') +GO + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '22-2024-03') +GO + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATETIME, Hence following query should throw error +SELECT CONVERT(DATETIME, '2-3-4') +GO + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATETIME, '2024-22-03') +GO + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATETIME, 'Apr 12,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2000 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATETIME, 'Apr 12, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1 14:30', 130) +GO + +--- mon yyyy [dd] +SELECT CONVERT(DATETIME, 'Apr 2024 22 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2024 2 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 22 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 2 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 2024 22 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2024 2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 22 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATETIME, '24 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '24 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '24Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '24Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATETIME, N'24 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'24 محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4 محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'24محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'24محرم2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4محرم2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO + +--- dd mon[,][yy]yy +SELECT CONVERT(DATETIME, '12 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr, 24 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 24 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr, 4 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 4 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr, 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 24 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr24 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 4 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr4 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATETIME, N'12 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم 14:30', 130) +GO + +--- dd [yy]yy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 24 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 24Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 24 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 24محرم 14:30', 130) +GO + +--- [dd] yyyy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2 2024Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2 2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2 2024محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO + +--- yyyy mon [dd] +SELECT CONVERT(DATETIME, '2024 Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 2 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr2 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 محرم 12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO + +--- yyyy [dd] mon +SELECT CONVERT(DATETIME, '2024 12 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 2 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 12Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 2Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 12 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 2 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 12محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 2محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO + +-- ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-1-22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-2T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T3:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:4:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:1.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.12') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1234') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.15') +GO + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13 :34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10 -22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22 T 13:34:12.123') +GO + +-- Unseparated +SELECT CONVERT(DATETIME, '20240129') +GO + +SELECT CONVERT(DATETIME, '20241329') +GO + +SELECT CONVERT(DATETIME, '240129') +GO + +SELECT CONVERT(DATETIME, '241329') +GO + +SELECT CONVERT(DATETIME, '2001') +GO + +SELECT CONVERT(DATETIME, '0001') +GO + +SELECT CONVERT(DATETIME, '20240129 03:00:00') +GO + +SELECT CONVERT(DATETIME, '20241329 03:00:00') +GO + +SELECT CONVERT(DATETIME, '240129 03:00') +GO + +SELECT CONVERT(DATETIME, '241329 03:00') +GO + +SELECT CONVERT(DATETIME, '2001 03:00:00.123') +GO + +SELECT CONVERT(DATETIME, '0001 03:00:00.421') +GO + +-- -- invalid syntax +SELECT CONVERT(DATETIME, '0') +GO + +SELECT CONVERT(DATETIME, '1') +GO + +SELECT CONVERT(DATETIME, '11') +GO + +SELECT CONVERT(DATETIME, '111') +GO + +SELECT CONVERT(DATETIME, '11111') +GO + +SELECT CONVERT(DATETIME, '1111111') +GO + +-- should return default DATETIME +SELECT CONVERT(DATETIME, '16:23:51') +GO + +SELECT CONVERT(DATETIME, '4:12:12:123') +GO + +SELECT CONVERT(DATETIME, '4:12:12:1234') +GO + +SELECT CONVERT(DATETIME, '4:12:12.1234') +GO + +-- hijri +SELECT CONVERT(DATETIME, '20231229', 130) +GO + +SELECT CONVERT(DATETIME, '20231230', 130) +GO + +SELECT CONVERT(DATETIME, '20231129', 130) +GO + +SELECT CONVERT(DATETIME, '20231130', 130) +GO + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 131) +GO + +-- -- hijri leap year +SELECT CONVERT(DATETIME, '20241230', 130) +GO + +-- rounding of DATETIME +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.999') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.998') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.997') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.996') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.995') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.994') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.993') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.992') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.991') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.990') +GO + +-- DATETIME with typmod +SELECT CONVERT(DATETIME(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME(3), '01/01/98 23:59:59.123') +GO + +-- boundary tests +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.999') +GO + +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.998') +GO + +-- -- out of bound values +SELECT CONVERT(DATETIME,'2022-10-00 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'0000-10-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'2023-00-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'0000-00-00 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'1742-10-01 23:59:59.990') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(DATETIME, '02/12/21', 1) +GO + +SELECT CONVERT(DATETIME, '21.02.12', 2) +GO + +SELECT CONVERT(DATETIME, '12/02/21', 3) +GO + +SELECT CONVERT(DATETIME, '12.02.21', 4) +GO + +SELECT CONVERT(DATETIME, '12-02-21', 5) +GO + +SELECT CONVERT(DATETIME, '12 Apr 21', 6) +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(DATETIME, '10:13:14', 8) +GO + +SELECT CONVERT(DATETIME, '10:13:14', 24) +GO + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(DATETIME, '02-12-21', 10) +GO + +SELECT CONVERT(DATETIME, '21/02/12', 11) +GO + +SELECT CONVERT(DATETIME, '210212', 12) +GO + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(DATETIME, '15:13:14:123', 14) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(DATETIME, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(DATETIME, '2021-02-12', 23) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(DATETIME, '02/12/2021', 101) +GO + +SELECT CONVERT(DATETIME, '2021.02.12', 102) +GO + +SELECT CONVERT(DATETIME, '12/02/2021', 103) +GO + +SELECT CONVERT(DATETIME, '12.02.2021', 104) +GO + +SELECT CONVERT(DATETIME, '12-02-2021', 105) +GO + +SELECT CONVERT(DATETIME, '12 Apr 2021', 106) +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(DATETIME, '10:13:14', 108) +GO + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(DATETIME, '02-12-2021', 110) +GO + +SELECT CONVERT(DATETIME, '2021/02/12', 111) +GO + +SELECT CONVERT(DATETIME, '20210212', 112) +GO + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(DATETIME, '15:13:14:123', 114) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME, '12/02/2021 15:13:14:123 PM', 131) +GO + +--- misc +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME, '2020') +GO + +SELECT CONVERT(DATETIME, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(DATETIME, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(DATETIME, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(DATETIME, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME, '2020') +GO + +SELECT CONVERT(DATETIME, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATETIME, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime_v1 +GO +EXEC test_conv_string_to_datetime_p1 +GO +SELECT test_conv_string_to_datetime_f1() +GO + +SELECT * FROM test_conv_string_to_datetime_v2 +GO +EXEC test_conv_string_to_datetime_p2 +GO +SELECT test_conv_string_to_datetime_f2() +GO + +SELECT * FROM test_conv_string_to_datetime_v3 +GO +EXEC test_conv_string_to_datetime_p3 +GO +SELECT test_conv_string_to_datetime_f3() +GO + +SELECT * FROM test_conv_string_to_datetime_v4 +GO +EXEC test_conv_string_to_datetime_p4 +GO +SELECT test_conv_string_to_datetime_f4() +GO + +SELECT * FROM test_conv_string_to_datetime_v5 +GO +EXEC test_conv_string_to_datetime_p5 +GO +SELECT test_conv_string_to_datetime_f5() +GO + +SELECT * FROM test_conv_string_to_datetime_v6 +GO +EXEC test_conv_string_to_datetime_p6 +GO +SELECT test_conv_string_to_datetime_f6() +GO + +SELECT * FROM test_conv_string_to_datetime_v7 +GO +EXEC test_conv_string_to_datetime_p7 +GO +SELECT test_conv_string_to_datetime_f7() +GO + +SELECT * FROM test_conv_string_to_datetime_v8 +GO +EXEC test_conv_string_to_datetime_p8 +GO +SELECT test_conv_string_to_datetime_f8() +GO + +SELECT * FROM test_conv_string_to_datetime_v9 +GO +EXEC test_conv_string_to_datetime_p9 +GO +SELECT test_conv_string_to_datetime_f9() +GO + +SELECT * FROM test_conv_string_to_datetime_v10 +GO + +SELECT * FROM test_conv_string_to_datetime_v11 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_datetime-vu-cleanup.sql new file mode 100644 index 0000000000..eee79e360d --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime-vu-cleanup.sql @@ -0,0 +1,68 @@ +DROP VIEW test_conv_string_to_datetime_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime_p1 +GO +DROP FUNCTION test_conv_string_to_datetime_f1() +GO + +DROP VIEW test_conv_string_to_datetime_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime_p2 +GO +DROP FUNCTION test_conv_string_to_datetime_f2() +GO + +DROP VIEW test_conv_string_to_datetime_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime_p3 +GO +DROP FUNCTION test_conv_string_to_datetime_f3() +GO + +DROP VIEW test_conv_string_to_datetime_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime_p4 +GO +DROP FUNCTION test_conv_string_to_datetime_f4() +GO + +DROP VIEW test_conv_string_to_datetime_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime_p5 +GO +DROP FUNCTION test_conv_string_to_datetime_f5() +GO + +DROP VIEW test_conv_string_to_datetime_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime_p6 +GO +DROP FUNCTION test_conv_string_to_datetime_f6() +GO + +DROP VIEW test_conv_string_to_datetime_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime_p7 +GO +DROP FUNCTION test_conv_string_to_datetime_f7() +GO + +DROP VIEW test_conv_string_to_datetime_v8 +GO +DROP PROCEDURE test_conv_string_to_datetime_p8 +GO +DROP FUNCTION test_conv_string_to_datetime_f8() +GO + +DROP VIEW test_conv_string_to_datetime_v9 +GO +DROP PROCEDURE test_conv_string_to_datetime_p9 +GO +DROP FUNCTION test_conv_string_to_datetime_f9() +GO + +DROP VIEW test_conv_string_to_datetime_v10 +GO + +DROP VIEW test_conv_string_to_datetime_v11 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_datetime-vu-prepare.sql new file mode 100644 index 0000000000..7194d7f94d --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime-vu-prepare.sql @@ -0,0 +1,104 @@ +CREATE VIEW test_conv_string_to_datetime_v1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p1 as (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f1() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p2 as (SELECT CONVERT(datetime, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f2() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p3 as (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +GO +CREATE FUNCTION test_conv_string_to_datetime_f3() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, '1753-01-01 0:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p4 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f4() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p5 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f5() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p6 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f6() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p7 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f7() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p8 as (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f8() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime_p9 as (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_datetime_f9() +RETURNS datetime AS +BEGIN +RETURN (SELECT CONVERT(datetime, CAST('2017-08-25 13:01:59' AS VARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime_v10 as (SELECT CONVERT(datetime, '20')); +GO + +CREATE VIEW test_conv_string_to_datetime_v11 as (SELECT CONVERT(datetime, CAST('20' AS INTEGER))); +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_datetime-vu-verify.sql new file mode 100644 index 0000000000..bb7c08ac8d --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime-vu-verify.sql @@ -0,0 +1,1408 @@ +-- sla 100000 +-- Empty string, should return default values +SELECT CONVERT(DATETIME, '') +GO + +SELECT CONVERT(DATETIME, '', 130) +GO + +-- -- Numeric: +-- 1 or 2 digit number in a given datetime string literal is considered as either +-- day, month or year based on session dateformat value. +-- [m]m[d]d([y]y|yyyy) +SELECT CONVERT(DATETIME, '3-2-4 14:30') +GO + +SELECT CONVERT(DATETIME, '3-12-4 14:30') +GO + +SELECT CONVERT(DATETIME, '3-12-24 14:30') +GO + +SELECT CONVERT(DATETIME, '3-12-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '11-12-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3 - 12 - 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3.2.4 14:30') +GO + +SELECT CONVERT(DATETIME, '3.12.4 14:30') +GO + +SELECT CONVERT(DATETIME, '3.12.24 14:30') +GO + +SELECT CONVERT(DATETIME, '3.12.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '11.12.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3 . 12 . 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3/2/4 14:30') +GO + +SELECT CONVERT(DATETIME, '3/12/4 14:30') +GO + +SELECT CONVERT(DATETIME, '3/12/24 14:30') +GO + +SELECT CONVERT(DATETIME, '3/12/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '11/12/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '3 / 12 / 2024 14:30') +GO + +-- [m]m([y]y|yyyy)[d]d +SELECT CONVERT(DATETIME, '3-4-2 14:30') +GO + +SELECT CONVERT(DATETIME, '3-4-12 14:30') +GO + +SELECT CONVERT(DATETIME, '3-24-12 14:30') +GO + +SELECT CONVERT(DATETIME, '3-2024-12 14:30') +GO + +SELECT CONVERT(DATETIME, '11-2024-12 14:30') +GO + +SELECT CONVERT(DATETIME, '3 - 2024 - 12 14:30') +GO + +SELECT CONVERT(DATETIME, '3.4.2 14:30') +GO + +SELECT CONVERT(DATETIME, '3.4.12 14:30') +GO + +SELECT CONVERT(DATETIME, '3.24.12 14:30') +GO + +SELECT CONVERT(DATETIME, '3.2024.12 14:30') +GO + +SELECT CONVERT(DATETIME, '11.2024.12 14:30') +GO + +SELECT CONVERT(DATETIME, '3 . 2024 . 12 14:30') +GO + +SELECT CONVERT(DATETIME, '3/4/2 14:30') +GO + +SELECT CONVERT(DATETIME, '3/4/12 14:30') +GO + +SELECT CONVERT(DATETIME, '3/24/12 14:30') +GO + +SELECT CONVERT(DATETIME, '3/2024/12 14:30') +GO + +SELECT CONVERT(DATETIME, '11/2024/12 14:30') +GO + +SELECT CONVERT(DATETIME, '3 / 2024 / 12 14:30') +GO + +-- [d]d[m]m([y]y|yyyy) +SELECT CONVERT(DATETIME, '2-3-4 14:30') +GO + +SELECT CONVERT(DATETIME, '12-3-4 14:30') +GO + +SELECT CONVERT(DATETIME, '12-3-24 14:30') +GO + +SELECT CONVERT(DATETIME, '12-3-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12-11-2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 - 3 - 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '2.3.4 14:30') +GO + +SELECT CONVERT(DATETIME, '12.3.4 14:30') +GO + +SELECT CONVERT(DATETIME, '12.3.24 14:30') +GO + +SELECT CONVERT(DATETIME, '12.3.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12.11.2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 . 3 . 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '2/3/4 14:30') +GO + +SELECT CONVERT(DATETIME, '12/3/4 14:30') +GO + +SELECT CONVERT(DATETIME, '12/3/24 14:30') +GO + +SELECT CONVERT(DATETIME, '12/3/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12/11/2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 / 3 / 2024 14:30') +GO + +-- [d]d([y]y|yyyy)[m]m +SELECT CONVERT(DATETIME, '2-4-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-4-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-24-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-2024-3 14:30') +GO + +SELECT CONVERT(DATETIME, '12-2024-11 14:30') +GO + +SELECT CONVERT(DATETIME, '12 - 2024 - 3 14:30') +GO + +SELECT CONVERT(DATETIME, '2.4.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.4.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.24.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.2024.3 14:30') +GO + +SELECT CONVERT(DATETIME, '12.2024.11 14:30') +GO + +SELECT CONVERT(DATETIME, '12 . 2024 . 3 14:30') +GO + +SELECT CONVERT(DATETIME, '2/4/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/4/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/24/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/2024/3 14:30') +GO + +SELECT CONVERT(DATETIME, '12/2024/11 14:30') +GO + +SELECT CONVERT(DATETIME, '12 / 2024 / 3 14:30') +GO + +-- ([y]y|yyyy)[m]m[d]d +SELECT CONVERT(DATETIME, '4-3-2 14:30') +GO + +SELECT CONVERT(DATETIME, '4-3-12 14:30') +GO + +SELECT CONVERT(DATETIME, '24-3-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024-3-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024-11-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 - 3 - 12 14:30') +GO + +SELECT CONVERT(DATETIME, '4.3.2 14:30') +GO + +SELECT CONVERT(DATETIME, '4.3.12 14:30') +GO + +SELECT CONVERT(DATETIME, '24.3.12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.3.12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.11.12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 . 3 . 12 14:30') +GO + +SELECT CONVERT(DATETIME, '4/3/2 14:30') +GO + +SELECT CONVERT(DATETIME, '4/3/12 14:30') +GO + +SELECT CONVERT(DATETIME, '24/3/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024/3/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024/11/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 / 3 / 12 14:30') +GO + +-- combination of different seperator also works for DATETIME +SELECT CONVERT(DATETIME, '2024/11-12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024-11/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.11/12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024.11-12 14:30') +GO + +-- invalid syntax +SELECT CONVERT(DATETIME, '3 12 2024') +GO + +SELECT CONVERT(DATETIME, '3#12#2024') +GO + +-- cut off year +SELECT CONVERT(DATETIME, '11-12-49') +GO + +SELECT CONVERT(DATETIME, '11-12-50') +GO + +-- Babelfish currently doesn't support setting DATEFORMAT, +-- hence currently session language dateformat is used +SET DATEFORMAT 'MDY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '03-22-2024') +GO + +SET DATEFORMAT 'DMY' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '22-03-2024') +GO + +SET DATEFORMAT 'YMD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '2024-03-22') +GO + +SET DATEFORMAT 'MYD' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '03-2024-22') +GO + +SET DATEFORMAT 'DYM' +GO + +SELECT CONVERT(DATETIME, '2-3-4') +GO + +SELECT CONVERT(DATETIME, '22-2024-03') +GO + +SET DATEFORMAT 'YDM' +GO + +-- YDM DATE format is not supported when converting from this +-- character string format to DATETIME, Hence following query should throw error +SELECT CONVERT(DATETIME, '2-3-4') +GO + +-- For DATE as follows, it will always be treated as YMD DATEFORMAT as YDM is not supported. +SELECT CONVERT(DATETIME, '2024-22-03') +GO + +-- SET DATEFORMAT back to default +SET DATEFORMAT 'MDY' +GO + +-- Alphabetical +--- mon [dd][,] yyyy +SELECT CONVERT(DATETIME, 'Apr 12,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr,2000 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2000 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم ,2000 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2000 14:30', 130) +GO + +--- mon [d]d[,] [yy] +SELECT CONVERT(DATETIME, 'Apr 12, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 1 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr12 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1, 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 24 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1, 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 4 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1, 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr1 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 12, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 1 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم1 14:30', 130) +GO + +--- mon yyyy [dd] +SELECT CONVERT(DATETIME, 'Apr 2024 22 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2024 2 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 22 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 2 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'محرم 2024 22 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2024 2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 22 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO + +--- [dd] mon[,] yyyy +SELECT CONVERT(DATETIME, '24 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '24 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '24Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '24Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '4Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, 'Apr2024 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should +SELECT CONVERT(DATETIME, N'24 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'24 محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4 محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'24محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'24محرم2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'4محرم2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'محرم2024 14:30', 130) +GO + +--- dd mon[,][yy]yy +SELECT CONVERT(DATETIME, '12 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr, 24 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 24 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr, 4 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 4 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr, 14:30') +GO + +SELECT CONVERT(DATETIME, '12 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 24 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr24 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 4 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr4 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr, 14:30') +GO + +SELECT CONVERT(DATETIME, '12Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- also these styles only support DATEFORMAT DMY, hence following queries should work +SELECT CONVERT(DATETIME, N'12 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم2024 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم24 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم4 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم, 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12محرم 14:30', 130) +GO + +--- dd [yy]yy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 24 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 24Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 24 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 24محرم 14:30', 130) +GO + +--- [dd] yyyy mon +SELECT CONVERT(DATETIME, '12 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '12 2024Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2 2024Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'12 2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2 2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'12 2024محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2 2024محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO + +--- yyyy mon [dd] +SELECT CONVERT(DATETIME, '2024 Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 2 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr12 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr2 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 محرم 12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم12 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم2 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO + +--- yyyy [dd] mon +SELECT CONVERT(DATETIME, '2024 12 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 2 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 12Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024 2Apr 14:30') +GO + +SELECT CONVERT(DATETIME, '2024Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format, +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(DATETIME, N'2024 12 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 2 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 12محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024 2محرم 14:30', 130) +GO + +SELECT CONVERT(DATETIME, N'2024محرم 14:30', 130) +GO + +-- ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-1-22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-2T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T3:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:4:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:1.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.12') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.1234') +GO + +SELECT CONVERT(DATETIME, '2022-10-22T13:34:12.15') +GO + +-- -- spaces are not allowed between any two tokens for ISO 8601 +SELECT CONVERT(DATETIME, '2022-10-22T13 :34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10 -22T13:34:12.123') +GO + +SELECT CONVERT(DATETIME, '2022-10-22 T 13:34:12.123') +GO + +-- Unseparated +SELECT CONVERT(DATETIME, '20240129') +GO + +SELECT CONVERT(DATETIME, '20241329') +GO + +SELECT CONVERT(DATETIME, '240129') +GO + +SELECT CONVERT(DATETIME, '241329') +GO + +SELECT CONVERT(DATETIME, '2001') +GO + +SELECT CONVERT(DATETIME, '0001') +GO + +SELECT CONVERT(DATETIME, '20240129 03:00:00') +GO + +SELECT CONVERT(DATETIME, '20241329 03:00:00') +GO + +SELECT CONVERT(DATETIME, '240129 03:00') +GO + +SELECT CONVERT(DATETIME, '241329 03:00') +GO + +SELECT CONVERT(DATETIME, '2001 03:00:00.123') +GO + +SELECT CONVERT(DATETIME, '0001 03:00:00.421') +GO + +-- -- invalid syntax +SELECT CONVERT(DATETIME, '0') +GO + +SELECT CONVERT(DATETIME, '1') +GO + +SELECT CONVERT(DATETIME, '11') +GO + +SELECT CONVERT(DATETIME, '111') +GO + +SELECT CONVERT(DATETIME, '11111') +GO + +SELECT CONVERT(DATETIME, '1111111') +GO + +-- should return default DATETIME +SELECT CONVERT(DATETIME, '16:23:51') +GO + +SELECT CONVERT(DATETIME, '4:12:12:123') +GO + +SELECT CONVERT(DATETIME, '4:12:12:1234') +GO + +SELECT CONVERT(DATETIME, '4:12:12.1234') +GO + +-- hijri +SELECT CONVERT(DATETIME, '20231229', 130) +GO + +SELECT CONVERT(DATETIME, '20231230', 130) +GO + +SELECT CONVERT(DATETIME, '20231129', 130) +GO + +SELECT CONVERT(DATETIME, '20231130', 130) +GO + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(DATETIME, '22/12/1440 1:39:17.090PM', 131) +GO + +-- -- hijri leap year +SELECT CONVERT(DATETIME, '20241230', 130) +GO + +-- rounding of DATETIME +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.999') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.998') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.997') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.996') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.995') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.994') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.993') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.992') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.991') +GO + +SELECT CONVERT(DATETIME, '01/01/98 23:59:59.990') +GO + +-- DATETIME with typmod +SELECT CONVERT(DATETIME(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME(3), '01/01/98 23:59:59.123') +GO + +-- boundary tests +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.999') +GO + +SELECT CONVERT(DATETIME, '9999-12-31 23:59:59.998') +GO + +-- -- out of bound values +SELECT CONVERT(DATETIME,'2022-10-00 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'0000-10-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'2023-00-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'0000-00-00 23:59:59.990') +GO + +SELECT CONVERT(DATETIME,'1742-10-01 23:59:59.990') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(DATETIME, '02/12/21', 1) +GO + +SELECT CONVERT(DATETIME, '21.02.12', 2) +GO + +SELECT CONVERT(DATETIME, '12/02/21', 3) +GO + +SELECT CONVERT(DATETIME, '12.02.21', 4) +GO + +SELECT CONVERT(DATETIME, '12-02-21', 5) +GO + +SELECT CONVERT(DATETIME, '12 Apr 21', 6) +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(DATETIME, '10:13:14', 8) +GO + +SELECT CONVERT(DATETIME, '10:13:14', 24) +GO + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(DATETIME, '02-12-21', 10) +GO + +SELECT CONVERT(DATETIME, '21/02/12', 11) +GO + +SELECT CONVERT(DATETIME, '210212', 12) +GO + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(DATETIME, '15:13:14:123', 14) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(DATETIME, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(DATETIME, '2021-02-12', 23) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(DATETIME, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(DATETIME, '02/12/2021', 101) +GO + +SELECT CONVERT(DATETIME, '2021.02.12', 102) +GO + +SELECT CONVERT(DATETIME, '12/02/2021', 103) +GO + +SELECT CONVERT(DATETIME, '12.02.2021', 104) +GO + +SELECT CONVERT(DATETIME, '12-02-2021', 105) +GO + +SELECT CONVERT(DATETIME, '12 Apr 2021', 106) +GO + +SELECT CONVERT(DATETIME, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(DATETIME, '10:13:14', 108) +GO + +SELECT CONVERT(DATETIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(DATETIME, '02-12-2021', 110) +GO + +SELECT CONVERT(DATETIME, '2021/02/12', 111) +GO + +SELECT CONVERT(DATETIME, '20210212', 112) +GO + +SELECT CONVERT(DATETIME, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(DATETIME, '15:13:14:123', 114) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(DATETIME, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(DATETIME, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(DATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME, '12/02/2021 15:13:14:123 PM', 131) +GO + +--- misc +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME, '2020') +GO + +SELECT CONVERT(DATETIME, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(DATETIME, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(DATETIME, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(DATETIME, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(DATETIME, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(DATETIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME, '2020') +GO + +SELECT CONVERT(DATETIME, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATETIME, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(DATETIME, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime_v1 +GO +EXEC test_conv_string_to_datetime_p1 +GO +SELECT test_conv_string_to_datetime_f1() +GO + +SELECT * FROM test_conv_string_to_datetime_v2 +GO +EXEC test_conv_string_to_datetime_p2 +GO +SELECT test_conv_string_to_datetime_f2() +GO + +SELECT * FROM test_conv_string_to_datetime_v3 +GO +EXEC test_conv_string_to_datetime_p3 +GO +SELECT test_conv_string_to_datetime_f3() +GO + +SELECT * FROM test_conv_string_to_datetime_v4 +GO +EXEC test_conv_string_to_datetime_p4 +GO +SELECT test_conv_string_to_datetime_f4() +GO + +SELECT * FROM test_conv_string_to_datetime_v5 +GO +EXEC test_conv_string_to_datetime_p5 +GO +SELECT test_conv_string_to_datetime_f5() +GO + +SELECT * FROM test_conv_string_to_datetime_v6 +GO +EXEC test_conv_string_to_datetime_p6 +GO +SELECT test_conv_string_to_datetime_f6() +GO + +SELECT * FROM test_conv_string_to_datetime_v7 +GO +EXEC test_conv_string_to_datetime_p7 +GO +SELECT test_conv_string_to_datetime_f7() +GO + +SELECT * FROM test_conv_string_to_datetime_v8 +GO +EXEC test_conv_string_to_datetime_p8 +GO +SELECT test_conv_string_to_datetime_f8() +GO + +SELECT * FROM test_conv_string_to_datetime_v9 +GO +EXEC test_conv_string_to_datetime_p9 +GO +SELECT test_conv_string_to_datetime_f9() +GO + +SELECT * FROM test_conv_string_to_datetime_v10 +GO + +SELECT * FROM test_conv_string_to_datetime_v11 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-cleanup.sql new file mode 100644 index 0000000000..e9e44fd452 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-cleanup.sql @@ -0,0 +1,60 @@ +DROP VIEW test_conv_string_to_datetime2_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p1 +GO +DROP FUNCTION test_conv_string_to_datetime2_f1() +GO + +DROP VIEW test_conv_string_to_datetime2_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2() +GO + +DROP PROCEDURE test_conv_string_to_datetime2_p2_2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2_2() +GO + +DROP VIEW test_conv_string_to_datetime2_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p3 +GO +DROP FUNCTION test_conv_string_to_datetime2_f3() +GO + +DROP VIEW test_conv_string_to_datetime2_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p4 +GO +DROP FUNCTION test_conv_string_to_datetime2_f4() +GO + +DROP VIEW test_conv_string_to_datetime2_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p5 +GO +DROP FUNCTION test_conv_string_to_datetime2_f5() +GO + +DROP VIEW test_conv_string_to_datetime2_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p6 +GO +DROP FUNCTION test_conv_string_to_datetime2_f6() +GO + +DROP VIEW test_conv_string_to_datetime2_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p7 +GO +DROP FUNCTION test_conv_string_to_datetime2_f7() +GO + +DROP VIEW test_conv_string_to_datetime2_v8 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p8 +GO +DROP FUNCTION test_conv_string_to_datetime2_f8() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-prepare.sql new file mode 100644 index 0000000000..19948dc11c --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-prepare.sql @@ -0,0 +1,97 @@ +CREATE VIEW test_conv_string_to_datetime2_v1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f1() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE PROCEDURE test_conv_string_to_datetime2_p2_2 as (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2_2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +END +GO + + +CREATE VIEW test_conv_string_to_datetime2_v3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f3() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f4() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f5() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f6() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f7() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f8() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-verify.sql new file mode 100644 index 0000000000..c9dbfc26b4 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-14_5-vu-verify.sql @@ -0,0 +1,684 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIME2, '') +GO + +SELECT CONVERT(DATETIME2, '', 130) +GO + +-- -- Numeric +SELECT CONVERT(DATETIME2, '3-2-4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3-12-4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3-12-24 14:30') +GO + +SELECT CONVERT(DATETIME2, '3-12-2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 - 12 - 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.2.4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.12.4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.12.24 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.12.2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 . 12 . 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/2/4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/12/4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/12/24 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/12/2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 / 12 / 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '04-02-03 14:30') +GO + +-- invalid syntax +SELECT CONVERT(DATETIME2, '3 12 2024') +GO + +SELECT CONVERT(DATETIME2, '3#12#2024') +GO + +SELECT CONVERT(DATETIME2, '3/12.2024') +GO + +-- Alphabetical +SELECT CONVERT(DATETIME2, 'Apr 12,2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 12 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1,2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16, 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1, 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'April 16, 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'April 16 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16, 24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16,4 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1,4 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16 24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16 4 14:30') +GO + +SELECT CONVERT(DATETIME2, 'April 16 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 22 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 2 14:30') +GO + +SELECT CONVERT(DATETIME2, '24 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3Apr24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr,24 14:30') +GO + +SELECT CONVERT(DATETIME2, '24 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 24 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 12 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 9 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, Apr, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 Apr, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 12, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 12, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 12 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 2024, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 2024 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, 2024, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 2024, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, 12, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 12, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, 12 Apr 14:30') +GO + +-- ISO 8601 +SELECT CONVERT(DATETIME2, '2023-11-27') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123-12:12') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123+12:12') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00') +GO + +SELECT CONVERT(DATETIME2, '2022-10 -30T03: 00:00') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.12345') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:123') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:12345') +GO + +-- Unseparated +SELECT CONVERT(DATETIME2, '20240129') +GO + +SELECT CONVERT(DATETIME2, '20241329') +GO + +SELECT CONVERT(DATETIME2, '240129') +GO + +SELECT CONVERT(DATETIME2, '241329') +GO + +SELECT CONVERT(DATETIME2, '2001') +GO + +SELECT CONVERT(DATETIME2, '0001') +GO + +SELECT CONVERT(DATETIME2, '20240129 03:00:00') +GO + +SELECT CONVERT(DATETIME2, '20241329 03:00:00') +GO + +SELECT CONVERT(DATETIME2, '240129 03:00') +GO + +SELECT CONVERT(DATETIME2, '241329 03:00') +GO + +SELECT CONVERT(DATETIME2, '2001 03:00:00.123') +GO + +SELECT CONVERT(DATETIME2, '0001 03:00:00.421') +GO + +-- -- invalid syntax +SELECT CONVERT(DATETIME2, '0') +GO + +SELECT CONVERT(DATETIME2, '1') +GO + +SELECT CONVERT(DATETIME2, '11') +GO + +SELECT CONVERT(DATETIME2, '111') +GO + +SELECT CONVERT(DATETIME2, '11111') +GO + +SELECT CONVERT(DATETIME2, '1111111') +GO + +-- should return default DATETIME2 +SELECT CONVERT(DATETIME2, '16:23:51') +GO + +SELECT CONVERT(DATETIME2, '4:12:12:123') +GO + +SELECT CONVERT(DATETIME2, '4:12:12:1234') +GO + +SELECT CONVERT(DATETIME2, '4:12:12.1234') +GO + +-- hijri +SELECT CONVERT(DATETIME2, '20231229', 130) +GO + +SELECT CONVERT(DATETIME2, '20231230', 130) +GO + +SELECT CONVERT(DATETIME2, '20231129', 130) +GO + +SELECT CONVERT(DATETIME2, '20231130', 130) +GO + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 131) +GO + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 130) +GO + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 131) +GO + +-- -- hijri leap year +SELECT CONVERT(DATETIME2, '20241230', 130) +GO + +-- rounding of DATETIME2 +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345679') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345678') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345677') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345676') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345675') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345674') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345673') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345672') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345671') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345670') +GO + +-- DATETIME2 with typmod +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.501') +GO + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.500') +GO + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.499') +GO + +SELECT CONVERT(DATETIME2(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME2(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME2(3), '01/01/98 23:59:59.123') +GO + +-- -- Boundary values +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.99999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.999999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.99999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.999999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999999') +GO + +-- -- out of bound values +SELECT CONVERT(DATETIME2,'2022-10-00 23:59:59.990') +GO + +SELECT CONVERT(DATETIME2,'0000-10-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME2,'2023-00-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME2,'0000-00-00 23:59:59.990') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(DATETIME2, '02/12/21', 1) +GO + +SELECT CONVERT(DATETIME2, '21.02.12', 2) +GO + +SELECT CONVERT(DATETIME2, '12/02/21', 3) +GO + +SELECT CONVERT(DATETIME2, '12.02.21', 4) +GO + +SELECT CONVERT(DATETIME2, '12-02-21', 5) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 21', 6) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(DATETIME2, '10:13:14', 8) +GO + +SELECT CONVERT(DATETIME2, '10:13:14', 24) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(DATETIME2, '02-12-21', 10) +GO + +SELECT CONVERT(DATETIME2, '21/02/12', 11) +GO + +SELECT CONVERT(DATETIME2, '210212', 12) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(DATETIME2, '15:13:14:123', 14) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(DATETIME2, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12', 23) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(DATETIME2, '02/12/2021', 101) +GO + +SELECT CONVERT(DATETIME2, '2021.02.12', 102) +GO + +SELECT CONVERT(DATETIME2, '12/02/2021', 103) +GO + +SELECT CONVERT(DATETIME2, '12.02.2021', 104) +GO + +SELECT CONVERT(DATETIME2, '12-02-2021', 105) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 2021', 106) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(DATETIME2, '10:13:14', 108) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(DATETIME2, '02-12-2021', 110) +GO + +SELECT CONVERT(DATETIME2, '2021/02/12', 111) +GO + +SELECT CONVERT(DATETIME2, '20210212', 112) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(DATETIME2, '15:13:14:123', 114) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME2, '12/02/2021 15:13:14:123 PM', 131) +GO + +--- misc +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME2, '2020') +GO + +SELECT CONVERT(DATETIME2, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(DATETIME2, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME2, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(DATETIME2, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(DATETIME2, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME2, '2020') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATETIME2, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME2, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime2_v1 +GO +EXEC test_conv_string_to_datetime2_p1 +GO +SELECT test_conv_string_to_datetime2_f1() +GO + +SELECT * FROM test_conv_string_to_datetime2_v2 +GO +EXEC test_conv_string_to_datetime2_p2 +GO +SELECT test_conv_string_to_datetime2_f2() +GO + +EXEC test_conv_string_to_datetime2_p2_2 +GO +SELECT test_conv_string_to_datetime2_f2_2() +GO + +SELECT * FROM test_conv_string_to_datetime2_v3 +GO +EXEC test_conv_string_to_datetime2_p3 +GO +SELECT test_conv_string_to_datetime2_f3() +GO + +SELECT * FROM test_conv_string_to_datetime2_v4 +GO +EXEC test_conv_string_to_datetime2_p4 +GO +SELECT test_conv_string_to_datetime2_f4() +GO + +SELECT * FROM test_conv_string_to_datetime2_v5 +GO +EXEC test_conv_string_to_datetime2_p5 +GO +SELECT test_conv_string_to_datetime2_f5() +GO + +SELECT * FROM test_conv_string_to_datetime2_v6 +GO +EXEC test_conv_string_to_datetime2_p6 +GO +SELECT test_conv_string_to_datetime2_f6() +GO + +SELECT * FROM test_conv_string_to_datetime2_v7 +GO +EXEC test_conv_string_to_datetime2_p7 +GO +SELECT test_conv_string_to_datetime2_f7() +GO + +SELECT * FROM test_conv_string_to_datetime2_v8 +GO +EXEC test_conv_string_to_datetime2_p8 +GO +SELECT test_conv_string_to_datetime2_f8() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-cleanup.sql new file mode 100644 index 0000000000..e9e44fd452 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-cleanup.sql @@ -0,0 +1,60 @@ +DROP VIEW test_conv_string_to_datetime2_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p1 +GO +DROP FUNCTION test_conv_string_to_datetime2_f1() +GO + +DROP VIEW test_conv_string_to_datetime2_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2() +GO + +DROP PROCEDURE test_conv_string_to_datetime2_p2_2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2_2() +GO + +DROP VIEW test_conv_string_to_datetime2_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p3 +GO +DROP FUNCTION test_conv_string_to_datetime2_f3() +GO + +DROP VIEW test_conv_string_to_datetime2_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p4 +GO +DROP FUNCTION test_conv_string_to_datetime2_f4() +GO + +DROP VIEW test_conv_string_to_datetime2_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p5 +GO +DROP FUNCTION test_conv_string_to_datetime2_f5() +GO + +DROP VIEW test_conv_string_to_datetime2_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p6 +GO +DROP FUNCTION test_conv_string_to_datetime2_f6() +GO + +DROP VIEW test_conv_string_to_datetime2_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p7 +GO +DROP FUNCTION test_conv_string_to_datetime2_f7() +GO + +DROP VIEW test_conv_string_to_datetime2_v8 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p8 +GO +DROP FUNCTION test_conv_string_to_datetime2_f8() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-prepare.sql new file mode 100644 index 0000000000..19948dc11c --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-prepare.sql @@ -0,0 +1,97 @@ +CREATE VIEW test_conv_string_to_datetime2_v1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f1() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE PROCEDURE test_conv_string_to_datetime2_p2_2 as (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2_2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +END +GO + + +CREATE VIEW test_conv_string_to_datetime2_v3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f3() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f4() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f5() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f6() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f7() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f8() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-verify.sql new file mode 100644 index 0000000000..c9dbfc26b4 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime2-before-17_3-vu-verify.sql @@ -0,0 +1,684 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIME2, '') +GO + +SELECT CONVERT(DATETIME2, '', 130) +GO + +-- -- Numeric +SELECT CONVERT(DATETIME2, '3-2-4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3-12-4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3-12-24 14:30') +GO + +SELECT CONVERT(DATETIME2, '3-12-2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 - 12 - 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.2.4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.12.4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.12.24 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.12.2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 . 12 . 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/2/4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/12/4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/12/24 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/12/2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 / 12 / 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '04-02-03 14:30') +GO + +-- invalid syntax +SELECT CONVERT(DATETIME2, '3 12 2024') +GO + +SELECT CONVERT(DATETIME2, '3#12#2024') +GO + +SELECT CONVERT(DATETIME2, '3/12.2024') +GO + +-- Alphabetical +SELECT CONVERT(DATETIME2, 'Apr 12,2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 12 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1,2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16, 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1, 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'April 16, 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'April 16 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16, 24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16,4 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1,4 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16 24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16 4 14:30') +GO + +SELECT CONVERT(DATETIME2, 'April 16 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 22 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 2 14:30') +GO + +SELECT CONVERT(DATETIME2, '24 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3Apr24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr,24 14:30') +GO + +SELECT CONVERT(DATETIME2, '24 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 24 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 12 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 9 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, Apr, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 Apr, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 12, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 12, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 12 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 2024, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 2024 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, 2024, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 2024, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, 12, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 12, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, 12 Apr 14:30') +GO + +-- ISO 8601 +SELECT CONVERT(DATETIME2, '2023-11-27') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123-12:12') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123+12:12') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00') +GO + +SELECT CONVERT(DATETIME2, '2022-10 -30T03: 00:00') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.12345') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:123') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:12345') +GO + +-- Unseparated +SELECT CONVERT(DATETIME2, '20240129') +GO + +SELECT CONVERT(DATETIME2, '20241329') +GO + +SELECT CONVERT(DATETIME2, '240129') +GO + +SELECT CONVERT(DATETIME2, '241329') +GO + +SELECT CONVERT(DATETIME2, '2001') +GO + +SELECT CONVERT(DATETIME2, '0001') +GO + +SELECT CONVERT(DATETIME2, '20240129 03:00:00') +GO + +SELECT CONVERT(DATETIME2, '20241329 03:00:00') +GO + +SELECT CONVERT(DATETIME2, '240129 03:00') +GO + +SELECT CONVERT(DATETIME2, '241329 03:00') +GO + +SELECT CONVERT(DATETIME2, '2001 03:00:00.123') +GO + +SELECT CONVERT(DATETIME2, '0001 03:00:00.421') +GO + +-- -- invalid syntax +SELECT CONVERT(DATETIME2, '0') +GO + +SELECT CONVERT(DATETIME2, '1') +GO + +SELECT CONVERT(DATETIME2, '11') +GO + +SELECT CONVERT(DATETIME2, '111') +GO + +SELECT CONVERT(DATETIME2, '11111') +GO + +SELECT CONVERT(DATETIME2, '1111111') +GO + +-- should return default DATETIME2 +SELECT CONVERT(DATETIME2, '16:23:51') +GO + +SELECT CONVERT(DATETIME2, '4:12:12:123') +GO + +SELECT CONVERT(DATETIME2, '4:12:12:1234') +GO + +SELECT CONVERT(DATETIME2, '4:12:12.1234') +GO + +-- hijri +SELECT CONVERT(DATETIME2, '20231229', 130) +GO + +SELECT CONVERT(DATETIME2, '20231230', 130) +GO + +SELECT CONVERT(DATETIME2, '20231129', 130) +GO + +SELECT CONVERT(DATETIME2, '20231130', 130) +GO + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 131) +GO + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 130) +GO + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 131) +GO + +-- -- hijri leap year +SELECT CONVERT(DATETIME2, '20241230', 130) +GO + +-- rounding of DATETIME2 +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345679') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345678') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345677') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345676') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345675') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345674') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345673') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345672') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345671') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345670') +GO + +-- DATETIME2 with typmod +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.501') +GO + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.500') +GO + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.499') +GO + +SELECT CONVERT(DATETIME2(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME2(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME2(3), '01/01/98 23:59:59.123') +GO + +-- -- Boundary values +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.99999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.999999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.99999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.999999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999999') +GO + +-- -- out of bound values +SELECT CONVERT(DATETIME2,'2022-10-00 23:59:59.990') +GO + +SELECT CONVERT(DATETIME2,'0000-10-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME2,'2023-00-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME2,'0000-00-00 23:59:59.990') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(DATETIME2, '02/12/21', 1) +GO + +SELECT CONVERT(DATETIME2, '21.02.12', 2) +GO + +SELECT CONVERT(DATETIME2, '12/02/21', 3) +GO + +SELECT CONVERT(DATETIME2, '12.02.21', 4) +GO + +SELECT CONVERT(DATETIME2, '12-02-21', 5) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 21', 6) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(DATETIME2, '10:13:14', 8) +GO + +SELECT CONVERT(DATETIME2, '10:13:14', 24) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(DATETIME2, '02-12-21', 10) +GO + +SELECT CONVERT(DATETIME2, '21/02/12', 11) +GO + +SELECT CONVERT(DATETIME2, '210212', 12) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(DATETIME2, '15:13:14:123', 14) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(DATETIME2, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12', 23) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(DATETIME2, '02/12/2021', 101) +GO + +SELECT CONVERT(DATETIME2, '2021.02.12', 102) +GO + +SELECT CONVERT(DATETIME2, '12/02/2021', 103) +GO + +SELECT CONVERT(DATETIME2, '12.02.2021', 104) +GO + +SELECT CONVERT(DATETIME2, '12-02-2021', 105) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 2021', 106) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(DATETIME2, '10:13:14', 108) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(DATETIME2, '02-12-2021', 110) +GO + +SELECT CONVERT(DATETIME2, '2021/02/12', 111) +GO + +SELECT CONVERT(DATETIME2, '20210212', 112) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(DATETIME2, '15:13:14:123', 114) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME2, '12/02/2021 15:13:14:123 PM', 131) +GO + +--- misc +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME2, '2020') +GO + +SELECT CONVERT(DATETIME2, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(DATETIME2, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME2, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(DATETIME2, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(DATETIME2, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME2, '2020') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATETIME2, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME2, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime2_v1 +GO +EXEC test_conv_string_to_datetime2_p1 +GO +SELECT test_conv_string_to_datetime2_f1() +GO + +SELECT * FROM test_conv_string_to_datetime2_v2 +GO +EXEC test_conv_string_to_datetime2_p2 +GO +SELECT test_conv_string_to_datetime2_f2() +GO + +EXEC test_conv_string_to_datetime2_p2_2 +GO +SELECT test_conv_string_to_datetime2_f2_2() +GO + +SELECT * FROM test_conv_string_to_datetime2_v3 +GO +EXEC test_conv_string_to_datetime2_p3 +GO +SELECT test_conv_string_to_datetime2_f3() +GO + +SELECT * FROM test_conv_string_to_datetime2_v4 +GO +EXEC test_conv_string_to_datetime2_p4 +GO +SELECT test_conv_string_to_datetime2_f4() +GO + +SELECT * FROM test_conv_string_to_datetime2_v5 +GO +EXEC test_conv_string_to_datetime2_p5 +GO +SELECT test_conv_string_to_datetime2_f5() +GO + +SELECT * FROM test_conv_string_to_datetime2_v6 +GO +EXEC test_conv_string_to_datetime2_p6 +GO +SELECT test_conv_string_to_datetime2_f6() +GO + +SELECT * FROM test_conv_string_to_datetime2_v7 +GO +EXEC test_conv_string_to_datetime2_p7 +GO +SELECT test_conv_string_to_datetime2_f7() +GO + +SELECT * FROM test_conv_string_to_datetime2_v8 +GO +EXEC test_conv_string_to_datetime2_p8 +GO +SELECT test_conv_string_to_datetime2_f8() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime2-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_datetime2-vu-cleanup.sql new file mode 100644 index 0000000000..e9e44fd452 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime2-vu-cleanup.sql @@ -0,0 +1,60 @@ +DROP VIEW test_conv_string_to_datetime2_v1 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p1 +GO +DROP FUNCTION test_conv_string_to_datetime2_f1() +GO + +DROP VIEW test_conv_string_to_datetime2_v2 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2() +GO + +DROP PROCEDURE test_conv_string_to_datetime2_p2_2 +GO +DROP FUNCTION test_conv_string_to_datetime2_f2_2() +GO + +DROP VIEW test_conv_string_to_datetime2_v3 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p3 +GO +DROP FUNCTION test_conv_string_to_datetime2_f3() +GO + +DROP VIEW test_conv_string_to_datetime2_v4 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p4 +GO +DROP FUNCTION test_conv_string_to_datetime2_f4() +GO + +DROP VIEW test_conv_string_to_datetime2_v5 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p5 +GO +DROP FUNCTION test_conv_string_to_datetime2_f5() +GO + +DROP VIEW test_conv_string_to_datetime2_v6 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p6 +GO +DROP FUNCTION test_conv_string_to_datetime2_f6() +GO + +DROP VIEW test_conv_string_to_datetime2_v7 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p7 +GO +DROP FUNCTION test_conv_string_to_datetime2_f7() +GO + +DROP VIEW test_conv_string_to_datetime2_v8 +GO +DROP PROCEDURE test_conv_string_to_datetime2_p8 +GO +DROP FUNCTION test_conv_string_to_datetime2_f8() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime2-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_datetime2-vu-prepare.sql new file mode 100644 index 0000000000..19948dc11c --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime2-vu-prepare.sql @@ -0,0 +1,97 @@ +CREATE VIEW test_conv_string_to_datetime2_v1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p1 as (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f1() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(1), CAST('2017-08-25 13:01:59' AS datetime))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p2 as (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE PROCEDURE test_conv_string_to_datetime2_p2_2 as (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f2_2() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(10), '2017-08-25 13:01:59.1234567')); +END +GO + + +CREATE VIEW test_conv_string_to_datetime2_v3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p3 as (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f3() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2(5), '2017-08-25 13:01:59.1234567')); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p4 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f4() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p5 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f5() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS CHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p6 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f6() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p7 as (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f7() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017-08-25 13:01:59.1234567' AS NVARCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetime2_v8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetime2_p8 as (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetime2_f8() +RETURNS DATETIME2 AS +BEGIN +RETURN (SELECT CONVERT(datetime2, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetime2-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_datetime2-vu-verify.sql new file mode 100644 index 0000000000..b8fb885a78 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetime2-vu-verify.sql @@ -0,0 +1,685 @@ +-- sla 70000 +-- Empty string, should return default values +SELECT CONVERT(DATETIME2, '') +GO + +SELECT CONVERT(DATETIME2, '', 130) +GO + +-- -- Numeric +SELECT CONVERT(DATETIME2, '3-2-4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3-12-4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3-12-24 14:30') +GO + +SELECT CONVERT(DATETIME2, '3-12-2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 - 12 - 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.2.4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.12.4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.12.24 14:30') +GO + +SELECT CONVERT(DATETIME2, '3.12.2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 . 12 . 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/2/4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/12/4 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/12/24 14:30') +GO + +SELECT CONVERT(DATETIME2, '3/12/2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 / 12 / 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '04-02-03 14:30') +GO + +-- invalid syntax +SELECT CONVERT(DATETIME2, '3 12 2024') +GO + +SELECT CONVERT(DATETIME2, '3#12#2024') +GO + +SELECT CONVERT(DATETIME2, '3/12.2024') +GO + +-- Alphabetical +SELECT CONVERT(DATETIME2, 'Apr 12,2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 12 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1,2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16, 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1, 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'April 16, 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'April 16 2000 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16, 24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16,4 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 1,4 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16 24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 16 4 14:30') +GO + +SELECT CONVERT(DATETIME2, 'April 16 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 22 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 2 14:30') +GO + +SELECT CONVERT(DATETIME2, '24 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3 Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3Apr2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '3Apr24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr24 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr,24 14:30') +GO + +SELECT CONVERT(DATETIME2, '24 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 24 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 12 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 9 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 Apr, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, Apr 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, Apr, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 Apr, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, Apr 12 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 12, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 12, 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 12 2024 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 2024, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr 2024, 12 14:30') +GO + +SELECT CONVERT(DATETIME2, 'Apr, 2024 12 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, 2024, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12 2024, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '12, 2024 Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, 12, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024 12, Apr 14:30') +GO + +SELECT CONVERT(DATETIME2, '2024, 12 Apr 14:30') +GO + +-- ISO 8601 +SELECT CONVERT(DATETIME2, '2023-11-27') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123-12:12') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.123+12:12') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00') +GO + +SELECT CONVERT(DATETIME2, '2022-10 -30T03: 00:00') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00.12345') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:123') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00:12345') +GO + +-- Unseparated +SELECT CONVERT(DATETIME2, '20240129') +GO + +SELECT CONVERT(DATETIME2, '20241329') +GO + +SELECT CONVERT(DATETIME2, '240129') +GO + +SELECT CONVERT(DATETIME2, '241329') +GO + +SELECT CONVERT(DATETIME2, '2001') +GO + +SELECT CONVERT(DATETIME2, '0001') +GO + +SELECT CONVERT(DATETIME2, '20240129 03:00:00') +GO + +SELECT CONVERT(DATETIME2, '20241329 03:00:00') +GO + +SELECT CONVERT(DATETIME2, '240129 03:00') +GO + +SELECT CONVERT(DATETIME2, '241329 03:00') +GO + +SELECT CONVERT(DATETIME2, '2001 03:00:00.123') +GO + +SELECT CONVERT(DATETIME2, '0001 03:00:00.421') +GO + +-- -- invalid syntax +SELECT CONVERT(DATETIME2, '0') +GO + +SELECT CONVERT(DATETIME2, '1') +GO + +SELECT CONVERT(DATETIME2, '11') +GO + +SELECT CONVERT(DATETIME2, '111') +GO + +SELECT CONVERT(DATETIME2, '11111') +GO + +SELECT CONVERT(DATETIME2, '1111111') +GO + +-- should return default DATETIME2 +SELECT CONVERT(DATETIME2, '16:23:51') +GO + +SELECT CONVERT(DATETIME2, '4:12:12:123') +GO + +SELECT CONVERT(DATETIME2, '4:12:12:1234') +GO + +SELECT CONVERT(DATETIME2, '4:12:12.1234') +GO + +-- hijri +SELECT CONVERT(DATETIME2, '20231229', 130) +GO + +SELECT CONVERT(DATETIME2, '20231230', 130) +GO + +SELECT CONVERT(DATETIME2, '20231129', 130) +GO + +SELECT CONVERT(DATETIME2, '20231130', 130) +GO + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(DATETIME2, '22/12/1440 1:39:17.090PM', 131) +GO + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 130) +GO + +SELECT CONVERT(DATETIME2, N'29 شوال 1445 11:46:25:347AM', 131) +GO + +-- -- hijri leap year +SELECT CONVERT(DATETIME2, '20241230', 130) +GO + +-- rounding of DATETIME2 +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345679') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345678') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345677') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345676') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345675') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345674') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345673') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345672') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345671') +GO + +SELECT CONVERT(DATETIME2, '01/01/98 23:59:59.12345670') +GO + +-- DATETIME2 with typmod +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.501') +GO + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.500') +GO + +SELECT CONVERT(DATETIME2(0), '01/01/98 23:59:56.499') +GO + +SELECT CONVERT(DATETIME2(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME2(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIME2(3), '01/01/98 23:59:59.123') +GO + +-- -- Boundary values +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.99999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.999999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-30 23:59:59.9999999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.99999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.999999999') +GO + +SELECT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999999') +GO + +-- -- out of bound values +SELECT CONVERT(DATETIME2,'2022-10-00 23:59:59.990') +GO + +SELECT CONVERT(DATETIME2,'0000-10-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME2,'2023-00-01 23:59:59.990') +GO + +SELECT CONVERT(DATETIME2,'0000-00-00 23:59:59.990') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(DATETIME2, '02/12/21', 1) +GO + +SELECT CONVERT(DATETIME2, '21.02.12', 2) +GO + +SELECT CONVERT(DATETIME2, '12/02/21', 3) +GO + +SELECT CONVERT(DATETIME2, '12.02.21', 4) +GO + +SELECT CONVERT(DATETIME2, '12-02-21', 5) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 21', 6) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(DATETIME2, '10:13:14', 8) +GO + +SELECT CONVERT(DATETIME2, '10:13:14', 24) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(DATETIME2, '02-12-21', 10) +GO + +SELECT CONVERT(DATETIME2, '21/02/12', 11) +GO + +SELECT CONVERT(DATETIME2, '210212', 12) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(DATETIME2, '15:13:14:123', 14) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(DATETIME2, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12', 23) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(DATETIME2, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(DATETIME2, '02/12/2021', 101) +GO + +SELECT CONVERT(DATETIME2, '2021.02.12', 102) +GO + +SELECT CONVERT(DATETIME2, '12/02/2021', 103) +GO + +SELECT CONVERT(DATETIME2, '12.02.2021', 104) +GO + +SELECT CONVERT(DATETIME2, '12-02-2021', 105) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 2021', 106) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(DATETIME2, '10:13:14', 108) +GO + +SELECT CONVERT(DATETIME2, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(DATETIME2, '02-12-2021', 110) +GO + +SELECT CONVERT(DATETIME2, '2021/02/12', 111) +GO + +SELECT CONVERT(DATETIME2, '20210212', 112) +GO + +SELECT CONVERT(DATETIME2, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(DATETIME2, '15:13:14:123', 114) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(DATETIME2, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(DATETIME2, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIME2, '12/02/2021 15:13:14:123 PM', 131) +GO + +--- misc +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME2, '2020') +GO + +SELECT CONVERT(DATETIME2, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(DATETIME2, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIME2, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(DATETIME2, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(DATETIME2, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(DATETIME2, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(DATETIME2,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIME2, '2020') +GO + +SELECT CONVERT(DATETIME2, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATETIME2, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(DATETIME2, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIME2, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetime2_v1 +GO +EXEC test_conv_string_to_datetime2_p1 +GO +SELECT test_conv_string_to_datetime2_f1() +GO + +SELECT * FROM test_conv_string_to_datetime2_v2 +GO +EXEC test_conv_string_to_datetime2_p2 +GO +SELECT test_conv_string_to_datetime2_f2() +GO + +EXEC test_conv_string_to_datetime2_p2_2 +GO +SELECT test_conv_string_to_datetime2_f2_2() +GO + +SELECT * FROM test_conv_string_to_datetime2_v3 +GO +EXEC test_conv_string_to_datetime2_p3 +GO +SELECT test_conv_string_to_datetime2_f3() +GO + +SELECT * FROM test_conv_string_to_datetime2_v4 +GO +EXEC test_conv_string_to_datetime2_p4 +GO +SELECT test_conv_string_to_datetime2_f4() +GO + +SELECT * FROM test_conv_string_to_datetime2_v5 +GO +EXEC test_conv_string_to_datetime2_p5 +GO +SELECT test_conv_string_to_datetime2_f5() +GO + +SELECT * FROM test_conv_string_to_datetime2_v6 +GO +EXEC test_conv_string_to_datetime2_p6 +GO +SELECT test_conv_string_to_datetime2_f6() +GO + +SELECT * FROM test_conv_string_to_datetime2_v7 +GO +EXEC test_conv_string_to_datetime2_p7 +GO +SELECT test_conv_string_to_datetime2_f7() +GO + +SELECT * FROM test_conv_string_to_datetime2_v8 +GO +EXEC test_conv_string_to_datetime2_p8 +GO +SELECT test_conv_string_to_datetime2_f8() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-cleanup.sql new file mode 100644 index 0000000000..751e44c265 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-cleanup.sql @@ -0,0 +1,48 @@ +DROP VIEW test_conv_string_to_datetimeoffset_v1 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p1 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f1() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v2 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p2 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f2() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v3 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p3 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f3() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v4 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p4 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f4() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v5 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p5 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f5() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v6 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p6 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f6() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v7 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p7 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f7() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-prepare.sql new file mode 100644 index 0000000000..809c7e2ac9 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-prepare.sql @@ -0,0 +1,76 @@ +CREATE VIEW test_conv_string_to_datetimeoffset_v1 as (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p1 as (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f1() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v2 as (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p2 as (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f2() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v3 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p3 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f3() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v4 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p4 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f4() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v5 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p5 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f5() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v6 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p6 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f6() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v7 as (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p7 as (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f7() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-verify.sql new file mode 100644 index 0000000000..c565c53836 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-before-17_3-vu-verify.sql @@ -0,0 +1,743 @@ +-- Empty string, should return default values +SELECT CONVERT(DATETIMEOFFSET, '') +GO + +SELECT CONVERT(DATETIMEOFFSET, '', 130) +GO + +-- -- Numeric +SELECT CONVERT(DATETIMEOFFSET, '3-2-4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3-12-4 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3-12-24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3-12-2024 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3 - 12 - 2024 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3.2.4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3.12.4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3.12.24 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3.12.2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3 . 12 . 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3/2/4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3/12/4 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3/12/24 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3/12/2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3 / 12 / 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '04-02-03 14:30 -8:00') +GO + +-- invalid syntax +SELECT CONVERT(DATETIMEOFFSET, '3 12 2024 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3#12#2024 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3/12.2024 -8:00') +GO + +-- Alphabetical +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12,2000 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2000 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1 2000 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1,2000 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2000 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16, 2000 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1, 2000 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'April 16, 2000 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'April 16 2000 14:30Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16, 24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16,4 14:30Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1,4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16 24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16 4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'April 16 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 14:30Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 22 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 2 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '24 Apr, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3 Apr, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3 Apr 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3Apr2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3Apr24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr,24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '24 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 24 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 2024 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 12 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 9 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12, Apr, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12, Apr 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024, Apr, 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr, 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024, Apr 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 12, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 12 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024, 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024, 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12, 2024, Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 2024, Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12, 2024 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024, 12, Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 12, Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024, 12 Apr 14:30 -8:00') +GO + +-- W3C XML +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27-8:00') +GO + +-- ISO 8601 +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345Z') +GO + + +-- Unseparated +SELECT CONVERT(DATETIMEOFFSET, '20240129 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '20241329 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '240129 Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '241329 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2001 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '0001 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '20240129 03:00:00 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '20241329 03:00:00 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '240129 03:00 Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '241329 03:00 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2001 03:00:00.123 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '0001 03:00:00.421Z') +GO + +-- -- invalid syntax +SELECT CONVERT(DATETIMEOFFSET, '0') +GO + +SELECT CONVERT(DATETIMEOFFSET, '1') +GO + +SELECT CONVERT(DATETIMEOFFSET, '11') +GO + +SELECT CONVERT(DATETIMEOFFSET, '111') +GO + +SELECT CONVERT(DATETIMEOFFSET, '11111') +GO + +SELECT CONVERT(DATETIMEOFFSET, '1111111') +GO + +-- should return default DATETIMEOFFSET +SELECT CONVERT(DATETIMEOFFSET, '16:23:51 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12:123 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12:1234 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12.1234 -8:00') +GO + +-- hijri +SELECT CONVERT(DATETIMEOFFSET, '20231229', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, '20231230', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, '20231129', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, '20231130', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(DATETIMEOFFSET, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, '22/12/1440 1:39:17.090PM', 131) +GO + +-- -- hijri leap year +SELECT CONVERT(DATETIMEOFFSET, '20241230', 130) +GO + +-- rounding of DATETIMEOFFSET +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345679 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345678 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345677 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345676 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345675 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345674 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345673 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345672 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345671 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345670 -8:00') +GO + +-- DATETIMEOFFSET with typmod +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.501') +GO + +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.500') +GO + +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.499') +GO + +SELECT CONVERT(DATETIMEOFFSET(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIMEOFFSET(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIMEOFFSET(3), '01/01/98 23:59:59.123') +GO + +-- -- Boundary values +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.9999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.99999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.999999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.9999999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.9999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.99999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.999999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.9999999999') +GO + +-- -- out of bound values +SELECT CONVERT(DATETIMEOFFSET,'2022-10-00 23:59:59.990 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET,'0000-10-01 23:59:59.990 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET,'2023-00-01 23:59:59.990 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET,'0000-00-00 23:59:59.990 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-21 23:59:59.990 +14:01') +GO + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-21 23:59:59.990 -15:00') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIMEOFFSET, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02/12/21', 1) +GO + +SELECT CONVERT(DATETIMEOFFSET, '21.02.12', 2) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12/02/21', 3) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12.02.21', 4) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12-02-21', 5) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 21', 6) +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 8) +GO + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 24) +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02-12-21', 10) +GO + +SELECT CONVERT(DATETIMEOFFSET, '21/02/12', 11) +GO + +SELECT CONVERT(DATETIMEOFFSET, '210212', 12) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(DATETIMEOFFSET, '15:13:14:123', 14) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12', 23) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02/12/2021', 101) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021.02.12', 102) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12/02/2021', 103) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12.02.2021', 104) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12-02-2021', 105) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021', 106) +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 108) +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02-12-2021', 110) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021/02/12', 111) +GO + +SELECT CONVERT(DATETIMEOFFSET, '20210212', 112) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(DATETIMEOFFSET, '15:13:14:123', 114) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12/02/2021 15:13:14:123 PM', 131) +GO + +--- misc +SELECT CONVERT(DATETIMEOFFSET,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2020') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(DATETIMEOFFSET, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2020') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIMEOFFSET, @TM_ICLO) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '1900-05-06 13:59:29.050') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2000-04-22 16:23:51.7668c0 -8:00') +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetimeoffset_v1 +GO +EXEC test_conv_string_to_datetimeoffset_p1 +GO +SELECT test_conv_string_to_datetimeoffset_f1() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v2 +GO +EXEC test_conv_string_to_datetimeoffset_p2 +GO +SELECT test_conv_string_to_datetimeoffset_f2() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v3 +GO +EXEC test_conv_string_to_datetimeoffset_p3 +GO +SELECT test_conv_string_to_datetimeoffset_f3() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v4 +GO +EXEC test_conv_string_to_datetimeoffset_p4 +GO +SELECT test_conv_string_to_datetimeoffset_f4() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v5 +GO +EXEC test_conv_string_to_datetimeoffset_p5 +GO +SELECT test_conv_string_to_datetimeoffset_f5() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v6 +GO +EXEC test_conv_string_to_datetimeoffset_p6 +GO +SELECT test_conv_string_to_datetimeoffset_f6() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v7 +GO +EXEC test_conv_string_to_datetimeoffset_p7 +GO +SELECT test_conv_string_to_datetimeoffset_f7() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-cleanup.sql new file mode 100644 index 0000000000..751e44c265 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-cleanup.sql @@ -0,0 +1,48 @@ +DROP VIEW test_conv_string_to_datetimeoffset_v1 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p1 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f1() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v2 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p2 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f2() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v3 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p3 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f3() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v4 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p4 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f4() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v5 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p5 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f5() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v6 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p6 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f6() +GO + +DROP VIEW test_conv_string_to_datetimeoffset_v7 +GO +DROP PROCEDURE test_conv_string_to_datetimeoffset_p7 +GO +DROP FUNCTION test_conv_string_to_datetimeoffset_f7() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-prepare.sql new file mode 100644 index 0000000000..809c7e2ac9 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-prepare.sql @@ -0,0 +1,76 @@ +CREATE VIEW test_conv_string_to_datetimeoffset_v1 as (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p1 as (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f1() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, '2017-08-25 13:01:59 +12:15')); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v2 as (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p2 as (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f2() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, '13:01:59 +12:15')); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v3 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p3 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f3() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v4 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p4 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f4() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS CHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v5 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p5 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f5() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v6 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p6 as (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f6() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017-08-25 13:01:59 +12:15' AS NVARCHAR(30)))); +END +GO + +CREATE VIEW test_conv_string_to_datetimeoffset_v7 as (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_datetimeoffset_p7 as (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_datetimeoffset_f7() +RETURNS datetimeoffset AS +BEGIN +RETURN (SELECT CONVERT(datetimeoffset, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-verify.sql new file mode 100644 index 0000000000..3a837b0729 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_datetimeoffset-vu-verify.sql @@ -0,0 +1,744 @@ +-- sla 70000 +-- Empty string, should return default values +SELECT CONVERT(DATETIMEOFFSET, '') +GO + +SELECT CONVERT(DATETIMEOFFSET, '', 130) +GO + +-- -- Numeric +SELECT CONVERT(DATETIMEOFFSET, '3-2-4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3-12-4 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3-12-24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3-12-2024 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3 - 12 - 2024 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3.2.4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3.12.4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3.12.24 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3.12.2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3 . 12 . 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3/2/4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3/12/4 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3/12/24 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3/12/2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3 / 12 / 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '04-02-03 14:30 -8:00') +GO + +-- invalid syntax +SELECT CONVERT(DATETIMEOFFSET, '3 12 2024 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3#12#2024 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3/12.2024 -8:00') +GO + +-- Alphabetical +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12,2000 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2000 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1 2000 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1,2000 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2000 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16, 2000 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1, 2000 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'April 16, 2000 14:30 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'April 16 2000 14:30Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16, 24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16,4 14:30Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 1,4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16 24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 16 4 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'April 16 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 14:30Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 22 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 2 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '24 Apr, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3 Apr, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3 Apr 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3Apr2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '3Apr24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr,24 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '24 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 24 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 2024 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 12 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 9 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12, Apr, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12, Apr 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024, Apr, 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 Apr, 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024, Apr 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 12, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 12 2024 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024, 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 2024, 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr, 2024 12 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12, 2024, Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 2024, Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '12, 2024 Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024, 12, Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024 12, Apr 14:30 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2024, 12 Apr 14:30 -8:00') +GO + +-- W3C XML +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27-8:00') +GO + +-- ISO 8601 +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345-8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345+8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2023-11-27Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123-12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.123+12:12') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10 -30T03: 00:00Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00.12345Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:123Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00:12345Z') +GO + + +-- Unseparated +SELECT CONVERT(DATETIMEOFFSET, '20240129 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '20241329 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '240129 Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '241329 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2001 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '0001 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '20240129 03:00:00 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '20241329 03:00:00 +8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '240129 03:00 Z') +GO + +SELECT CONVERT(DATETIMEOFFSET, '241329 03:00 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2001 03:00:00.123 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '0001 03:00:00.421Z') +GO + +-- -- invalid syntax +SELECT CONVERT(DATETIMEOFFSET, '0') +GO + +SELECT CONVERT(DATETIMEOFFSET, '1') +GO + +SELECT CONVERT(DATETIMEOFFSET, '11') +GO + +SELECT CONVERT(DATETIMEOFFSET, '111') +GO + +SELECT CONVERT(DATETIMEOFFSET, '11111') +GO + +SELECT CONVERT(DATETIMEOFFSET, '1111111') +GO + +-- should return default DATETIMEOFFSET +SELECT CONVERT(DATETIMEOFFSET, '16:23:51 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12:123 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12:1234 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '4:12:12.1234 -8:00') +GO + +-- hijri +SELECT CONVERT(DATETIMEOFFSET, '20231229', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, '20231230', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, '20231129', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, '20231130', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(DATETIMEOFFSET, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, '22/12/1440 1:39:17.090PM', 131) +GO + +-- -- hijri leap year +SELECT CONVERT(DATETIMEOFFSET, '20241230', 130) +GO + +-- rounding of DATETIMEOFFSET +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345679 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345678 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345677 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345676 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345675 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345674 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345673 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345672 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345671 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '01/01/98 23:59:59.12345670 -8:00') +GO + +-- DATETIMEOFFSET with typmod +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.501') +GO + +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.500') +GO + +SELECT CONVERT(DATETIMEOFFSET(0), '01/01/98 23:59:56.499') +GO + +SELECT CONVERT(DATETIMEOFFSET(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIMEOFFSET(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(DATETIMEOFFSET(3), '01/01/98 23:59:59.123') +GO + +-- -- Boundary values +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.9999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.99999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.999999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-30 23:59:59.9999999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.9999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.99999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.999999999') +GO + +SELECT CONVERT(DATETIMEOFFSET, '9999-12-31 23:59:59.9999999999') +GO + +-- -- out of bound values +SELECT CONVERT(DATETIMEOFFSET,'2022-10-00 23:59:59.990 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET,'0000-10-01 23:59:59.990 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET,'2023-00-01 23:59:59.990 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET,'0000-00-00 23:59:59.990 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-21 23:59:59.990 +14:01') +GO + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-21 23:59:59.990 -15:00') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(DATETIMEOFFSET, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02/12/21', 1) +GO + +SELECT CONVERT(DATETIMEOFFSET, '21.02.12', 2) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12/02/21', 3) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12.02.21', 4) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12-02-21', 5) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 21', 6) +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 8) +GO + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 24) +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02-12-21', 10) +GO + +SELECT CONVERT(DATETIMEOFFSET, '21/02/12', 11) +GO + +SELECT CONVERT(DATETIMEOFFSET, '210212', 12) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(DATETIMEOFFSET, '15:13:14:123', 14) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12', 23) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02/12/2021', 101) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021.02.12', 102) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12/02/2021', 103) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12.02.2021', 104) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12-02-2021', 105) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021', 106) +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(DATETIMEOFFSET, '10:13:14', 108) +GO + +SELECT CONVERT(DATETIMEOFFSET, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02-12-2021', 110) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021/02/12', 111) +GO + +SELECT CONVERT(DATETIMEOFFSET, '20210212', 112) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(DATETIMEOFFSET, '15:13:14:123', 114) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(DATETIMEOFFSET, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(DATETIMEOFFSET, '12/02/2021 15:13:14:123 PM', 131) +GO + +--- misc +SELECT CONVERT(DATETIMEOFFSET,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2020') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(DATETIMEOFFSET, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(DATETIMEOFFSET,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2020') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(DATETIMEOFFSET, @TM_ICLO) +GO + +SELECT CONVERT(DATETIMEOFFSET, '02001-04-22 16:23:51 -8:00') +GO + +SELECT CONVERT(DATETIMEOFFSET, '1900-05-06 13:59:29.050') +GO + +SELECT CONVERT(DATETIMEOFFSET, '2000-04-22 16:23:51.7668c0 -8:00') +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_datetimeoffset_v1 +GO +EXEC test_conv_string_to_datetimeoffset_p1 +GO +SELECT test_conv_string_to_datetimeoffset_f1() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v2 +GO +EXEC test_conv_string_to_datetimeoffset_p2 +GO +SELECT test_conv_string_to_datetimeoffset_f2() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v3 +GO +EXEC test_conv_string_to_datetimeoffset_p3 +GO +SELECT test_conv_string_to_datetimeoffset_f3() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v4 +GO +EXEC test_conv_string_to_datetimeoffset_p4 +GO +SELECT test_conv_string_to_datetimeoffset_f4() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v5 +GO +EXEC test_conv_string_to_datetimeoffset_p5 +GO +SELECT test_conv_string_to_datetimeoffset_f5() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v6 +GO +EXEC test_conv_string_to_datetimeoffset_p6 +GO +SELECT test_conv_string_to_datetimeoffset_f6() +GO + +SELECT * FROM test_conv_string_to_datetimeoffset_v7 +GO +EXEC test_conv_string_to_datetimeoffset_p7 +GO +SELECT test_conv_string_to_datetimeoffset_f7() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-cleanup.sql new file mode 100644 index 0000000000..b7292d08e8 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-cleanup.sql @@ -0,0 +1,48 @@ +DROP VIEW test_conv_string_to_smalldatetime_v1 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p1 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f1() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v2 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p2 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f2() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v3 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p3 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f3() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v4 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p4 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f4() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v5 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p5 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f5() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v6 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p6 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f6() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v7 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p7 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f7() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-prepare.sql new file mode 100644 index 0000000000..e778e0dfaa --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-prepare.sql @@ -0,0 +1,76 @@ +CREATE VIEW test_conv_string_to_smalldatetime_v1 as (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p1 as (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f1() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v2 as (SELECT CONVERT(smalldatetime, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p2 as (SELECT CONVERT(smalldatetime, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f2() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v3 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p3 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f3() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v4 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p4 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f4() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v5 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p5 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f5() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v6 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p6 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f6() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v7 as (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p7 as (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f7() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-verify.sql new file mode 100644 index 0000000000..29bc68b721 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-before-14_6-vu-verify.sql @@ -0,0 +1,776 @@ +-- Empty string, should return default values +SELECT CONVERT(SMALLDATETIME, '') +GO + +SELECT CONVERT(SMALLDATETIME, '', 130) +GO + +-- -- Numeric +SELECT CONVERT(SMALLDATETIME, '3-2-4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3-12-4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3-12-24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3-12-2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3 - 12 - 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3.2.4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3.12.4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3.12.24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3.12.2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3 . 12 . 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3/2/4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3/12/4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3/12/24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3/12/2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3 / 12 / 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '04-02-03 14:30') +GO + +-- invalid syntax +SELECT CONVERT(SMALLDATETIME, '3 12 2024') +GO + +SELECT CONVERT(SMALLDATETIME, '3#12#2024') +GO + +SELECT CONVERT(SMALLDATETIME, '3/12.2024') +GO + +-- Alphabetical +SELECT CONVERT(SMALLDATETIME, 'Apr 12,2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 1 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 1,2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 16, 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 1, 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'April 16, 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'April 16 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 16, 24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 16,4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 1,4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 16 24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 16 4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'April 16 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 22 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 2 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '24 Apr, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3 Apr, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3 Apr 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3Apr2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3Apr24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr,24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '24 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12 24 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12 2024 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 12 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 9 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 Apr 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12, Apr, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12 Apr, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12, Apr 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024, Apr, 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 Apr, 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024, Apr 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr, 12, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr, 12 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024, 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024, 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12, 2024, Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12 2024, Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12, 2024 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024, 12, Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 12, Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024, 12 Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(SMALLDATETIME, N'محرم 12,2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 12 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 1 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 1,2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 1, 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 24 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16,4 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 1,4 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 24 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 4 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 22 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 2 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'24 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'3 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'3 محرم 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'3محرم2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'3محرم24 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم24 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم,24 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'24 محرم 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'12 24 محرم 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'12 2024 محرم 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 12 محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 9 محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12, محرم, 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12 محرم, 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12, محرم 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024, محرم, 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم, 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024, محرم 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم, 12, 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 12, 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم, 12 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024, 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024, 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12, 2024, محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12 2024, محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12, 2024 محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024, 12, محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 12, محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024, 12 محرم 14:30', 131) +GO + +-- ISO 8601 +SELECT CONVERT(SMALLDATETIME, '2023-11-27') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123-12:12') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123+12:12') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10 -30T03: 00:00') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.12345') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00:123') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00:12345') +GO + +-- Unseparated +SELECT CONVERT(SMALLDATETIME, '20240129') +GO + +SELECT CONVERT(SMALLDATETIME, '20241329') +GO + +SELECT CONVERT(SMALLDATETIME, '240129') +GO + +SELECT CONVERT(SMALLDATETIME, '241329') +GO + +SELECT CONVERT(SMALLDATETIME, '2001') +GO + +SELECT CONVERT(SMALLDATETIME, '0001') +GO + +SELECT CONVERT(SMALLDATETIME, '20240129 03:00:00') +GO + +SELECT CONVERT(SMALLDATETIME, '20241329 03:00:00') +GO + +SELECT CONVERT(SMALLDATETIME, '240129 03:00') +GO + +SELECT CONVERT(SMALLDATETIME, '241329 03:00') +GO + +SELECT CONVERT(SMALLDATETIME, '2001 03:00:00.123') +GO + +SELECT CONVERT(SMALLDATETIME, '0001 03:00:00.421') +GO + +-- -- invalid syntax +SELECT CONVERT(SMALLDATETIME, '0') +GO + +SELECT CONVERT(SMALLDATETIME, '1') +GO + +SELECT CONVERT(SMALLDATETIME, '11') +GO + +SELECT CONVERT(SMALLDATETIME, '111') +GO + +SELECT CONVERT(SMALLDATETIME, '11111') +GO + +SELECT CONVERT(SMALLDATETIME, '1111111') +GO + +-- should return default SMALLDATETIME +SELECT CONVERT(SMALLDATETIME, '16:23:51') +GO + +SELECT CONVERT(SMALLDATETIME, '4:12:12:123') +GO + +SELECT CONVERT(SMALLDATETIME, '4:12:12:1234') +GO + +SELECT CONVERT(SMALLDATETIME, '4:12:12.1234') +GO + +-- hijri +SELECT CONVERT(SMALLDATETIME, '20231229', 130) +GO + +SELECT CONVERT(SMALLDATETIME, '20231230', 130) +GO + +SELECT CONVERT(SMALLDATETIME, '20231129', 130) +GO + +SELECT CONVERT(SMALLDATETIME, '20231130', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(SMALLDATETIME, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(SMALLDATETIME, '22/12/1440 1:39:17.090PM', 131) +GO + +-- -- hijri leap year +SELECT CONVERT(SMALLDATETIME, '20241230', 130) +GO + +-- rounding of SMALLDATETIME +SELECT CONVERT(SMALLDATETIME, '01/01/98 23:44:29') +GO + +SELECT CONVERT(SMALLDATETIME, '01/01/98 23:44:30') +GO + +-- SMALLDATETIME with typmod +SELECT CONVERT(SMALLDATETIME(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(SMALLDATETIME(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(SMALLDATETIME(3), '01/01/98 23:59:59.123') +GO + +-- boundary tests +SELECT CONVERT(SMALLDATETIME, '2079-06-06 23:59:29.999') +GO + +SELECT CONVERT(SMALLDATETIME, '2079-06-06 23:59:29.998') +GO + +-- -- out of bound values +SELECT CONVERT(SMALLDATETIME,'2022-10-00 23:59:59.990') +GO + +SELECT CONVERT(SMALLDATETIME,'0000-10-01 23:59:59.990') +GO + +SELECT CONVERT(SMALLDATETIME,'2023-00-01 23:59:59.990') +GO + +SELECT CONVERT(SMALLDATETIME,'0000-00-00 23:59:59.990') +GO + +SELECT CONVERT(SMALLDATETIME,'1742-10-01 23:59:59.990') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(SMALLDATETIME, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(SMALLDATETIME, '02/12/21', 1) +GO + +SELECT CONVERT(SMALLDATETIME, '21.02.12', 2) +GO + +SELECT CONVERT(SMALLDATETIME, '12/02/21', 3) +GO + +SELECT CONVERT(SMALLDATETIME, '12.02.21', 4) +GO + +SELECT CONVERT(SMALLDATETIME, '12-02-21', 5) +GO + +SELECT CONVERT(SMALLDATETIME, '12 Apr 21', 6) +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 8) +GO + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 24) +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(SMALLDATETIME, '02-12-21', 10) +GO + +SELECT CONVERT(SMALLDATETIME, '21/02/12', 11) +GO + +SELECT CONVERT(SMALLDATETIME, '210212', 12) +GO + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(SMALLDATETIME, '15:13:14:123', 14) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(SMALLDATETIME, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12', 23) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(SMALLDATETIME, '02/12/2021', 101) +GO + +SELECT CONVERT(SMALLDATETIME, '2021.02.12', 102) +GO + +SELECT CONVERT(SMALLDATETIME, '12/02/2021', 103) +GO + +SELECT CONVERT(SMALLDATETIME, '12.02.2021', 104) +GO + +SELECT CONVERT(SMALLDATETIME, '12-02-2021', 105) +GO + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021', 106) +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 108) +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(SMALLDATETIME, '02-12-2021', 110) +GO + +SELECT CONVERT(SMALLDATETIME, '2021/02/12', 111) +GO + +SELECT CONVERT(SMALLDATETIME, '20210212', 112) +GO + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(SMALLDATETIME, '15:13:14:123', 114) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(SMALLDATETIME, '12/02/2021 15:13:14:123 PM', 131) +GO + +--- misc +SELECT CONVERT(SMALLDATETIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(SMALLDATETIME, '2020') +GO + +SELECT CONVERT(SMALLDATETIME, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(SMALLDATETIME, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(SMALLDATETIME, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(SMALLDATETIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(SMALLDATETIME, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(SMALLDATETIME, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(SMALLDATETIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(SMALLDATETIME, '2020') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(SMALLDATETIME, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(SMALLDATETIME, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_smalldatetime_v1 +GO +EXEC test_conv_string_to_smalldatetime_p1 +GO +SELECT test_conv_string_to_smalldatetime_f1() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v2 +GO +EXEC test_conv_string_to_smalldatetime_p2 +GO +SELECT test_conv_string_to_smalldatetime_f2() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v3 +GO +EXEC test_conv_string_to_smalldatetime_p3 +GO +SELECT test_conv_string_to_smalldatetime_f3() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v4 +GO +EXEC test_conv_string_to_smalldatetime_p4 +GO +SELECT test_conv_string_to_smalldatetime_f4() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v5 +GO +EXEC test_conv_string_to_smalldatetime_p5 +GO +SELECT test_conv_string_to_smalldatetime_f5() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v6 +GO +EXEC test_conv_string_to_smalldatetime_p6 +GO +SELECT test_conv_string_to_smalldatetime_f6() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v7 +GO +EXEC test_conv_string_to_smalldatetime_p7 +GO +SELECT test_conv_string_to_smalldatetime_f7() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-cleanup.sql new file mode 100644 index 0000000000..b7292d08e8 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-cleanup.sql @@ -0,0 +1,48 @@ +DROP VIEW test_conv_string_to_smalldatetime_v1 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p1 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f1() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v2 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p2 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f2() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v3 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p3 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f3() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v4 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p4 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f4() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v5 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p5 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f5() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v6 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p6 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f6() +GO + +DROP VIEW test_conv_string_to_smalldatetime_v7 +GO +DROP PROCEDURE test_conv_string_to_smalldatetime_p7 +GO +DROP FUNCTION test_conv_string_to_smalldatetime_f7() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-prepare.sql new file mode 100644 index 0000000000..e778e0dfaa --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-prepare.sql @@ -0,0 +1,76 @@ +CREATE VIEW test_conv_string_to_smalldatetime_v1 as (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p1 as (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f1() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, '2017-08-25 13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v2 as (SELECT CONVERT(smalldatetime, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p2 as (SELECT CONVERT(smalldatetime, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f2() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v3 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p3 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f3() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v4 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p4 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f4() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS CHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v5 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p5 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f5() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v6 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p6 as (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f6() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017-08-25 13:01:59' AS NVARCHAR(20)))); +END +GO + +CREATE VIEW test_conv_string_to_smalldatetime_v7 as (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_smalldatetime_p7 as (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_smalldatetime_f7() +RETURNS smalldatetime AS +BEGIN +RETURN (SELECT CONVERT(smalldatetime, CAST('2017' AS INTEGER))); +END +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-verify.sql new file mode 100644 index 0000000000..bc167cc473 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_smalldatetime-vu-verify.sql @@ -0,0 +1,777 @@ +-- sla 70000 +-- Empty string, should return default values +SELECT CONVERT(SMALLDATETIME, '') +GO + +SELECT CONVERT(SMALLDATETIME, '', 130) +GO + +-- -- Numeric +SELECT CONVERT(SMALLDATETIME, '3-2-4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3-12-4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3-12-24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3-12-2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3 - 12 - 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3.2.4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3.12.4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3.12.24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3.12.2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3 . 12 . 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3/2/4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3/12/4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3/12/24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3/12/2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3 / 12 / 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '04-02-03 14:30') +GO + +-- invalid syntax +SELECT CONVERT(SMALLDATETIME, '3 12 2024') +GO + +SELECT CONVERT(SMALLDATETIME, '3#12#2024') +GO + +SELECT CONVERT(SMALLDATETIME, '3/12.2024') +GO + +-- Alphabetical +SELECT CONVERT(SMALLDATETIME, 'Apr 12,2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 1 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 1,2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 16, 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 1, 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'April 16, 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'April 16 2000 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 16, 24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 16,4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 1,4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 16 24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 16 4 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'April 16 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 22 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 2 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '24 Apr, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3 Apr, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3 Apr 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3Apr2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '3Apr24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr,24 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '24 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12 24 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12 2024 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 12 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 9 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 Apr 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12, Apr, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12 Apr, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12, Apr 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024, Apr, 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 Apr, 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024, Apr 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr, 12, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr, 12 2024 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024, 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 2024, 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr, 2024 12 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12, 2024, Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12 2024, Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '12, 2024 Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024, 12, Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024 12, Apr 14:30') +GO + +SELECT CONVERT(SMALLDATETIME, '2024, 12 Apr 14:30') +GO + +-- For styles 130 and 131, the month name will be in hijri format +-- this is only applicable for datetime and smalldatetime, for other datatypes error will be thrown +SELECT CONVERT(SMALLDATETIME, N'محرم 12,2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 12 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 1 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 1,2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 1, 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 2000 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16, 24 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16,4 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 1,4 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 24 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 4 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 16 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 22 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 2 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'24 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'3 محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'3 محرم 2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'3محرم2024 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'3محرم24 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم24 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم,24 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'24 محرم 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'12 24 محرم 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'12 2024 محرم 14:30', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 12 محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 9 محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12, محرم, 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12 محرم, 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12, محرم 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024, محرم, 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 محرم, 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024, محرم 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم, 12, 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 12, 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم, 12 2024 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024, 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم 2024, 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'محرم, 2024 12 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12, 2024, محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12 2024, محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'12, 2024 محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024, 12, محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024 12, محرم 14:30', 131) +GO + +SELECT CONVERT(SMALLDATETIME, N'2024, 12 محرم 14:30', 131) +GO + +-- ISO 8601 +SELECT CONVERT(SMALLDATETIME, '2023-11-27') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123-12:12') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.123+12:12') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10 -30T03: 00:00') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00.12345') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00:123') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00:12345') +GO + +-- Unseparated +SELECT CONVERT(SMALLDATETIME, '20240129') +GO + +SELECT CONVERT(SMALLDATETIME, '20241329') +GO + +SELECT CONVERT(SMALLDATETIME, '240129') +GO + +SELECT CONVERT(SMALLDATETIME, '241329') +GO + +SELECT CONVERT(SMALLDATETIME, '2001') +GO + +SELECT CONVERT(SMALLDATETIME, '0001') +GO + +SELECT CONVERT(SMALLDATETIME, '20240129 03:00:00') +GO + +SELECT CONVERT(SMALLDATETIME, '20241329 03:00:00') +GO + +SELECT CONVERT(SMALLDATETIME, '240129 03:00') +GO + +SELECT CONVERT(SMALLDATETIME, '241329 03:00') +GO + +SELECT CONVERT(SMALLDATETIME, '2001 03:00:00.123') +GO + +SELECT CONVERT(SMALLDATETIME, '0001 03:00:00.421') +GO + +-- -- invalid syntax +SELECT CONVERT(SMALLDATETIME, '0') +GO + +SELECT CONVERT(SMALLDATETIME, '1') +GO + +SELECT CONVERT(SMALLDATETIME, '11') +GO + +SELECT CONVERT(SMALLDATETIME, '111') +GO + +SELECT CONVERT(SMALLDATETIME, '11111') +GO + +SELECT CONVERT(SMALLDATETIME, '1111111') +GO + +-- should return default SMALLDATETIME +SELECT CONVERT(SMALLDATETIME, '16:23:51') +GO + +SELECT CONVERT(SMALLDATETIME, '4:12:12:123') +GO + +SELECT CONVERT(SMALLDATETIME, '4:12:12:1234') +GO + +SELECT CONVERT(SMALLDATETIME, '4:12:12.1234') +GO + +-- hijri +SELECT CONVERT(SMALLDATETIME, '20231229', 130) +GO + +SELECT CONVERT(SMALLDATETIME, '20231230', 130) +GO + +SELECT CONVERT(SMALLDATETIME, '20231129', 130) +GO + +SELECT CONVERT(SMALLDATETIME, '20231130', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 131) +GO + +SELECT CONVERT(SMALLDATETIME, '22/12/1440 1:39:17.090PM', 130) +GO + +SELECT CONVERT(SMALLDATETIME, '22/12/1440 1:39:17.090PM', 131) +GO + +-- -- hijri leap year +SELECT CONVERT(SMALLDATETIME, '20241230', 130) +GO + +-- rounding of SMALLDATETIME +SELECT CONVERT(SMALLDATETIME, '01/01/98 23:44:29') +GO + +SELECT CONVERT(SMALLDATETIME, '01/01/98 23:44:30') +GO + +-- SMALLDATETIME with typmod +SELECT CONVERT(SMALLDATETIME(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(SMALLDATETIME(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(SMALLDATETIME(3), '01/01/98 23:59:59.123') +GO + +-- boundary tests +SELECT CONVERT(SMALLDATETIME, '2079-06-06 23:59:29.999') +GO + +SELECT CONVERT(SMALLDATETIME, '2079-06-06 23:59:29.998') +GO + +-- -- out of bound values +SELECT CONVERT(SMALLDATETIME,'2022-10-00 23:59:59.990') +GO + +SELECT CONVERT(SMALLDATETIME,'0000-10-01 23:59:59.990') +GO + +SELECT CONVERT(SMALLDATETIME,'2023-00-01 23:59:59.990') +GO + +SELECT CONVERT(SMALLDATETIME,'0000-00-00 23:59:59.990') +GO + +SELECT CONVERT(SMALLDATETIME,'1742-10-01 23:59:59.990') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(SMALLDATETIME, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(SMALLDATETIME, '02/12/21', 1) +GO + +SELECT CONVERT(SMALLDATETIME, '21.02.12', 2) +GO + +SELECT CONVERT(SMALLDATETIME, '12/02/21', 3) +GO + +SELECT CONVERT(SMALLDATETIME, '12.02.21', 4) +GO + +SELECT CONVERT(SMALLDATETIME, '12-02-21', 5) +GO + +SELECT CONVERT(SMALLDATETIME, '12 Apr 21', 6) +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 8) +GO + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 24) +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(SMALLDATETIME, '02-12-21', 10) +GO + +SELECT CONVERT(SMALLDATETIME, '21/02/12', 11) +GO + +SELECT CONVERT(SMALLDATETIME, '210212', 12) +GO + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(SMALLDATETIME, '15:13:14:123', 14) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(SMALLDATETIME, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12', 23) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(SMALLDATETIME, '02/12/2021', 101) +GO + +SELECT CONVERT(SMALLDATETIME, '2021.02.12', 102) +GO + +SELECT CONVERT(SMALLDATETIME, '12/02/2021', 103) +GO + +SELECT CONVERT(SMALLDATETIME, '12.02.2021', 104) +GO + +SELECT CONVERT(SMALLDATETIME, '12-02-2021', 105) +GO + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021', 106) +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(SMALLDATETIME, '10:13:14', 108) +GO + +SELECT CONVERT(SMALLDATETIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(SMALLDATETIME, '02-12-2021', 110) +GO + +SELECT CONVERT(SMALLDATETIME, '2021/02/12', 111) +GO + +SELECT CONVERT(SMALLDATETIME, '20210212', 112) +GO + +SELECT CONVERT(SMALLDATETIME, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(SMALLDATETIME, '15:13:14:123', 114) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(SMALLDATETIME, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(SMALLDATETIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(SMALLDATETIME, '12/02/2021 15:13:14:123 PM', 131) +GO + +--- misc +SELECT CONVERT(SMALLDATETIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(SMALLDATETIME, '2020') +GO + +SELECT CONVERT(SMALLDATETIME, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(SMALLDATETIME, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(SMALLDATETIME, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(SMALLDATETIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(SMALLDATETIME, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(SMALLDATETIME, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(SMALLDATETIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(SMALLDATETIME, '2020') +GO + +SELECT CONVERT(SMALLDATETIME, '2022-10-30T03:00:00') +GO + +SELECT CONVERT(SMALLDATETIME, CONVERT(DATETIMEOFFSET,'2021-01-01 00:00:00.000 +12:00')) +GO + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 10:30.00 AMZ') +GO + +SELECT CONVERT(SMALLDATETIME, '2011-08-15 10:30.00 PMZ') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(SMALLDATETIME, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_smalldatetime_v1 +GO +EXEC test_conv_string_to_smalldatetime_p1 +GO +SELECT test_conv_string_to_smalldatetime_f1() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v2 +GO +EXEC test_conv_string_to_smalldatetime_p2 +GO +SELECT test_conv_string_to_smalldatetime_f2() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v3 +GO +EXEC test_conv_string_to_smalldatetime_p3 +GO +SELECT test_conv_string_to_smalldatetime_f3() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v4 +GO +EXEC test_conv_string_to_smalldatetime_p4 +GO +SELECT test_conv_string_to_smalldatetime_f4() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v5 +GO +EXEC test_conv_string_to_smalldatetime_p5 +GO +SELECT test_conv_string_to_smalldatetime_f5() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v6 +GO +EXEC test_conv_string_to_smalldatetime_p6 +GO +SELECT test_conv_string_to_smalldatetime_f6() +GO + +SELECT * FROM test_conv_string_to_smalldatetime_v7 +GO +EXEC test_conv_string_to_smalldatetime_p7 +GO +SELECT test_conv_string_to_smalldatetime_f7() +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-cleanup.sql new file mode 100644 index 0000000000..a33d1bdadf --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-cleanup.sql @@ -0,0 +1,71 @@ +DROP VIEW test_conv_string_to_time_v1 +GO +DROP PROCEDURE test_conv_string_to_time_p1 +GO +DROP FUNCTION test_conv_string_to_time_f1() +GO + +DROP VIEW test_conv_string_to_time_v2 +GO +DROP PROCEDURE test_conv_string_to_time_p2 +GO +DROP FUNCTION test_conv_string_to_time_f2() +GO + +DROP VIEW test_conv_string_to_time_v3 +GO +DROP PROCEDURE test_conv_string_to_time_p3 +GO +DROP FUNCTION test_conv_string_to_time_f3() +GO + +DROP VIEW test_conv_string_to_time_v4 +GO +DROP PROCEDURE test_conv_string_to_time_p4 +GO +DROP FUNCTION test_conv_string_to_time_f4() +GO + +DROP VIEW test_conv_string_to_time_v5 +GO +DROP PROCEDURE test_conv_string_to_time_p5 +GO +DROP FUNCTION test_conv_string_to_time_f5() +GO + +DROP VIEW test_conv_string_to_time_v6 +GO +DROP PROCEDURE test_conv_string_to_time_p6 +GO +DROP FUNCTION test_conv_string_to_time_f6() +GO + +DROP VIEW test_conv_string_to_time_v7 +GO +DROP PROCEDURE test_conv_string_to_time_p7 +GO +DROP FUNCTION test_conv_string_to_time_f7() +GO + +DROP VIEW test_conv_string_to_time_v8 +GO +DROP PROCEDURE test_conv_string_to_time_p8 +GO +DROP FUNCTION test_conv_string_to_time_f8() +GO + +DROP VIEW test_conv_string_to_time_v9 +GO +DROP PROCEDURE test_conv_string_to_time_p9 +GO +DROP FUNCTION test_conv_string_to_time_f9() +GO + +DROP VIEW test_conv_string_to_time_v10 +GO + +DROP VIEW test_conv_string_to_time_v11 +GO + +DROP VIEW test_conv_string_to_time_v12 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-prepare.sql new file mode 100644 index 0000000000..cc5596c91d --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-prepare.sql @@ -0,0 +1,107 @@ +CREATE VIEW test_conv_string_to_time_v1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_time_p1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_time_f1() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_time_v2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE PROCEDURE test_conv_string_to_time_p2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE FUNCTION test_conv_string_to_time_f2() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '00:00:00')); +END +GO + +CREATE VIEW test_conv_string_to_time_v3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE PROCEDURE test_conv_string_to_time_p3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE FUNCTION test_conv_string_to_time_f3() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '1:1:1')); +END +GO + +CREATE VIEW test_conv_string_to_time_v4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_time_p4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_time_f4() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_time_v5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f5() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f6() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f7() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_time_p8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_time_f8() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_time_v9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f9() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v10 as (SELECT CONVERT(time, '02-03-2003 11:11:11 +11:11')); +GO + +CREATE VIEW test_conv_string_to_time_v11 as (SELECT CONVERT(time, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)))); +GO + +CREATE VIEW test_conv_string_to_time_v12 as (SELECT CONVERT(time, CAST('20' as INTEGER))); +GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-verify.sql new file mode 100644 index 0000000000..7b31f9c866 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_time-before-13_6-vu-verify.sql @@ -0,0 +1,920 @@ +-- Empty string, should return default values +SELECT CONVERT(TIME, '') +GO + +SELECT CONVERT(TIME, '', 130) +GO + +SELECT CONVERT(TIME, '11 AM') +GO + +SELECT CONVERT(TIME, '13 AM') +GO + +SELECT CONVERT(TIME, '11 PM') +GO + +SELECT CONVERT(TIME, '13 PM') +GO + +SELECT CONVERT(TIME, '24 PM') +GO + +SELECT CONVERT(TIME, '0 PM') +GO + +SELECT CONVERT(TIME, '0 AM') +GO + +SELECT CONVERT(TIME, '11AM ') +GO + +SELECT CONVERT(TIME, ' 13AM') +GO + +SELECT CONVERT(TIME, '11PM') +GO + +SELECT CONVERT(TIME, '13PM') +GO + +SELECT CONVERT(TIME, '24PM') +GO + +SELECT CONVERT(TIME, '11') +GO + +SELECT CONVERT(TIME, ' 11:22 ') +GO + +SELECT CONVERT(TIME, '11:22 AM') +GO + +SELECT CONVERT(TIME, '11:22 PM') +GO + +SELECT CONVERT(TIME, '11:22.123') +GO + +SELECT CONVERT(TIME, '11:22.123 AM') +GO + +SELECT CONVERT(TIME, '11:22.123 PM') +GO + +SELECT CONVERT(TIME, '11: 22 :12') +GO + +SELECT CONVERT(TIME, '11:22:12 AM') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM') +GO + +SELECT CONVERT(TIME, '11 :22:12:123') +GO + +SELECT CONVERT(TIME, '11:22:12:1234') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM') +GO + +SELECT CONVERT(TIME, '11: 22:12.123') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM') +GO + +-- TIME with typmod +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.501') +GO + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.500') +GO + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.499') +GO + +SELECT CONVERT(TIME(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(TIME(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(TIME(3), '01/01/98 23:59:59.123') +GO + +-- -- rounding of minutes or fractional seconds +SELECT CONVERT(TIME, '11:22:12.12345675') +GO + +SELECT CONVERT(TIME, '11:22:12.12345674') +GO + +-- -- Boundary values +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999') +GO + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.99999999') +GO + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.999999999') +GO + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.99999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.999999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999999') +GO + +SELECT CONVERT(TIME, '11:22:12.129') +GO + +SELECT CONVERT(TIME, '11:22:12.128') +GO + +SELECT CONVERT(TIME, '11:22:12.127') +GO + +SELECT CONVERT(TIME, '11:22:12.126') +GO + +SELECT CONVERT(TIME, '11:22:12.125') +GO + +SELECT CONVERT(TIME, '11:22:12.124') +GO + +SELECT CONVERT(TIME, '11:22:12.123') +GO + +SELECT CONVERT(TIME, '11:22:12.122') +GO + +SELECT CONVERT(TIME, '11:22:12.121') +GO + +SELECT CONVERT(TIME, '11:22:12.120') +GO + +SELECT CONVERT(TIME, '11:22:29') +GO + +SELECT CONVERT(TIME, '11:22:30') +GO + +SELECT CONVERT(TIME, '11 AM +00:00') +GO + +SELECT CONVERT(TIME, '13 AM -00:00') +GO + +SELECT CONVERT(TIME, '11 PM +00:00') +GO + +SELECT CONVERT(TIME, '13 PM -00:00') +GO + +SELECT CONVERT(TIME, '24 PM +00:00') +GO + +SELECT CONVERT(TIME, '0 PM -00:00') +GO + +SELECT CONVERT(TIME, '0 AM +00:00') +GO + +SELECT CONVERT(TIME, '11AM -00:00') +GO + +SELECT CONVERT(TIME, ' 13AM +00:00') +GO + +SELECT CONVERT(TIME, '11PM -00:00') +GO + +SELECT CONVERT(TIME, '13PM +00:00') +GO + +SELECT CONVERT(TIME, '24PM -00:00') +GO + +SELECT CONVERT(TIME, '11 +00:00') +GO + +SELECT CONVERT(TIME, ' 11:22 -00:00') +GO + +SELECT CONVERT(TIME, '11:22 AM -00:00') +GO + +SELECT CONVERT(TIME, '11:22 PM +00:00') +GO + +SELECT CONVERT(TIME, '11:22.123 -00:00') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +00:00') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -00:00') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +00:00') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -00:00') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +00:00') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +00:00') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +00:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +00:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -00:00') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +00:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +00:00') +GO + +SELECT CONVERT(TIME, '11 AM -05:12') +GO + +SELECT CONVERT(TIME, '13 AM +05:12') +GO + +SELECT CONVERT(TIME, '11 PM -05:12') +GO + +SELECT CONVERT(TIME, '13 PM +05:12') +GO + +SELECT CONVERT(TIME, '24 PM -05:12') +GO + +SELECT CONVERT(TIME, '0 PM +05:12') +GO + +SELECT CONVERT(TIME, '0 AM -05:12') +GO + +SELECT CONVERT(TIME, '11AM +05:12') +GO + +SELECT CONVERT(TIME, ' 13AM -05:12') +GO + +SELECT CONVERT(TIME, '11PM +05:12') +GO + +SELECT CONVERT(TIME, '13PM -05:12') +GO + +SELECT CONVERT(TIME, '24PM +05:12') +GO + +SELECT CONVERT(TIME, '11 -05:12') +GO + +SELECT CONVERT(TIME, ' 11:22 +05:12') +GO + +SELECT CONVERT(TIME, '11:22 AM -05:12') +GO + +SELECT CONVERT(TIME, '11:22 PM +05:12') +GO + +SELECT CONVERT(TIME, '11:22.123 -05:12') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +05:12') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -05:12') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +05:12') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -05:12') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +05:12') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +05:12') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +05:12') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +05:12') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -05:12') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +05:12') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +05:12') +GO + +SELECT CONVERT(TIME, '11 AM -14:00') +GO + +SELECT CONVERT(TIME, '13 AM +14:00') +GO + +SELECT CONVERT(TIME, '11 PM -14:00') +GO + +SELECT CONVERT(TIME, '13 PM +14:00') +GO + +SELECT CONVERT(TIME, '24 PM -14:00') +GO + +SELECT CONVERT(TIME, '0 PM +14:00') +GO + +SELECT CONVERT(TIME, '0 AM -14:00') +GO + +SELECT CONVERT(TIME, '11AM +14:00') +GO + +SELECT CONVERT(TIME, ' 13AM -14:00') +GO + +SELECT CONVERT(TIME, '11PM +14:00') +GO + +SELECT CONVERT(TIME, '13PM -14:00') +GO + +SELECT CONVERT(TIME, '24PM +14:00') +GO + +SELECT CONVERT(TIME, '11 -14:00') +GO + +SELECT CONVERT(TIME, ' 11:22 +14:00') +GO + +SELECT CONVERT(TIME, '11:22 AM -14:00') +GO + +SELECT CONVERT(TIME, '11:22 PM +14:00') +GO + +SELECT CONVERT(TIME, '11:22.123 -14:00') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +14:00') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -14:00') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +14:00') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -14:00') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +14:00') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +14:00') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:00') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:00') +GO + +SELECT CONVERT(TIME, '11 AM -14:10') +GO + +SELECT CONVERT(TIME, '13 AM +14:10') +GO + +SELECT CONVERT(TIME, '11 PM -14:10') +GO + +SELECT CONVERT(TIME, '13 PM +14:10') +GO + +SELECT CONVERT(TIME, '24 PM -14:10') +GO + +SELECT CONVERT(TIME, '0 PM +14:10') +GO + +SELECT CONVERT(TIME, '0 AM -14:10') +GO + +SELECT CONVERT(TIME, '11AM +14:10') +GO + +SELECT CONVERT(TIME, ' 13AM -14:10') +GO + +SELECT CONVERT(TIME, '11PM +14:10') +GO + +SELECT CONVERT(TIME, '13PM -14:10') +GO + +SELECT CONVERT(TIME, '24PM +14:10') +GO + +SELECT CONVERT(TIME, '11 -14:10') +GO + +SELECT CONVERT(TIME, ' 11:22 +14:10') +GO + +SELECT CONVERT(TIME, '11:22 AM -14:10') +GO + +SELECT CONVERT(TIME, '11:22 PM +14:10') +GO + +SELECT CONVERT(TIME, '11:22.123 -14:10') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +14:10') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -14:10') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +14:10') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -14:10') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +14:10') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +14:10') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:10') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:10') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:10') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:10') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:10') +GO + +SELECT CONVERT(TIME, '11 AM Z') +GO + +SELECT CONVERT(TIME, '13 AM Z') +GO + +SELECT CONVERT(TIME, '11 PM Z') +GO + +SELECT CONVERT(TIME, '13 PM Z') +GO + +SELECT CONVERT(TIME, '24 PM Z') +GO + +SELECT CONVERT(TIME, '0 PM Z') +GO + +SELECT CONVERT(TIME, '0 AM Z') +GO + +SELECT CONVERT(TIME, '11AM Z') +GO + +SELECT CONVERT(TIME, ' 13AM Z') +GO + +SELECT CONVERT(TIME, '11PM Z') +GO + +SELECT CONVERT(TIME, '13PM Z') +GO + +SELECT CONVERT(TIME, '24PM Z') +GO + +SELECT CONVERT(TIME, '11Z') +GO + +SELECT CONVERT(TIME, ' 11:22 Z') +GO + +SELECT CONVERT(TIME, '11:22 AM Z') +GO + +SELECT CONVERT(TIME, '11:22 PM Z') +GO + +SELECT CONVERT(TIME, '11:22.123Z') +GO + +SELECT CONVERT(TIME, '11:22.123 AM Z') +GO + +SELECT CONVERT(TIME, '11:22.123 PM Z') +GO + +SELECT CONVERT(TIME, '11: 22 :12Z') +GO + +SELECT CONVERT(TIME, '11:22:12 AM Z') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM Z') +GO + +SELECT CONVERT(TIME, '11 :22:12:123Z') +GO + +SELECT CONVERT(TIME, '11:22:12:1234Z') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM Z') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM Z') +GO + +SELECT CONVERT(TIME, '11: 22:12.123Z') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234Z') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789Z') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891Z') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM Z') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM Z') +GO + +-- default value if only DATE is passed +SELECT CONVERT(TIME, '2000-04-22') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(TIME, '02/12/21', 1) +GO + +SELECT CONVERT(TIME, '21.02.12', 2) +GO + +SELECT CONVERT(TIME, '12/02/21', 3) +GO + +SELECT CONVERT(TIME, '12.02.21', 4) +GO + +SELECT CONVERT(TIME, '12-02-21', 5) +GO + +SELECT CONVERT(TIME, '12 Apr 21', 6) +GO + +SELECT CONVERT(TIME, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(TIME, '10:13:14', 8) +GO + +SELECT CONVERT(TIME, '10:13:14', 24) +GO + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(TIME, '02-12-21', 10) +GO + +SELECT CONVERT(TIME, '21/02/12', 11) +GO + +SELECT CONVERT(TIME, '210212', 12) +GO + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(TIME, '15:13:14:123', 14) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(TIME, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(TIME, '2021-02-12', 23) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(TIME, '02/12/2021', 101) +GO + +SELECT CONVERT(TIME, '2021.02.12', 102) +GO + +SELECT CONVERT(TIME, '12/02/2021', 103) +GO + +SELECT CONVERT(TIME, '12.02.2021', 104) +GO + +SELECT CONVERT(TIME, '12-02-2021', 105) +GO + +SELECT CONVERT(TIME, '12 Apr 2021', 106) +GO + +SELECT CONVERT(TIME, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(TIME, '10:13:14', 108) +GO + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(TIME, '02-12-2021', 110) +GO + +SELECT CONVERT(TIME, '2021/02/12', 111) +GO + +SELECT CONVERT(TIME, '20210212', 112) +GO + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(TIME, '15:13:14:123', 114) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(TIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(TIME, '12/02/2021 15:13:14:123 PM', 131) +GO + +-- -- misc +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(TIME, '2020') +GO + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(TIME, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(TIME, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(TIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(TIME, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(TIME, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(TIME, '2020') +GO + +SELECT CONVERT(TIME, '2022-10-30T03:00:00') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(TIME, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_time_v1 +GO +EXEC test_conv_string_to_time_p1 +GO +SELECT test_conv_string_to_time_f1() +GO + +SELECT * FROM test_conv_string_to_time_v2 +GO +EXEC test_conv_string_to_time_p2 +GO +SELECT test_conv_string_to_time_f2() +GO + +SELECT * FROM test_conv_string_to_time_v3 +GO +EXEC test_conv_string_to_time_p3 +GO +SELECT test_conv_string_to_time_f3() +GO + +SELECT * FROM test_conv_string_to_time_v4 +GO +EXEC test_conv_string_to_time_p4 +GO +SELECT test_conv_string_to_time_f4() +GO + +SELECT * FROM test_conv_string_to_time_v5 +GO +EXEC test_conv_string_to_time_p5 +GO +SELECT test_conv_string_to_time_f5() +GO + +SELECT * FROM test_conv_string_to_time_v6 +GO +EXEC test_conv_string_to_time_p6 +GO +SELECT test_conv_string_to_time_f6() +GO + +SELECT * FROM test_conv_string_to_time_v7 +GO +EXEC test_conv_string_to_time_p7 +GO +SELECT test_conv_string_to_time_f7() +GO + +SELECT * FROM test_conv_string_to_time_v8 +GO +EXEC test_conv_string_to_time_p8 +GO +SELECT test_conv_string_to_time_f8() +GO + +SELECT * FROM test_conv_string_to_time_v9 +GO +EXEC test_conv_string_to_time_p9 +GO +SELECT test_conv_string_to_time_f9() +GO + +SELECT * FROM test_conv_string_to_time_v10 +GO + +SELECT * FROM test_conv_string_to_time_v11 +GO + +SELECT * FROM test_conv_string_to_time_v12 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-cleanup.sql new file mode 100644 index 0000000000..a33d1bdadf --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-cleanup.sql @@ -0,0 +1,71 @@ +DROP VIEW test_conv_string_to_time_v1 +GO +DROP PROCEDURE test_conv_string_to_time_p1 +GO +DROP FUNCTION test_conv_string_to_time_f1() +GO + +DROP VIEW test_conv_string_to_time_v2 +GO +DROP PROCEDURE test_conv_string_to_time_p2 +GO +DROP FUNCTION test_conv_string_to_time_f2() +GO + +DROP VIEW test_conv_string_to_time_v3 +GO +DROP PROCEDURE test_conv_string_to_time_p3 +GO +DROP FUNCTION test_conv_string_to_time_f3() +GO + +DROP VIEW test_conv_string_to_time_v4 +GO +DROP PROCEDURE test_conv_string_to_time_p4 +GO +DROP FUNCTION test_conv_string_to_time_f4() +GO + +DROP VIEW test_conv_string_to_time_v5 +GO +DROP PROCEDURE test_conv_string_to_time_p5 +GO +DROP FUNCTION test_conv_string_to_time_f5() +GO + +DROP VIEW test_conv_string_to_time_v6 +GO +DROP PROCEDURE test_conv_string_to_time_p6 +GO +DROP FUNCTION test_conv_string_to_time_f6() +GO + +DROP VIEW test_conv_string_to_time_v7 +GO +DROP PROCEDURE test_conv_string_to_time_p7 +GO +DROP FUNCTION test_conv_string_to_time_f7() +GO + +DROP VIEW test_conv_string_to_time_v8 +GO +DROP PROCEDURE test_conv_string_to_time_p8 +GO +DROP FUNCTION test_conv_string_to_time_f8() +GO + +DROP VIEW test_conv_string_to_time_v9 +GO +DROP PROCEDURE test_conv_string_to_time_p9 +GO +DROP FUNCTION test_conv_string_to_time_f9() +GO + +DROP VIEW test_conv_string_to_time_v10 +GO + +DROP VIEW test_conv_string_to_time_v11 +GO + +DROP VIEW test_conv_string_to_time_v12 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-prepare.sql new file mode 100644 index 0000000000..cc5596c91d --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-prepare.sql @@ -0,0 +1,107 @@ +CREATE VIEW test_conv_string_to_time_v1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_time_p1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_time_f1() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_time_v2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE PROCEDURE test_conv_string_to_time_p2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE FUNCTION test_conv_string_to_time_f2() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '00:00:00')); +END +GO + +CREATE VIEW test_conv_string_to_time_v3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE PROCEDURE test_conv_string_to_time_p3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE FUNCTION test_conv_string_to_time_f3() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '1:1:1')); +END +GO + +CREATE VIEW test_conv_string_to_time_v4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_time_p4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_time_f4() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_time_v5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f5() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f6() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f7() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_time_p8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_time_f8() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_time_v9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f9() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v10 as (SELECT CONVERT(time, '02-03-2003 11:11:11 +11:11')); +GO + +CREATE VIEW test_conv_string_to_time_v11 as (SELECT CONVERT(time, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)))); +GO + +CREATE VIEW test_conv_string_to_time_v12 as (SELECT CONVERT(time, CAST('20' as INTEGER))); +GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-verify.sql new file mode 100644 index 0000000000..7b31f9c866 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_time-before-17_3-vu-verify.sql @@ -0,0 +1,920 @@ +-- Empty string, should return default values +SELECT CONVERT(TIME, '') +GO + +SELECT CONVERT(TIME, '', 130) +GO + +SELECT CONVERT(TIME, '11 AM') +GO + +SELECT CONVERT(TIME, '13 AM') +GO + +SELECT CONVERT(TIME, '11 PM') +GO + +SELECT CONVERT(TIME, '13 PM') +GO + +SELECT CONVERT(TIME, '24 PM') +GO + +SELECT CONVERT(TIME, '0 PM') +GO + +SELECT CONVERT(TIME, '0 AM') +GO + +SELECT CONVERT(TIME, '11AM ') +GO + +SELECT CONVERT(TIME, ' 13AM') +GO + +SELECT CONVERT(TIME, '11PM') +GO + +SELECT CONVERT(TIME, '13PM') +GO + +SELECT CONVERT(TIME, '24PM') +GO + +SELECT CONVERT(TIME, '11') +GO + +SELECT CONVERT(TIME, ' 11:22 ') +GO + +SELECT CONVERT(TIME, '11:22 AM') +GO + +SELECT CONVERT(TIME, '11:22 PM') +GO + +SELECT CONVERT(TIME, '11:22.123') +GO + +SELECT CONVERT(TIME, '11:22.123 AM') +GO + +SELECT CONVERT(TIME, '11:22.123 PM') +GO + +SELECT CONVERT(TIME, '11: 22 :12') +GO + +SELECT CONVERT(TIME, '11:22:12 AM') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM') +GO + +SELECT CONVERT(TIME, '11 :22:12:123') +GO + +SELECT CONVERT(TIME, '11:22:12:1234') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM') +GO + +SELECT CONVERT(TIME, '11: 22:12.123') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM') +GO + +-- TIME with typmod +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.501') +GO + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.500') +GO + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.499') +GO + +SELECT CONVERT(TIME(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(TIME(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(TIME(3), '01/01/98 23:59:59.123') +GO + +-- -- rounding of minutes or fractional seconds +SELECT CONVERT(TIME, '11:22:12.12345675') +GO + +SELECT CONVERT(TIME, '11:22:12.12345674') +GO + +-- -- Boundary values +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999') +GO + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.99999999') +GO + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.999999999') +GO + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.99999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.999999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999999') +GO + +SELECT CONVERT(TIME, '11:22:12.129') +GO + +SELECT CONVERT(TIME, '11:22:12.128') +GO + +SELECT CONVERT(TIME, '11:22:12.127') +GO + +SELECT CONVERT(TIME, '11:22:12.126') +GO + +SELECT CONVERT(TIME, '11:22:12.125') +GO + +SELECT CONVERT(TIME, '11:22:12.124') +GO + +SELECT CONVERT(TIME, '11:22:12.123') +GO + +SELECT CONVERT(TIME, '11:22:12.122') +GO + +SELECT CONVERT(TIME, '11:22:12.121') +GO + +SELECT CONVERT(TIME, '11:22:12.120') +GO + +SELECT CONVERT(TIME, '11:22:29') +GO + +SELECT CONVERT(TIME, '11:22:30') +GO + +SELECT CONVERT(TIME, '11 AM +00:00') +GO + +SELECT CONVERT(TIME, '13 AM -00:00') +GO + +SELECT CONVERT(TIME, '11 PM +00:00') +GO + +SELECT CONVERT(TIME, '13 PM -00:00') +GO + +SELECT CONVERT(TIME, '24 PM +00:00') +GO + +SELECT CONVERT(TIME, '0 PM -00:00') +GO + +SELECT CONVERT(TIME, '0 AM +00:00') +GO + +SELECT CONVERT(TIME, '11AM -00:00') +GO + +SELECT CONVERT(TIME, ' 13AM +00:00') +GO + +SELECT CONVERT(TIME, '11PM -00:00') +GO + +SELECT CONVERT(TIME, '13PM +00:00') +GO + +SELECT CONVERT(TIME, '24PM -00:00') +GO + +SELECT CONVERT(TIME, '11 +00:00') +GO + +SELECT CONVERT(TIME, ' 11:22 -00:00') +GO + +SELECT CONVERT(TIME, '11:22 AM -00:00') +GO + +SELECT CONVERT(TIME, '11:22 PM +00:00') +GO + +SELECT CONVERT(TIME, '11:22.123 -00:00') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +00:00') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -00:00') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +00:00') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -00:00') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +00:00') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +00:00') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +00:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +00:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -00:00') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +00:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +00:00') +GO + +SELECT CONVERT(TIME, '11 AM -05:12') +GO + +SELECT CONVERT(TIME, '13 AM +05:12') +GO + +SELECT CONVERT(TIME, '11 PM -05:12') +GO + +SELECT CONVERT(TIME, '13 PM +05:12') +GO + +SELECT CONVERT(TIME, '24 PM -05:12') +GO + +SELECT CONVERT(TIME, '0 PM +05:12') +GO + +SELECT CONVERT(TIME, '0 AM -05:12') +GO + +SELECT CONVERT(TIME, '11AM +05:12') +GO + +SELECT CONVERT(TIME, ' 13AM -05:12') +GO + +SELECT CONVERT(TIME, '11PM +05:12') +GO + +SELECT CONVERT(TIME, '13PM -05:12') +GO + +SELECT CONVERT(TIME, '24PM +05:12') +GO + +SELECT CONVERT(TIME, '11 -05:12') +GO + +SELECT CONVERT(TIME, ' 11:22 +05:12') +GO + +SELECT CONVERT(TIME, '11:22 AM -05:12') +GO + +SELECT CONVERT(TIME, '11:22 PM +05:12') +GO + +SELECT CONVERT(TIME, '11:22.123 -05:12') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +05:12') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -05:12') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +05:12') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -05:12') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +05:12') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +05:12') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +05:12') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +05:12') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -05:12') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +05:12') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +05:12') +GO + +SELECT CONVERT(TIME, '11 AM -14:00') +GO + +SELECT CONVERT(TIME, '13 AM +14:00') +GO + +SELECT CONVERT(TIME, '11 PM -14:00') +GO + +SELECT CONVERT(TIME, '13 PM +14:00') +GO + +SELECT CONVERT(TIME, '24 PM -14:00') +GO + +SELECT CONVERT(TIME, '0 PM +14:00') +GO + +SELECT CONVERT(TIME, '0 AM -14:00') +GO + +SELECT CONVERT(TIME, '11AM +14:00') +GO + +SELECT CONVERT(TIME, ' 13AM -14:00') +GO + +SELECT CONVERT(TIME, '11PM +14:00') +GO + +SELECT CONVERT(TIME, '13PM -14:00') +GO + +SELECT CONVERT(TIME, '24PM +14:00') +GO + +SELECT CONVERT(TIME, '11 -14:00') +GO + +SELECT CONVERT(TIME, ' 11:22 +14:00') +GO + +SELECT CONVERT(TIME, '11:22 AM -14:00') +GO + +SELECT CONVERT(TIME, '11:22 PM +14:00') +GO + +SELECT CONVERT(TIME, '11:22.123 -14:00') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +14:00') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -14:00') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +14:00') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -14:00') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +14:00') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +14:00') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:00') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:00') +GO + +SELECT CONVERT(TIME, '11 AM -14:10') +GO + +SELECT CONVERT(TIME, '13 AM +14:10') +GO + +SELECT CONVERT(TIME, '11 PM -14:10') +GO + +SELECT CONVERT(TIME, '13 PM +14:10') +GO + +SELECT CONVERT(TIME, '24 PM -14:10') +GO + +SELECT CONVERT(TIME, '0 PM +14:10') +GO + +SELECT CONVERT(TIME, '0 AM -14:10') +GO + +SELECT CONVERT(TIME, '11AM +14:10') +GO + +SELECT CONVERT(TIME, ' 13AM -14:10') +GO + +SELECT CONVERT(TIME, '11PM +14:10') +GO + +SELECT CONVERT(TIME, '13PM -14:10') +GO + +SELECT CONVERT(TIME, '24PM +14:10') +GO + +SELECT CONVERT(TIME, '11 -14:10') +GO + +SELECT CONVERT(TIME, ' 11:22 +14:10') +GO + +SELECT CONVERT(TIME, '11:22 AM -14:10') +GO + +SELECT CONVERT(TIME, '11:22 PM +14:10') +GO + +SELECT CONVERT(TIME, '11:22.123 -14:10') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +14:10') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -14:10') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +14:10') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -14:10') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +14:10') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +14:10') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:10') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:10') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:10') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:10') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:10') +GO + +SELECT CONVERT(TIME, '11 AM Z') +GO + +SELECT CONVERT(TIME, '13 AM Z') +GO + +SELECT CONVERT(TIME, '11 PM Z') +GO + +SELECT CONVERT(TIME, '13 PM Z') +GO + +SELECT CONVERT(TIME, '24 PM Z') +GO + +SELECT CONVERT(TIME, '0 PM Z') +GO + +SELECT CONVERT(TIME, '0 AM Z') +GO + +SELECT CONVERT(TIME, '11AM Z') +GO + +SELECT CONVERT(TIME, ' 13AM Z') +GO + +SELECT CONVERT(TIME, '11PM Z') +GO + +SELECT CONVERT(TIME, '13PM Z') +GO + +SELECT CONVERT(TIME, '24PM Z') +GO + +SELECT CONVERT(TIME, '11Z') +GO + +SELECT CONVERT(TIME, ' 11:22 Z') +GO + +SELECT CONVERT(TIME, '11:22 AM Z') +GO + +SELECT CONVERT(TIME, '11:22 PM Z') +GO + +SELECT CONVERT(TIME, '11:22.123Z') +GO + +SELECT CONVERT(TIME, '11:22.123 AM Z') +GO + +SELECT CONVERT(TIME, '11:22.123 PM Z') +GO + +SELECT CONVERT(TIME, '11: 22 :12Z') +GO + +SELECT CONVERT(TIME, '11:22:12 AM Z') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM Z') +GO + +SELECT CONVERT(TIME, '11 :22:12:123Z') +GO + +SELECT CONVERT(TIME, '11:22:12:1234Z') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM Z') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM Z') +GO + +SELECT CONVERT(TIME, '11: 22:12.123Z') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234Z') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789Z') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891Z') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM Z') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM Z') +GO + +-- default value if only DATE is passed +SELECT CONVERT(TIME, '2000-04-22') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(TIME, '02/12/21', 1) +GO + +SELECT CONVERT(TIME, '21.02.12', 2) +GO + +SELECT CONVERT(TIME, '12/02/21', 3) +GO + +SELECT CONVERT(TIME, '12.02.21', 4) +GO + +SELECT CONVERT(TIME, '12-02-21', 5) +GO + +SELECT CONVERT(TIME, '12 Apr 21', 6) +GO + +SELECT CONVERT(TIME, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(TIME, '10:13:14', 8) +GO + +SELECT CONVERT(TIME, '10:13:14', 24) +GO + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(TIME, '02-12-21', 10) +GO + +SELECT CONVERT(TIME, '21/02/12', 11) +GO + +SELECT CONVERT(TIME, '210212', 12) +GO + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(TIME, '15:13:14:123', 14) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(TIME, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(TIME, '2021-02-12', 23) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(TIME, '02/12/2021', 101) +GO + +SELECT CONVERT(TIME, '2021.02.12', 102) +GO + +SELECT CONVERT(TIME, '12/02/2021', 103) +GO + +SELECT CONVERT(TIME, '12.02.2021', 104) +GO + +SELECT CONVERT(TIME, '12-02-2021', 105) +GO + +SELECT CONVERT(TIME, '12 Apr 2021', 106) +GO + +SELECT CONVERT(TIME, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(TIME, '10:13:14', 108) +GO + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(TIME, '02-12-2021', 110) +GO + +SELECT CONVERT(TIME, '2021/02/12', 111) +GO + +SELECT CONVERT(TIME, '20210212', 112) +GO + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(TIME, '15:13:14:123', 114) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(TIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(TIME, '12/02/2021 15:13:14:123 PM', 131) +GO + +-- -- misc +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(TIME, '2020') +GO + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(TIME, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(TIME, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(TIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(TIME, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(TIME, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(TIME, '2020') +GO + +SELECT CONVERT(TIME, '2022-10-30T03:00:00') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(TIME, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_time_v1 +GO +EXEC test_conv_string_to_time_p1 +GO +SELECT test_conv_string_to_time_f1() +GO + +SELECT * FROM test_conv_string_to_time_v2 +GO +EXEC test_conv_string_to_time_p2 +GO +SELECT test_conv_string_to_time_f2() +GO + +SELECT * FROM test_conv_string_to_time_v3 +GO +EXEC test_conv_string_to_time_p3 +GO +SELECT test_conv_string_to_time_f3() +GO + +SELECT * FROM test_conv_string_to_time_v4 +GO +EXEC test_conv_string_to_time_p4 +GO +SELECT test_conv_string_to_time_f4() +GO + +SELECT * FROM test_conv_string_to_time_v5 +GO +EXEC test_conv_string_to_time_p5 +GO +SELECT test_conv_string_to_time_f5() +GO + +SELECT * FROM test_conv_string_to_time_v6 +GO +EXEC test_conv_string_to_time_p6 +GO +SELECT test_conv_string_to_time_f6() +GO + +SELECT * FROM test_conv_string_to_time_v7 +GO +EXEC test_conv_string_to_time_p7 +GO +SELECT test_conv_string_to_time_f7() +GO + +SELECT * FROM test_conv_string_to_time_v8 +GO +EXEC test_conv_string_to_time_p8 +GO +SELECT test_conv_string_to_time_f8() +GO + +SELECT * FROM test_conv_string_to_time_v9 +GO +EXEC test_conv_string_to_time_p9 +GO +SELECT test_conv_string_to_time_f9() +GO + +SELECT * FROM test_conv_string_to_time_v10 +GO + +SELECT * FROM test_conv_string_to_time_v11 +GO + +SELECT * FROM test_conv_string_to_time_v12 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_time-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_time-vu-cleanup.sql new file mode 100644 index 0000000000..a33d1bdadf --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_time-vu-cleanup.sql @@ -0,0 +1,71 @@ +DROP VIEW test_conv_string_to_time_v1 +GO +DROP PROCEDURE test_conv_string_to_time_p1 +GO +DROP FUNCTION test_conv_string_to_time_f1() +GO + +DROP VIEW test_conv_string_to_time_v2 +GO +DROP PROCEDURE test_conv_string_to_time_p2 +GO +DROP FUNCTION test_conv_string_to_time_f2() +GO + +DROP VIEW test_conv_string_to_time_v3 +GO +DROP PROCEDURE test_conv_string_to_time_p3 +GO +DROP FUNCTION test_conv_string_to_time_f3() +GO + +DROP VIEW test_conv_string_to_time_v4 +GO +DROP PROCEDURE test_conv_string_to_time_p4 +GO +DROP FUNCTION test_conv_string_to_time_f4() +GO + +DROP VIEW test_conv_string_to_time_v5 +GO +DROP PROCEDURE test_conv_string_to_time_p5 +GO +DROP FUNCTION test_conv_string_to_time_f5() +GO + +DROP VIEW test_conv_string_to_time_v6 +GO +DROP PROCEDURE test_conv_string_to_time_p6 +GO +DROP FUNCTION test_conv_string_to_time_f6() +GO + +DROP VIEW test_conv_string_to_time_v7 +GO +DROP PROCEDURE test_conv_string_to_time_p7 +GO +DROP FUNCTION test_conv_string_to_time_f7() +GO + +DROP VIEW test_conv_string_to_time_v8 +GO +DROP PROCEDURE test_conv_string_to_time_p8 +GO +DROP FUNCTION test_conv_string_to_time_f8() +GO + +DROP VIEW test_conv_string_to_time_v9 +GO +DROP PROCEDURE test_conv_string_to_time_p9 +GO +DROP FUNCTION test_conv_string_to_time_f9() +GO + +DROP VIEW test_conv_string_to_time_v10 +GO + +DROP VIEW test_conv_string_to_time_v11 +GO + +DROP VIEW test_conv_string_to_time_v12 +GO diff --git a/test/JDBC/input/functions/test_conv_string_to_time-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_time-vu-prepare.sql new file mode 100644 index 0000000000..cc5596c91d --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_time-vu-prepare.sql @@ -0,0 +1,107 @@ +CREATE VIEW test_conv_string_to_time_v1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE PROCEDURE test_conv_string_to_time_p1 as (SELECT CONVERT(time, '13:01:59')); +GO +CREATE FUNCTION test_conv_string_to_time_f1() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '13:01:59')); +END +GO + +CREATE VIEW test_conv_string_to_time_v2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE PROCEDURE test_conv_string_to_time_p2 as (SELECT CONVERT(time, '00:00:00')); +GO +CREATE FUNCTION test_conv_string_to_time_f2() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '00:00:00')); +END +GO + +CREATE VIEW test_conv_string_to_time_v3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE PROCEDURE test_conv_string_to_time_p3 as (SELECT CONVERT(time, '1:1:1')); +GO +CREATE FUNCTION test_conv_string_to_time_f3() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, '1:1:1')); +END +GO + +CREATE VIEW test_conv_string_to_time_v4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE PROCEDURE test_conv_string_to_time_p4 as (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +GO +CREATE FUNCTION test_conv_string_to_time_f4() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS TEXT))); +END +GO + +CREATE VIEW test_conv_string_to_time_v5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p5 as (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f5() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS CHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p6 as (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f6() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p7 as (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f7() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS NVARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE PROCEDURE test_conv_string_to_time_p8 as (SELECT CONVERT(time, CAST('13' AS INTEGER))); +GO +CREATE FUNCTION test_conv_string_to_time_f8() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13' AS INTEGER))); +END +GO + +CREATE VIEW test_conv_string_to_time_v9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE PROCEDURE test_conv_string_to_time_p9 as (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +GO +CREATE FUNCTION test_conv_string_to_time_f9() +RETURNS time AS +BEGIN +RETURN (SELECT CONVERT(time, CAST('13:01:59' AS VARCHAR(10)))); +END +GO + +CREATE VIEW test_conv_string_to_time_v10 as (SELECT CONVERT(time, '02-03-2003 11:11:11 +11:11')); +GO + +CREATE VIEW test_conv_string_to_time_v11 as (SELECT CONVERT(time, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)))); +GO + +CREATE VIEW test_conv_string_to_time_v12 as (SELECT CONVERT(time, CAST('20' as INTEGER))); +GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_time-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_time-vu-verify.sql new file mode 100644 index 0000000000..bf7fb2f8dd --- /dev/null +++ b/test/JDBC/input/functions/test_conv_string_to_time-vu-verify.sql @@ -0,0 +1,921 @@ +-- sla 70000 +-- Empty string, should return default values +SELECT CONVERT(TIME, '') +GO + +SELECT CONVERT(TIME, '', 130) +GO + +SELECT CONVERT(TIME, '11 AM') +GO + +SELECT CONVERT(TIME, '13 AM') +GO + +SELECT CONVERT(TIME, '11 PM') +GO + +SELECT CONVERT(TIME, '13 PM') +GO + +SELECT CONVERT(TIME, '24 PM') +GO + +SELECT CONVERT(TIME, '0 PM') +GO + +SELECT CONVERT(TIME, '0 AM') +GO + +SELECT CONVERT(TIME, '11AM ') +GO + +SELECT CONVERT(TIME, ' 13AM') +GO + +SELECT CONVERT(TIME, '11PM') +GO + +SELECT CONVERT(TIME, '13PM') +GO + +SELECT CONVERT(TIME, '24PM') +GO + +SELECT CONVERT(TIME, '11') +GO + +SELECT CONVERT(TIME, ' 11:22 ') +GO + +SELECT CONVERT(TIME, '11:22 AM') +GO + +SELECT CONVERT(TIME, '11:22 PM') +GO + +SELECT CONVERT(TIME, '11:22.123') +GO + +SELECT CONVERT(TIME, '11:22.123 AM') +GO + +SELECT CONVERT(TIME, '11:22.123 PM') +GO + +SELECT CONVERT(TIME, '11: 22 :12') +GO + +SELECT CONVERT(TIME, '11:22:12 AM') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM') +GO + +SELECT CONVERT(TIME, '11 :22:12:123') +GO + +SELECT CONVERT(TIME, '11:22:12:1234') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM') +GO + +SELECT CONVERT(TIME, '11: 22:12.123') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM') +GO + +-- TIME with typmod +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.501') +GO + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.500') +GO + +SELECT CONVERT(TIME(0), '01/01/98 23:59:56.499') +GO + +SELECT CONVERT(TIME(1), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(TIME(2), '01/01/98 23:59:59.123') +GO + +SELECT CONVERT(TIME(3), '01/01/98 23:59:59.123') +GO + +-- -- rounding of minutes or fractional seconds +SELECT CONVERT(TIME, '11:22:12.12345675') +GO + +SELECT CONVERT(TIME, '11:22:12.12345674') +GO + +-- -- Boundary values +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999') +GO + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.99999999') +GO + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.999999999') +GO + +SELECT CONVERT(TIME, '9999-12-30 23:59:59.9999999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.99999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.999999999') +GO + +SELECT CONVERT(TIME, '9999-12-31 23:59:59.9999999999') +GO + +SELECT CONVERT(TIME, '11:22:12.129') +GO + +SELECT CONVERT(TIME, '11:22:12.128') +GO + +SELECT CONVERT(TIME, '11:22:12.127') +GO + +SELECT CONVERT(TIME, '11:22:12.126') +GO + +SELECT CONVERT(TIME, '11:22:12.125') +GO + +SELECT CONVERT(TIME, '11:22:12.124') +GO + +SELECT CONVERT(TIME, '11:22:12.123') +GO + +SELECT CONVERT(TIME, '11:22:12.122') +GO + +SELECT CONVERT(TIME, '11:22:12.121') +GO + +SELECT CONVERT(TIME, '11:22:12.120') +GO + +SELECT CONVERT(TIME, '11:22:29') +GO + +SELECT CONVERT(TIME, '11:22:30') +GO + +SELECT CONVERT(TIME, '11 AM +00:00') +GO + +SELECT CONVERT(TIME, '13 AM -00:00') +GO + +SELECT CONVERT(TIME, '11 PM +00:00') +GO + +SELECT CONVERT(TIME, '13 PM -00:00') +GO + +SELECT CONVERT(TIME, '24 PM +00:00') +GO + +SELECT CONVERT(TIME, '0 PM -00:00') +GO + +SELECT CONVERT(TIME, '0 AM +00:00') +GO + +SELECT CONVERT(TIME, '11AM -00:00') +GO + +SELECT CONVERT(TIME, ' 13AM +00:00') +GO + +SELECT CONVERT(TIME, '11PM -00:00') +GO + +SELECT CONVERT(TIME, '13PM +00:00') +GO + +SELECT CONVERT(TIME, '24PM -00:00') +GO + +SELECT CONVERT(TIME, '11 +00:00') +GO + +SELECT CONVERT(TIME, ' 11:22 -00:00') +GO + +SELECT CONVERT(TIME, '11:22 AM -00:00') +GO + +SELECT CONVERT(TIME, '11:22 PM +00:00') +GO + +SELECT CONVERT(TIME, '11:22.123 -00:00') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +00:00') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -00:00') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +00:00') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -00:00') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +00:00') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +00:00') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +00:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +00:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -00:00') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +00:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -00:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +00:00') +GO + +SELECT CONVERT(TIME, '11 AM -05:12') +GO + +SELECT CONVERT(TIME, '13 AM +05:12') +GO + +SELECT CONVERT(TIME, '11 PM -05:12') +GO + +SELECT CONVERT(TIME, '13 PM +05:12') +GO + +SELECT CONVERT(TIME, '24 PM -05:12') +GO + +SELECT CONVERT(TIME, '0 PM +05:12') +GO + +SELECT CONVERT(TIME, '0 AM -05:12') +GO + +SELECT CONVERT(TIME, '11AM +05:12') +GO + +SELECT CONVERT(TIME, ' 13AM -05:12') +GO + +SELECT CONVERT(TIME, '11PM +05:12') +GO + +SELECT CONVERT(TIME, '13PM -05:12') +GO + +SELECT CONVERT(TIME, '24PM +05:12') +GO + +SELECT CONVERT(TIME, '11 -05:12') +GO + +SELECT CONVERT(TIME, ' 11:22 +05:12') +GO + +SELECT CONVERT(TIME, '11:22 AM -05:12') +GO + +SELECT CONVERT(TIME, '11:22 PM +05:12') +GO + +SELECT CONVERT(TIME, '11:22.123 -05:12') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +05:12') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -05:12') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +05:12') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -05:12') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +05:12') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +05:12') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +05:12') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +05:12') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -05:12') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +05:12') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -05:12') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +05:12') +GO + +SELECT CONVERT(TIME, '11 AM -14:00') +GO + +SELECT CONVERT(TIME, '13 AM +14:00') +GO + +SELECT CONVERT(TIME, '11 PM -14:00') +GO + +SELECT CONVERT(TIME, '13 PM +14:00') +GO + +SELECT CONVERT(TIME, '24 PM -14:00') +GO + +SELECT CONVERT(TIME, '0 PM +14:00') +GO + +SELECT CONVERT(TIME, '0 AM -14:00') +GO + +SELECT CONVERT(TIME, '11AM +14:00') +GO + +SELECT CONVERT(TIME, ' 13AM -14:00') +GO + +SELECT CONVERT(TIME, '11PM +14:00') +GO + +SELECT CONVERT(TIME, '13PM -14:00') +GO + +SELECT CONVERT(TIME, '24PM +14:00') +GO + +SELECT CONVERT(TIME, '11 -14:00') +GO + +SELECT CONVERT(TIME, ' 11:22 +14:00') +GO + +SELECT CONVERT(TIME, '11:22 AM -14:00') +GO + +SELECT CONVERT(TIME, '11:22 PM +14:00') +GO + +SELECT CONVERT(TIME, '11:22.123 -14:00') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +14:00') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -14:00') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +14:00') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -14:00') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +14:00') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +14:00') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:00') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:00') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:00') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:00') +GO + +SELECT CONVERT(TIME, '11 AM -14:10') +GO + +SELECT CONVERT(TIME, '13 AM +14:10') +GO + +SELECT CONVERT(TIME, '11 PM -14:10') +GO + +SELECT CONVERT(TIME, '13 PM +14:10') +GO + +SELECT CONVERT(TIME, '24 PM -14:10') +GO + +SELECT CONVERT(TIME, '0 PM +14:10') +GO + +SELECT CONVERT(TIME, '0 AM -14:10') +GO + +SELECT CONVERT(TIME, '11AM +14:10') +GO + +SELECT CONVERT(TIME, ' 13AM -14:10') +GO + +SELECT CONVERT(TIME, '11PM +14:10') +GO + +SELECT CONVERT(TIME, '13PM -14:10') +GO + +SELECT CONVERT(TIME, '24PM +14:10') +GO + +SELECT CONVERT(TIME, '11 -14:10') +GO + +SELECT CONVERT(TIME, ' 11:22 +14:10') +GO + +SELECT CONVERT(TIME, '11:22 AM -14:10') +GO + +SELECT CONVERT(TIME, '11:22 PM +14:10') +GO + +SELECT CONVERT(TIME, '11:22.123 -14:10') +GO + +SELECT CONVERT(TIME, '11:22.123 AM +14:10') +GO + +SELECT CONVERT(TIME, '11:22.123 PM -14:10') +GO + +SELECT CONVERT(TIME, '11: 22 :12 +14:10') +GO + +SELECT CONVERT(TIME, '11:22:12 AM -14:10') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM +14:10') +GO + +SELECT CONVERT(TIME, '11 :22:12:123 -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12:1234 +14:10') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM +14:10') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234 +14:10') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789 -14:10') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891 +14:10') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM -14:10') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM +14:10') +GO + +SELECT CONVERT(TIME, '11 AM Z') +GO + +SELECT CONVERT(TIME, '13 AM Z') +GO + +SELECT CONVERT(TIME, '11 PM Z') +GO + +SELECT CONVERT(TIME, '13 PM Z') +GO + +SELECT CONVERT(TIME, '24 PM Z') +GO + +SELECT CONVERT(TIME, '0 PM Z') +GO + +SELECT CONVERT(TIME, '0 AM Z') +GO + +SELECT CONVERT(TIME, '11AM Z') +GO + +SELECT CONVERT(TIME, ' 13AM Z') +GO + +SELECT CONVERT(TIME, '11PM Z') +GO + +SELECT CONVERT(TIME, '13PM Z') +GO + +SELECT CONVERT(TIME, '24PM Z') +GO + +SELECT CONVERT(TIME, '11Z') +GO + +SELECT CONVERT(TIME, ' 11:22 Z') +GO + +SELECT CONVERT(TIME, '11:22 AM Z') +GO + +SELECT CONVERT(TIME, '11:22 PM Z') +GO + +SELECT CONVERT(TIME, '11:22.123Z') +GO + +SELECT CONVERT(TIME, '11:22.123 AM Z') +GO + +SELECT CONVERT(TIME, '11:22.123 PM Z') +GO + +SELECT CONVERT(TIME, '11: 22 :12Z') +GO + +SELECT CONVERT(TIME, '11:22:12 AM Z') +GO + +SELECT CONVERT(TIME, '11: 22:12 PM Z') +GO + +SELECT CONVERT(TIME, '11 :22:12:123Z') +GO + +SELECT CONVERT(TIME, '11:22:12:1234Z') +GO + +SELECT CONVERT(TIME, '11:22:12:123 AM Z') +GO + +SELECT CONVERT(TIME, '11:22:12 :123 PM Z') +GO + +SELECT CONVERT(TIME, '11: 22:12.123Z') +GO + +SELECT CONVERT(TIME, '11:22:12. 1234Z') +GO + +SELECT CONVERT(TIME, '11:22:12. 123456789Z') +GO + +SELECT CONVERT(TIME, '11:22 :12.1234567891Z') +GO + +SELECT CONVERT(TIME, '11: 22:12.123 AM Z') +GO + +SELECT CONVERT(TIME, '11:22:12. 123234 PM Z') +GO + +-- default value if only DATE is passed +SELECT CONVERT(TIME, '2000-04-22') +GO + +-- Different DATETIME formats with their corresponding styles +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 0) +GO + +SELECT CONVERT(TIME, '02/12/21', 1) +GO + +SELECT CONVERT(TIME, '21.02.12', 2) +GO + +SELECT CONVERT(TIME, '12/02/21', 3) +GO + +SELECT CONVERT(TIME, '12.02.21', 4) +GO + +SELECT CONVERT(TIME, '12-02-21', 5) +GO + +SELECT CONVERT(TIME, '12 Apr 21', 6) +GO + +SELECT CONVERT(TIME, 'Apr 12, 21', 7) +GO + +SELECT CONVERT(TIME, '10:13:14', 8) +GO + +SELECT CONVERT(TIME, '10:13:14', 24) +GO + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 9) +GO + +SELECT CONVERT(TIME, '02-12-21', 10) +GO + +SELECT CONVERT(TIME, '21/02/12', 11) +GO + +SELECT CONVERT(TIME, '210212', 12) +GO + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 13) +GO + +SELECT CONVERT(TIME, '15:13:14:123', 14) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 20) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 21) +GO + +SELECT CONVERT(TIME, '02/12/21 15:13:14 PM', 22) +GO + +SELECT CONVERT(TIME, '2021-02-12', 23) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 25) +GO + +SELECT CONVERT(TIME, 'Apr 10 2021 11:12AM', 100) +GO + +SELECT CONVERT(TIME, '02/12/2021', 101) +GO + +SELECT CONVERT(TIME, '2021.02.12', 102) +GO + +SELECT CONVERT(TIME, '12/02/2021', 103) +GO + +SELECT CONVERT(TIME, '12.02.2021', 104) +GO + +SELECT CONVERT(TIME, '12-02-2021', 105) +GO + +SELECT CONVERT(TIME, '12 Apr 2021', 106) +GO + +SELECT CONVERT(TIME, 'Apr 12, 2021', 107) +GO + +SELECT CONVERT(TIME, '10:13:14', 108) +GO + +SELECT CONVERT(TIME, 'Apr 12 2021 10:13:14:123AM', 109) +GO + +SELECT CONVERT(TIME, '02-12-2021', 110) +GO + +SELECT CONVERT(TIME, '2021/02/12', 111) +GO + +SELECT CONVERT(TIME, '20210212', 112) +GO + +SELECT CONVERT(TIME, '12 Apr 2021 15:13:14:123', 113) +GO + +SELECT CONVERT(TIME, '15:13:14:123', 114) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14', 120) +GO + +SELECT CONVERT(TIME, '2021-02-12 15:13:14.123', 121) +GO + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 126) +GO + +SELECT CONVERT(TIME, '2021-02-12T15:13:14.123', 127) +GO + +SELECT CONVERT(TIME, N'22 محرم 1440 1:39:17.090', 130) +GO + +SELECT CONVERT(TIME, '12/02/2021 15:13:14:123 PM', 131) +GO + +-- -- misc +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(TIME, '2020') +GO + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(TIME, '2000-04-22 16:23:51.7668c0') +GO + +SELECT CONVERT(TIME, '2001-04-022 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(TIME, '02001-04-22 16:23:51.766890 +12:00') +GO + +SELECT CONVERT(TIME, ' 2001- 04 - 22 16: 23: 51. 766890 +12:00') +GO + +SELECT CONVERT(TIME, '02001-04-22 16:23:51') +GO + +SELECT CONVERT(TIME, '1900-05-06 13:59:29.050 -8:00') +GO + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(TIME, '2011-08-15 14:30.00') +GO + +SELECT CONVERT(TIME,'2022-10-29 20:01:00.000') +GO + +SELECT CONVERT(TIME, '2020') +GO + +SELECT CONVERT(TIME, '2022-10-30T03:00:00') +GO + +DECLARE @TM_ICLO TIME = '17:24:07.1766670' +SELECT CONVERT(TIME, @TM_ICLO) +GO + +-- Dependent objects +SELECT * FROM test_conv_string_to_time_v1 +GO +EXEC test_conv_string_to_time_p1 +GO +SELECT test_conv_string_to_time_f1() +GO + +SELECT * FROM test_conv_string_to_time_v2 +GO +EXEC test_conv_string_to_time_p2 +GO +SELECT test_conv_string_to_time_f2() +GO + +SELECT * FROM test_conv_string_to_time_v3 +GO +EXEC test_conv_string_to_time_p3 +GO +SELECT test_conv_string_to_time_f3() +GO + +SELECT * FROM test_conv_string_to_time_v4 +GO +EXEC test_conv_string_to_time_p4 +GO +SELECT test_conv_string_to_time_f4() +GO + +SELECT * FROM test_conv_string_to_time_v5 +GO +EXEC test_conv_string_to_time_p5 +GO +SELECT test_conv_string_to_time_f5() +GO + +SELECT * FROM test_conv_string_to_time_v6 +GO +EXEC test_conv_string_to_time_p6 +GO +SELECT test_conv_string_to_time_f6() +GO + +SELECT * FROM test_conv_string_to_time_v7 +GO +EXEC test_conv_string_to_time_p7 +GO +SELECT test_conv_string_to_time_f7() +GO + +SELECT * FROM test_conv_string_to_time_v8 +GO +EXEC test_conv_string_to_time_p8 +GO +SELECT test_conv_string_to_time_f8() +GO + +SELECT * FROM test_conv_string_to_time_v9 +GO +EXEC test_conv_string_to_time_p9 +GO +SELECT test_conv_string_to_time_f9() +GO + +SELECT * FROM test_conv_string_to_time_v10 +GO + +SELECT * FROM test_conv_string_to_time_v11 +GO + +SELECT * FROM test_conv_string_to_time_v12 +GO diff --git a/test/JDBC/jdbc_schedule b/test/JDBC/jdbc_schedule index 98d163f437..31be6c61ba 100644 --- a/test/JDBC/jdbc_schedule +++ b/test/JDBC/jdbc_schedule @@ -335,6 +335,44 @@ ignore#!#stuff-before-15_8-or-16_4-vu-prepare ignore#!#stuff-before-15_8-or-16_4-vu-verify ignore#!#stuff-before-15_8-or-16_4-vu-cleanup +# These tests are meant for upgrade scenario prior to 17_3 release +ignore#!#BABEL-3614-before-17_3-vu-prepare +ignore#!#BABEL-3614-before-17_3-vu-verify +ignore#!#BABEL-3486-before-17_3-vu-prepare +ignore#!#BABEL-3486-before-17_3-vu-verify +ignore#!#TestDatetime-numeric-dateaddfunction-before-17_3-vu-prepare +ignore#!#TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify +ignore#!#test_conv_string_to_date-before-17_3-vu-prepare +ignore#!#test_conv_string_to_date-before-17_3-vu-verify +ignore#!#test_conv_string_to_date-before-17_3-vu-cleanup +ignore#!#test_conv_string_to_date-before-13_6-vu-prepare +ignore#!#test_conv_string_to_date-before-13_6-vu-verify +ignore#!#test_conv_string_to_date-before-13_6-vu-cleanup +ignore#!#test_conv_string_to_time-before-17_3-vu-prepare +ignore#!#test_conv_string_to_time-before-17_3-vu-verify +ignore#!#test_conv_string_to_time-before-17_3-vu-cleanup +ignore#!#test_conv_string_to_time-before-13_6-vu-prepare +ignore#!#test_conv_string_to_time-before-13_6-vu-verify +ignore#!#test_conv_string_to_time-before-13_6-vu-cleanup +ignore#!#test_conv_string_to_datetime2-before-17_3-vu-prepare +ignore#!#test_conv_string_to_datetime2-before-17_3-vu-verify +ignore#!#test_conv_string_to_datetime2-before-17_3-vu-cleanup +ignore#!#test_conv_string_to_datetime2-before-14_5-vu-prepare +ignore#!#test_conv_string_to_datetime2-before-14_5-vu-verify +ignore#!#test_conv_string_to_datetime2-before-14_5-vu-cleanup +ignore#!#test_conv_string_to_datetimeoffset-before-17_3-vu-prepare +ignore#!#test_conv_string_to_datetimeoffset-before-17_3-vu-verify +ignore#!#test_conv_string_to_datetimeoffset-before-17_3-vu-cleanup +ignore#!#test_conv_string_to_smalldatetime-before-14_6-vu-prepare +ignore#!#test_conv_string_to_smalldatetime-before-14_6-vu-verify +ignore#!#test_conv_string_to_smalldatetime-before-14_6-vu-cleanup +ignore#!#test_conv_string_to_datetime-before-17_3-vu-prepare +ignore#!#test_conv_string_to_datetime-before-17_3-vu-verify +ignore#!#test_conv_string_to_datetime-before-17_3-vu-cleanup +ignore#!#test_conv_string_to_datetime-before-14_6-vu-prepare +ignore#!#test_conv_string_to_datetime-before-14_6-vu-verify +ignore#!#test_conv_string_to_datetime-before-14_6-vu-cleanup + # These tests are running in multidb mode in upgrade and singledb mode in JDBC ignore#!#BABEL-4279-vu-prepare ignore#!#BABEL-4279-vu-verify diff --git a/test/JDBC/upgrade/13_4/schedule b/test/JDBC/upgrade/13_4/schedule index 75771952f2..2c760cb0c9 100644 --- a/test/JDBC/upgrade/13_4/schedule +++ b/test/JDBC/upgrade/13_4/schedule @@ -253,4 +253,11 @@ binary-datatype-operators BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5059-before-14_7-or-15_2 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-13_6 +test_conv_string_to_datetime-before-14_6 +test_conv_string_to_datetime2-before-14_5 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime-before-14_6 +test_conv_string_to_time-before-13_6 +BABEL-5031 diff --git a/test/JDBC/upgrade/13_5/schedule b/test/JDBC/upgrade/13_5/schedule index debb792c0f..874a49ea06 100644 --- a/test/JDBC/upgrade/13_5/schedule +++ b/test/JDBC/upgrade/13_5/schedule @@ -306,4 +306,11 @@ BABEL-5059-before-14_7-or-15_2 replace-before-15_8-or-16_4 BABEL-CASE_EXPR-before-16_5-or-15_9 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-13_6 +test_conv_string_to_datetime-before-14_6 +test_conv_string_to_datetime2-before-14_5 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime-before-14_6 +test_conv_string_to_time-before-13_6 +BABEL-5031 diff --git a/test/JDBC/upgrade/13_6/schedule b/test/JDBC/upgrade/13_6/schedule index 630f602183..0b0c1faed8 100644 --- a/test/JDBC/upgrade/13_6/schedule +++ b/test/JDBC/upgrade/13_6/schedule @@ -363,3 +363,10 @@ replace-before-15_8-or-16_4 BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-14_6 +test_conv_string_to_datetime2-before-14_5 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime-before-14_6 +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/13_7/schedule b/test/JDBC/upgrade/13_7/schedule index f2c678f230..7ed9627d1e 100644 --- a/test/JDBC/upgrade/13_7/schedule +++ b/test/JDBC/upgrade/13_7/schedule @@ -356,4 +356,11 @@ replace-before-15_8-or-16_4 BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-14_6 +test_conv_string_to_datetime2-before-14_5 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime-before-14_6 +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/13_8/schedule b/test/JDBC/upgrade/13_8/schedule index 2b0ce2a271..06e7b29e4d 100644 --- a/test/JDBC/upgrade/13_8/schedule +++ b/test/JDBC/upgrade/13_8/schedule @@ -356,4 +356,11 @@ replace-before-15_8-or-16_4 BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-14_6 +test_conv_string_to_datetime2-before-14_5 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime-before-14_6 +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/13_9/schedule b/test/JDBC/upgrade/13_9/schedule index 23c12873f4..4d2c2a7e31 100644 --- a/test/JDBC/upgrade/13_9/schedule +++ b/test/JDBC/upgrade/13_9/schedule @@ -361,4 +361,11 @@ replace-before-15_8-or-16_4 BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-14_6 +test_conv_string_to_datetime2-before-14_5 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime-before-14_6 +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/14_10/schedule b/test/JDBC/upgrade/14_10/schedule index dbf13a2b0b..f153ca2d0c 100644 --- a/test/JDBC/upgrade/14_10/schedule +++ b/test/JDBC/upgrade/14_10/schedule @@ -135,9 +135,9 @@ BABEL-3116 BABEL-3117 BABEL-3118 BABEL-3249 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3474 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3646 BABEL-3748 BABEL-383 @@ -474,4 +474,11 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/14_11/schedule b/test/JDBC/upgrade/14_11/schedule index 694153db54..15c98c3d91 100644 --- a/test/JDBC/upgrade/14_11/schedule +++ b/test/JDBC/upgrade/14_11/schedule @@ -136,9 +136,9 @@ BABEL-3116 BABEL-3117 BABEL-3118 BABEL-3249 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3474 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3646 BABEL-3748 BABEL-383 @@ -472,4 +472,11 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/14_12/schedule b/test/JDBC/upgrade/14_12/schedule index 9a8a0592b8..4f64db5d83 100644 --- a/test/JDBC/upgrade/14_12/schedule +++ b/test/JDBC/upgrade/14_12/schedule @@ -135,9 +135,9 @@ BABEL-3116 BABEL-3117 BABEL-3118 BABEL-3249 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3474 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3646 BABEL-3748 BABEL-383 @@ -453,6 +453,12 @@ babel_4328_datetimeoffset translate-before-15_8-or-16_4 substring-before-15_8-or-16_4 babel_726 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 BABEL-3401 reverse-before-15_8-or-16_4 stuff-before-15_8-or-16_4 @@ -473,4 +479,5 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +BABEL-5031 diff --git a/test/JDBC/upgrade/14_3/schedule b/test/JDBC/upgrade/14_3/schedule index 39ca14015b..3311fa4b00 100644 --- a/test/JDBC/upgrade/14_3/schedule +++ b/test/JDBC/upgrade/14_3/schedule @@ -392,4 +392,11 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-14_6 +test_conv_string_to_datetime2-before-14_5 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime-before-14_6 +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/14_5/schedule b/test/JDBC/upgrade/14_5/schedule index 3f176f7b99..66e1d4e167 100644 --- a/test/JDBC/upgrade/14_5/schedule +++ b/test/JDBC/upgrade/14_5/schedule @@ -404,4 +404,11 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-14_6 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime-before-14_6 +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/14_6/schedule b/test/JDBC/upgrade/14_6/schedule index 82edbaa3a8..1aa60b862c 100644 --- a/test/JDBC/upgrade/14_6/schedule +++ b/test/JDBC/upgrade/14_6/schedule @@ -82,11 +82,11 @@ BABEL-3370 BABEL-3380 BABEL-3402 BABEL-3474 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -442,4 +442,11 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/14_7/schedule b/test/JDBC/upgrade/14_7/schedule index d525e680be..5c515127df 100644 --- a/test/JDBC/upgrade/14_7/schedule +++ b/test/JDBC/upgrade/14_7/schedule @@ -84,11 +84,11 @@ BABEL-3370 BABEL-3380 BABEL-3402 BABEL-3474 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -464,4 +464,11 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/14_8/schedule b/test/JDBC/upgrade/14_8/schedule index 088ab57d9c..c2a77290bd 100644 --- a/test/JDBC/upgrade/14_8/schedule +++ b/test/JDBC/upgrade/14_8/schedule @@ -84,11 +84,11 @@ BABEL-3370 BABEL-3380 BABEL-3402 BABEL-3474 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -466,4 +466,11 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/14_9/schedule b/test/JDBC/upgrade/14_9/schedule index 08168dda66..49bf0ec2fb 100644 --- a/test/JDBC/upgrade/14_9/schedule +++ b/test/JDBC/upgrade/14_9/schedule @@ -135,9 +135,9 @@ BABEL-3116 BABEL-3117 BABEL-3118 BABEL-3249 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3474 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3646 BABEL-3748 BABEL-383 @@ -469,4 +469,11 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/15_1/schedule b/test/JDBC/upgrade/15_1/schedule index ba704815c4..3c6879f516 100644 --- a/test/JDBC/upgrade/15_1/schedule +++ b/test/JDBC/upgrade/15_1/schedule @@ -82,11 +82,11 @@ BABEL-3370 BABEL-3380 BABEL-3402 BABEL-3474 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -442,4 +442,11 @@ datareader_datawriter BABEL-5186 BABEL-2736-before-15_3 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/15_2/schedule b/test/JDBC/upgrade/15_2/schedule index e164028edf..54d6cf58c7 100644 --- a/test/JDBC/upgrade/15_2/schedule +++ b/test/JDBC/upgrade/15_2/schedule @@ -84,11 +84,11 @@ BABEL-3370 BABEL-3380 BABEL-3402 BABEL-3474 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -478,4 +478,11 @@ datareader_datawriter BABEL-5186 BABEL-2736-before-15_3 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/15_3/schedule b/test/JDBC/upgrade/15_3/schedule index d30d4dccd6..f8769432e2 100644 --- a/test/JDBC/upgrade/15_3/schedule +++ b/test/JDBC/upgrade/15_3/schedule @@ -87,11 +87,11 @@ BABEL-3380 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -395,7 +395,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -497,4 +497,11 @@ datareader_datawriter BABEL-5186 BABEL-2736-before-16_5 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/15_4/schedule b/test/JDBC/upgrade/15_4/schedule index d7bfec90f2..f79a83fef7 100644 --- a/test/JDBC/upgrade/15_4/schedule +++ b/test/JDBC/upgrade/15_4/schedule @@ -87,11 +87,11 @@ BABEL-3380 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -402,7 +402,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -510,4 +510,11 @@ datareader_datawriter BABEL-5186 BABEL-2736-before-16_5 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/15_5/schedule b/test/JDBC/upgrade/15_5/schedule index d085bc4a4c..3fa81503d5 100644 --- a/test/JDBC/upgrade/15_5/schedule +++ b/test/JDBC/upgrade/15_5/schedule @@ -88,11 +88,11 @@ BABEL-3380 BABEL-3392 BABEL-3402 BABEL-3478 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -411,7 +411,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -543,4 +543,11 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/15_6/schedule b/test/JDBC/upgrade/15_6/schedule index 5d73d2bf8a..3984264888 100644 --- a/test/JDBC/upgrade/15_6/schedule +++ b/test/JDBC/upgrade/15_6/schedule @@ -90,11 +90,11 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -417,7 +417,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -559,4 +559,11 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/15_7/schedule b/test/JDBC/upgrade/15_7/schedule index 8f9a091f63..a2f276fdba 100644 --- a/test/JDBC/upgrade/15_7/schedule +++ b/test/JDBC/upgrade/15_7/schedule @@ -567,4 +567,13 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_string_to_date +test_conv_string_to_datetime +test_conv_string_to_datetime2 +test_conv_string_to_datetimeoffset +test_conv_string_to_smalldatetime +test_conv_string_to_time +BABEL-3401 +babel_726 +BABEL-5031 diff --git a/test/JDBC/upgrade/16_1/schedule b/test/JDBC/upgrade/16_1/schedule index 08d5dcb10e..9bda9bc843 100644 --- a/test/JDBC/upgrade/16_1/schedule +++ b/test/JDBC/upgrade/16_1/schedule @@ -90,11 +90,11 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -416,7 +416,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -552,4 +552,11 @@ datareader_datawriter BABEL-5186 BABEL-2736-before-16_5 smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/16_2/schedule b/test/JDBC/upgrade/16_2/schedule index ad5c7d9ec9..56147c106a 100644 --- a/test/JDBC/upgrade/16_2/schedule +++ b/test/JDBC/upgrade/16_2/schedule @@ -90,11 +90,11 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-16_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -419,7 +419,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -568,4 +568,11 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index 9bdf0112f1..be941c64b3 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -557,6 +557,12 @@ translate substring babel_4328_datetimeoffset babel_726 +test_conv_string_to_date +test_conv_string_to_datetime +test_conv_string_to_datetime2 +test_conv_string_to_datetimeoffset +test_conv_string_to_smalldatetime +test_conv_string_to_time BABEL-3401 BABEL-3820 stuff @@ -593,3 +599,5 @@ datareader_datawriter db_owner smalldatetime_date_cmp BABEL-2961 +BABEL-5031 + diff --git a/test/python/expected/upgrade_validation/expected_dependency.out b/test/python/expected/upgrade_validation/expected_dependency.out index 221f5b8c29..61bedca80e 100644 --- a/test/python/expected/upgrade_validation/expected_dependency.out +++ b/test/python/expected/upgrade_validation/expected_dependency.out @@ -97,16 +97,13 @@ Function sys.babelfish_conv_greg_to_hijri(date) Function sys.babelfish_conv_greg_to_hijri(numeric,numeric,numeric) Function sys.babelfish_conv_greg_to_hijri(text,text,text) Function sys.babelfish_conv_greg_to_hijri(timestamp without time zone) -Function sys.babelfish_conv_helper_to_date(anyelement,boolean,numeric) -Function sys.babelfish_conv_helper_to_time(anyelement,boolean,numeric) Function sys.babelfish_conv_hijri_to_greg(date) Function sys.babelfish_conv_hijri_to_greg(numeric,numeric,numeric) Function sys.babelfish_conv_hijri_to_greg(text,text,text) Function sys.babelfish_conv_hijri_to_greg(timestamp without time zone) -Function sys.babelfish_conv_string_to_date(text,numeric) -Function sys.babelfish_conv_string_to_datetime(text,text,numeric) -Function sys.babelfish_conv_string_to_time(text,text,numeric) -Function sys.babelfish_conv_string_to_varbinary(sys."varchar",numeric) +Function sys.babelfish_conv_string_to_datetime2(text,text,numeric) +Function sys.babelfish_conv_string_to_datetime_v2(text,text,numeric) +Function sys.babelfish_conv_string_to_datetimeoffset(text,text,numeric) Function sys.babelfish_conv_time_to_string(text,text,time without time zone,numeric) Function sys.babelfish_conv_to_varchar(text,anyelement,numeric) Function sys.babelfish_conv_to_varchar(text,text,numeric) @@ -122,7 +119,7 @@ Function sys.babelfish_get_int_part(double precision) Function sys.babelfish_get_jobs() Function sys.babelfish_get_lang_metadata_json(text) Function sys.babelfish_get_login_default_db(text) -Function sys.babelfish_get_microsecs_from_fractsecs(text,numeric) +Function sys.babelfish_get_microsecs_from_fractsecs_v2(text,numeric) Function sys.babelfish_get_monthnum_by_name(text,jsonb) Function sys.babelfish_get_name_delimiter_pos(text) Function sys.babelfish_get_sequence_value(character varying) @@ -193,13 +190,15 @@ Function sys.babelfish_try_conv_date_to_string(text,date,numeric) Function sys.babelfish_try_conv_datetime_to_string(text,text,timestamp without time zone,numeric) Function sys.babelfish_try_conv_float_to_string(text,double precision,numeric) Function sys.babelfish_try_conv_money_to_string(text,money,numeric) -Function sys.babelfish_try_conv_string_to_date(text,numeric) -Function sys.babelfish_try_conv_string_to_datetime(text,text,numeric) -Function sys.babelfish_try_conv_string_to_time(text,text,numeric) -Function sys.babelfish_try_conv_string_to_varbinary(sys."varchar",numeric) +Function sys.babelfish_try_conv_string_to_datetime2(text,text,numeric) +Function sys.babelfish_try_conv_string_to_datetime_v2(text,text,numeric) +Function sys.babelfish_try_conv_string_to_datetimeoffset(text,text,numeric) Function sys.babelfish_try_conv_time_to_string(text,text,time without time zone,numeric) Function sys.babelfish_try_conv_to_date(anyelement) Function sys.babelfish_try_conv_to_datetime(anyelement) +Function sys.babelfish_try_conv_to_datetime2(anyelement) +Function sys.babelfish_try_conv_to_datetimeoffset(anyelement) +Function sys.babelfish_try_conv_to_smalldatetime(anyelement) Function sys.babelfish_try_conv_to_time(anyelement) Function sys.babelfish_try_conv_to_varbinary(anyelement,numeric) Function sys.babelfish_try_conv_to_varchar(text,anyelement,numeric) From f01da9c0b0c8165df4b1d5192daf77b6cdf16eb1 Mon Sep 17 00:00:00 2001 From: Rohit Bhagat Date: Wed, 1 Jan 2025 05:20:07 +0000 Subject: [PATCH 02/10] update pg_catalog.trim to pg_catalog.btrim Signed-off-by: Rohit Bhagat --- contrib/babelfishpg_tsql/sql/sys_function_helpers.sql | 2 +- .../sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql b/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql index 8686f463a6..743bf27cca 100644 --- a/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql +++ b/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql @@ -2150,7 +2150,7 @@ DECLARE W3C_XML_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, '(', '(\-|\+)', '\s*(\d{2})\s*', '\:', '\s*(\d{2})\s*', '|', 'Z', ')','$'); W3C_XML_Z_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, 'Z','$'); BEGIN - v_datetimestring := pg_catalog.upper(pg_catalog.trim(p_datetimestring)); + v_datetimestring := pg_catalog.upper(pg_catalog.btrim(p_datetimestring)); -- datetimestring validation and conversion will be done in babelfish_conv_string_to_datetime2 function and a timestamp will be returned v_resdatetime := sys.babelfish_conv_string_to_datetime2(p_datatype, p_datetimestring, p_style); diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql index 17233a1912..ae8c3fc0ef 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql @@ -1614,7 +1614,7 @@ DECLARE W3C_XML_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, '(', '(\-|\+)', '\s*(\d{2})\s*', '\:', '\s*(\d{2})\s*', '|', 'Z', ')','$'); W3C_XML_Z_REGEXP CONSTANT VARCHAR COLLATE "C" := pg_catalog.concat('^', FULLYEAR_REGEXP, '-', DAYMM_REGEXP, '-', DAYMM_REGEXP, 'Z','$'); BEGIN - v_datetimestring := pg_catalog.upper(pg_catalog.trim(p_datetimestring)); + v_datetimestring := pg_catalog.upper(pg_catalog.btrim(p_datetimestring)); -- datetimestring validation and conversion will be done in babelfish_conv_string_to_datetime2 function and a timestamp will be returned v_resdatetime := sys.babelfish_conv_string_to_datetime2(p_datatype, p_datetimestring, p_style); From 95beae47c76408a4642ba36254b255521d022378 Mon Sep 17 00:00:00 2001 From: Rohit Bhagat Date: Wed, 1 Jan 2025 06:16:43 +0000 Subject: [PATCH 03/10] updated expected dependency file Signed-off-by: Rohit Bhagat --- test/python/expected/upgrade_validation/expected_dependency.out | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/python/expected/upgrade_validation/expected_dependency.out b/test/python/expected/upgrade_validation/expected_dependency.out index 61bedca80e..b7df97b8fe 100644 --- a/test/python/expected/upgrade_validation/expected_dependency.out +++ b/test/python/expected/upgrade_validation/expected_dependency.out @@ -104,6 +104,7 @@ Function sys.babelfish_conv_hijri_to_greg(timestamp without time zone) Function sys.babelfish_conv_string_to_datetime2(text,text,numeric) Function sys.babelfish_conv_string_to_datetime_v2(text,text,numeric) Function sys.babelfish_conv_string_to_datetimeoffset(text,text,numeric) +Function sys.babelfish_conv_string_to_varbinary(sys."varchar",numeric) Function sys.babelfish_conv_time_to_string(text,text,time without time zone,numeric) Function sys.babelfish_conv_to_varchar(text,anyelement,numeric) Function sys.babelfish_conv_to_varchar(text,text,numeric) @@ -193,6 +194,7 @@ Function sys.babelfish_try_conv_money_to_string(text,money,numeric) Function sys.babelfish_try_conv_string_to_datetime2(text,text,numeric) Function sys.babelfish_try_conv_string_to_datetime_v2(text,text,numeric) Function sys.babelfish_try_conv_string_to_datetimeoffset(text,text,numeric) +Function sys.babelfish_try_conv_string_to_varbinary(sys."varchar",numeric) Function sys.babelfish_try_conv_time_to_string(text,text,time without time zone,numeric) Function sys.babelfish_try_conv_to_date(anyelement) Function sys.babelfish_try_conv_to_datetime(anyelement) From 6d4271ffe36a51e7da623bd2d51a459f8a43660b Mon Sep 17 00:00:00 2001 From: Rohit Bhagat Date: Wed, 1 Jan 2025 06:28:40 +0000 Subject: [PATCH 04/10] update schedule files Signed-off-by: Rohit Bhagat --- test/JDBC/upgrade/14_10/schedule | 2 +- test/JDBC/upgrade/14_11/schedule | 2 +- test/JDBC/upgrade/14_12/schedule | 2 +- test/JDBC/upgrade/14_6/schedule | 2 +- test/JDBC/upgrade/14_7/schedule | 2 +- test/JDBC/upgrade/14_8/schedule | 2 +- test/JDBC/upgrade/14_9/schedule | 2 +- test/JDBC/upgrade/15_1/schedule | 2 +- test/JDBC/upgrade/15_2/schedule | 2 +- test/JDBC/upgrade/15_3/schedule | 2 +- test/JDBC/upgrade/15_4/schedule | 2 +- test/JDBC/upgrade/15_5/schedule | 2 +- test/JDBC/upgrade/15_6/schedule | 2 +- test/JDBC/upgrade/16_1/schedule | 2 +- test/JDBC/upgrade/16_2/schedule | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/JDBC/upgrade/14_10/schedule b/test/JDBC/upgrade/14_10/schedule index f153ca2d0c..ccf4a8f3cc 100644 --- a/test/JDBC/upgrade/14_10/schedule +++ b/test/JDBC/upgrade/14_10/schedule @@ -135,7 +135,7 @@ BABEL-3116 BABEL-3117 BABEL-3118 BABEL-3249 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3474 BABEL-3614-before-17_3 BABEL-3646 diff --git a/test/JDBC/upgrade/14_11/schedule b/test/JDBC/upgrade/14_11/schedule index 15c98c3d91..93dcf363c7 100644 --- a/test/JDBC/upgrade/14_11/schedule +++ b/test/JDBC/upgrade/14_11/schedule @@ -136,7 +136,7 @@ BABEL-3116 BABEL-3117 BABEL-3118 BABEL-3249 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3474 BABEL-3614-before-17_3 BABEL-3646 diff --git a/test/JDBC/upgrade/14_12/schedule b/test/JDBC/upgrade/14_12/schedule index 4f64db5d83..d5432aea26 100644 --- a/test/JDBC/upgrade/14_12/schedule +++ b/test/JDBC/upgrade/14_12/schedule @@ -135,7 +135,7 @@ BABEL-3116 BABEL-3117 BABEL-3118 BABEL-3249 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3474 BABEL-3614-before-17_3 BABEL-3646 diff --git a/test/JDBC/upgrade/14_6/schedule b/test/JDBC/upgrade/14_6/schedule index 1aa60b862c..2aff628678 100644 --- a/test/JDBC/upgrade/14_6/schedule +++ b/test/JDBC/upgrade/14_6/schedule @@ -82,7 +82,7 @@ BABEL-3370 BABEL-3380 BABEL-3402 BABEL-3474 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 diff --git a/test/JDBC/upgrade/14_7/schedule b/test/JDBC/upgrade/14_7/schedule index 5c515127df..a232df637e 100644 --- a/test/JDBC/upgrade/14_7/schedule +++ b/test/JDBC/upgrade/14_7/schedule @@ -84,7 +84,7 @@ BABEL-3370 BABEL-3380 BABEL-3402 BABEL-3474 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 diff --git a/test/JDBC/upgrade/14_8/schedule b/test/JDBC/upgrade/14_8/schedule index c2a77290bd..30ac879942 100644 --- a/test/JDBC/upgrade/14_8/schedule +++ b/test/JDBC/upgrade/14_8/schedule @@ -84,7 +84,7 @@ BABEL-3370 BABEL-3380 BABEL-3402 BABEL-3474 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 diff --git a/test/JDBC/upgrade/14_9/schedule b/test/JDBC/upgrade/14_9/schedule index 49bf0ec2fb..d35fd12137 100644 --- a/test/JDBC/upgrade/14_9/schedule +++ b/test/JDBC/upgrade/14_9/schedule @@ -135,7 +135,7 @@ BABEL-3116 BABEL-3117 BABEL-3118 BABEL-3249 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3474 BABEL-3614-before-17_3 BABEL-3646 diff --git a/test/JDBC/upgrade/15_1/schedule b/test/JDBC/upgrade/15_1/schedule index 3c6879f516..123071cec6 100644 --- a/test/JDBC/upgrade/15_1/schedule +++ b/test/JDBC/upgrade/15_1/schedule @@ -82,7 +82,7 @@ BABEL-3370 BABEL-3380 BABEL-3402 BABEL-3474 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 diff --git a/test/JDBC/upgrade/15_2/schedule b/test/JDBC/upgrade/15_2/schedule index 54d6cf58c7..79c7cd35d4 100644 --- a/test/JDBC/upgrade/15_2/schedule +++ b/test/JDBC/upgrade/15_2/schedule @@ -84,7 +84,7 @@ BABEL-3370 BABEL-3380 BABEL-3402 BABEL-3474 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 diff --git a/test/JDBC/upgrade/15_3/schedule b/test/JDBC/upgrade/15_3/schedule index f8769432e2..77e4d4c28b 100644 --- a/test/JDBC/upgrade/15_3/schedule +++ b/test/JDBC/upgrade/15_3/schedule @@ -87,7 +87,7 @@ BABEL-3380 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 diff --git a/test/JDBC/upgrade/15_4/schedule b/test/JDBC/upgrade/15_4/schedule index f79a83fef7..774fe70d32 100644 --- a/test/JDBC/upgrade/15_4/schedule +++ b/test/JDBC/upgrade/15_4/schedule @@ -87,7 +87,7 @@ BABEL-3380 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 diff --git a/test/JDBC/upgrade/15_5/schedule b/test/JDBC/upgrade/15_5/schedule index 3fa81503d5..474ab4bcf5 100644 --- a/test/JDBC/upgrade/15_5/schedule +++ b/test/JDBC/upgrade/15_5/schedule @@ -88,7 +88,7 @@ BABEL-3380 BABEL-3392 BABEL-3402 BABEL-3478 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 diff --git a/test/JDBC/upgrade/15_6/schedule b/test/JDBC/upgrade/15_6/schedule index 3984264888..08c9b2c3a7 100644 --- a/test/JDBC/upgrade/15_6/schedule +++ b/test/JDBC/upgrade/15_6/schedule @@ -90,7 +90,7 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 diff --git a/test/JDBC/upgrade/16_1/schedule b/test/JDBC/upgrade/16_1/schedule index 9bda9bc843..a9e19697e3 100644 --- a/test/JDBC/upgrade/16_1/schedule +++ b/test/JDBC/upgrade/16_1/schedule @@ -90,7 +90,7 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 diff --git a/test/JDBC/upgrade/16_2/schedule b/test/JDBC/upgrade/16_2/schedule index 56147c106a..11d4ab4407 100644 --- a/test/JDBC/upgrade/16_2/schedule +++ b/test/JDBC/upgrade/16_2/schedule @@ -90,7 +90,7 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486-before-16_3 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 From db7a88a8279e7cbaa3544ddaed2e15eb4a98ea7e Mon Sep 17 00:00:00 2001 From: Rohit Bhagat Date: Wed, 1 Jan 2025 07:48:02 +0000 Subject: [PATCH 05/10] added before test files into upgrade schedules Signed-off-by: Rohit Bhagat --- ...ric-dateaddfunction-before-17_3-vu-verify.out | 16 ++++++++-------- ...conv_string_to_date-before-13_6-vu-verify.out | 2 ++ ...conv_string_to_date-before-17_3-vu-verify.out | 2 ++ test/JDBC/upgrade/14_13/schedule | 10 ++++++++-- test/JDBC/upgrade/14_15/schedule | 10 ++++++++-- test/JDBC/upgrade/14_16/schedule | 10 ++++++++-- test/JDBC/upgrade/15_10/schedule | 12 +++++++++--- test/JDBC/upgrade/15_11/schedule | 12 +++++++++--- test/JDBC/upgrade/15_7/schedule | 16 ++++++++-------- test/JDBC/upgrade/15_8/schedule | 12 +++++++++--- test/JDBC/upgrade/16_3/schedule | 12 +++++++++--- test/JDBC/upgrade/16_4/schedule | 12 +++++++++--- test/JDBC/upgrade/16_6/schedule | 12 +++++++++--- test/JDBC/upgrade/16_7/schedule | 10 ++++++++-- test/JDBC/upgrade/17_2/schedule | 12 +++++++++--- 15 files changed, 115 insertions(+), 45 deletions(-) diff --git a/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.out b/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.out index 56817beab8..b48f2338df 100644 --- a/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.out +++ b/test/JDBC/expected/TestDatetime-numeric-dateaddfunction-before-17_3-vu-verify.out @@ -62,28 +62,28 @@ GO EXEC Datetime_proc1 '1900-01-02 00:00:00', 3.1 GO ~~START~~ -text +varchar pass ~~END~~ EXEC Datetime_proc1 '1900-01-02 00:00:00', 2 GO ~~START~~ -text +varchar pass ~~END~~ EXEC Datetime_proc1 '1900-01-01 00:00:00', 0 GO ~~START~~ -text +varchar pass ~~END~~ EXEC Datetime_proc1 '1900-01-02 00:00:00', -3.1 GO ~~START~~ -text +varchar pass ~~END~~ @@ -93,28 +93,28 @@ GO EXEC SMALLDatetime_proc1 '1900-01-02 00:00:00', 3.1 GO ~~START~~ -text +varchar pass ~~END~~ EXEC SMALLDatetime_proc1 '1900-01-02 00:00:00', 2 GO ~~START~~ -text +varchar pass ~~END~~ EXEC SMALLDatetime_proc1 '1900-01-01 00:00:00', 0 GO ~~START~~ -text +varchar pass ~~END~~ EXEC SMALLDatetime_proc1 '1900-01-02 00:00:00', -3.1 GO ~~START~~ -text +varchar pass ~~END~~ diff --git a/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out index 71d20a06c1..b9fa5eb983 100644 --- a/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out +++ b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out @@ -3516,6 +3516,8 @@ GO DECLARE @TM_ICLO TIME = '17:24:07.1766670' SELECT CONVERT(DATE, @TM_ICLO) GO +~~START~~ +date ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Explicit conversion from data type time without time zone to date is not allowed.)~~ diff --git a/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out index 96501e2f62..4fb732d83b 100644 --- a/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out +++ b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out @@ -3516,6 +3516,8 @@ GO DECLARE @TM_ICLO TIME = '17:24:07.1766670' SELECT CONVERT(DATE, @TM_ICLO) GO +~~START~~ +date ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Explicit conversion from data type time without time zone to date is not allowed.)~~ diff --git a/test/JDBC/upgrade/14_13/schedule b/test/JDBC/upgrade/14_13/schedule index 0e089fea64..8668b8a9ce 100644 --- a/test/JDBC/upgrade/14_13/schedule +++ b/test/JDBC/upgrade/14_13/schedule @@ -135,9 +135,9 @@ BABEL-3116 BABEL-3117 BABEL-3118 BABEL-3249 -BABEL-3486 +BABEL-3486-before-17_3 BABEL-3474 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3646 BABEL-3748 BABEL-383 @@ -473,4 +473,10 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 diff --git a/test/JDBC/upgrade/14_15/schedule b/test/JDBC/upgrade/14_15/schedule index 23483d79a2..32ef3702e4 100644 --- a/test/JDBC/upgrade/14_15/schedule +++ b/test/JDBC/upgrade/14_15/schedule @@ -135,9 +135,9 @@ BABEL-3116 BABEL-3117 BABEL-3118 BABEL-3249 -BABEL-3486 +BABEL-3486-before-17_3 BABEL-3474 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3646 BABEL-3748 BABEL-383 @@ -469,3 +469,9 @@ xml_exist-before-16_5 BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 diff --git a/test/JDBC/upgrade/14_16/schedule b/test/JDBC/upgrade/14_16/schedule index 132b4e6796..d1df5e536e 100644 --- a/test/JDBC/upgrade/14_16/schedule +++ b/test/JDBC/upgrade/14_16/schedule @@ -135,9 +135,9 @@ BABEL-3116 BABEL-3117 BABEL-3118 BABEL-3249 -BABEL-3486 +BABEL-3486-before-17_3 BABEL-3474 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3646 BABEL-3748 BABEL-383 @@ -469,3 +469,9 @@ xml_exist-before-16_5 BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 diff --git a/test/JDBC/upgrade/15_10/schedule b/test/JDBC/upgrade/15_10/schedule index b73b74cfda..08e9474a64 100644 --- a/test/JDBC/upgrade/15_10/schedule +++ b/test/JDBC/upgrade/15_10/schedule @@ -90,11 +90,11 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-17_3 BABEL-3513 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -415,7 +415,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -558,3 +558,9 @@ db_ddladmin BABEL-5186 BABEL-2736 smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 diff --git a/test/JDBC/upgrade/15_11/schedule b/test/JDBC/upgrade/15_11/schedule index 463f37e429..df49c22f67 100644 --- a/test/JDBC/upgrade/15_11/schedule +++ b/test/JDBC/upgrade/15_11/schedule @@ -90,11 +90,11 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-17_3 BABEL-3513 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -415,7 +415,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -558,3 +558,9 @@ db_ddladmin BABEL-5186 BABEL-2736 smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 diff --git a/test/JDBC/upgrade/15_7/schedule b/test/JDBC/upgrade/15_7/schedule index a2f276fdba..59883cbe96 100644 --- a/test/JDBC/upgrade/15_7/schedule +++ b/test/JDBC/upgrade/15_7/schedule @@ -90,11 +90,11 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -418,7 +418,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -567,12 +567,12 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp -test_conv_string_to_date -test_conv_string_to_datetime -test_conv_string_to_datetime2 -test_conv_string_to_datetimeoffset +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime -test_conv_string_to_time +test_conv_string_to_time-before-17_3 BABEL-3401 babel_726 BABEL-5031 diff --git a/test/JDBC/upgrade/15_8/schedule b/test/JDBC/upgrade/15_8/schedule index 1b3856fe35..8cc1aff639 100644 --- a/test/JDBC/upgrade/15_8/schedule +++ b/test/JDBC/upgrade/15_8/schedule @@ -90,11 +90,11 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-17_3 BABEL-3513 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -415,7 +415,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -558,4 +558,10 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 diff --git a/test/JDBC/upgrade/16_3/schedule b/test/JDBC/upgrade/16_3/schedule index 6d2164b7d5..d63a908359 100644 --- a/test/JDBC/upgrade/16_3/schedule +++ b/test/JDBC/upgrade/16_3/schedule @@ -90,11 +90,11 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-17_3 BABEL-3513_before_15_8_or_16_4 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -420,7 +420,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -572,4 +572,10 @@ securityadmin_role datareader_datawriter BABEL-5186 smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 diff --git a/test/JDBC/upgrade/16_4/schedule b/test/JDBC/upgrade/16_4/schedule index 2cffc4520f..826bc44975 100644 --- a/test/JDBC/upgrade/16_4/schedule +++ b/test/JDBC/upgrade/16_4/schedule @@ -89,11 +89,11 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-17_3 BABEL-3513 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -421,7 +421,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -585,4 +585,10 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 diff --git a/test/JDBC/upgrade/16_6/schedule b/test/JDBC/upgrade/16_6/schedule index a8243aef2a..d219b64901 100644 --- a/test/JDBC/upgrade/16_6/schedule +++ b/test/JDBC/upgrade/16_6/schedule @@ -89,11 +89,11 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-17_3 BABEL-3513 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -422,7 +422,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -588,3 +588,9 @@ dbcreator_role db_securityadmin db_ddladmin smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 diff --git a/test/JDBC/upgrade/16_7/schedule b/test/JDBC/upgrade/16_7/schedule index 5420de502d..6811d36da3 100644 --- a/test/JDBC/upgrade/16_7/schedule +++ b/test/JDBC/upgrade/16_7/schedule @@ -93,7 +93,7 @@ BABEL-3486 BABEL-3513 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -421,7 +421,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -592,4 +592,10 @@ dbcreator_role db_securityadmin db_ddladmin smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 db_owner diff --git a/test/JDBC/upgrade/17_2/schedule b/test/JDBC/upgrade/17_2/schedule index 5d54b6103f..87fb906ce1 100644 --- a/test/JDBC/upgrade/17_2/schedule +++ b/test/JDBC/upgrade/17_2/schedule @@ -88,11 +88,11 @@ BABEL-3392 BABEL-3402 BABEL-3474 BABEL-3478 -BABEL-3486 +BABEL-3486-before-17_3 BABEL-3513 BABEL-3556 BABEL-3588 -BABEL-3614 +BABEL-3614-before-17_3 BABEL-3640 BABEL-3646 BABEL-3655 @@ -419,7 +419,7 @@ Test-Computed-Columns TestDate TestDatetime TestDatetime2 -TestDatetime-numeric-dateaddfunction +TestDatetime-numeric-dateaddfunction-before-17_3 TestDatetime-numeric-representation TestDecimal TestFloat @@ -591,4 +591,10 @@ BABEL-2736 datareader_datawriter db_owner smalldatetime_date_cmp +test_conv_string_to_date-before-17_3 +test_conv_string_to_datetime-before-17_3 +test_conv_string_to_datetime2-before-17_3 +test_conv_string_to_datetimeoffset-before-17_3 +test_conv_string_to_smalldatetime +test_conv_string_to_time-before-17_3 From 87f9502e868c3e8967dad6e6594580b3353bfa4c Mon Sep 17 00:00:00 2001 From: Rohit Bhagat Date: Thu, 2 Jan 2025 09:26:30 +0000 Subject: [PATCH 06/10] fix issue in creation of index when parallel mode is enabled Signed-off-by: Rohit Bhagat --- .../babelfishpg_tsql/sql/sys_function_helpers.sql | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql b/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql index 743bf27cca..64777f4432 100644 --- a/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql +++ b/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql @@ -2619,10 +2619,16 @@ BEGIN END IF; IF (NOT v_is_cached) THEN - PERFORM set_config(format('sys.lang_metadata_json.%s', - v_lang_spec_culture), - v_lang_data_jsonb::TEXT, - FALSE); + BEGIN + PERFORM set_config(format('sys.lang_metadata_json.%s', + v_lang_spec_culture), + v_lang_data_jsonb::TEXT, + FALSE); + EXCEPTION + WHEN invalid_transaction_state THEN + -- This exception will only occur when we are trying to set config in parallel mode + -- we can ignore this error as we cannot store this config during a parallel operation + END; END IF; RETURN v_lang_data_jsonb; From a14776a0f41d5eff205e3614d8e3b1e09934278d Mon Sep 17 00:00:00 2001 From: Rohit Bhagat Date: Mon, 6 Jan 2025 18:55:09 +0000 Subject: [PATCH 07/10] Added BABEL-5031 in other upgrade schedule files as well Signed-off-by: Rohit Bhagat --- test/JDBC/upgrade/14_13/schedule | 1 + test/JDBC/upgrade/14_15/schedule | 1 + test/JDBC/upgrade/14_16/schedule | 1 + test/JDBC/upgrade/15_10/schedule | 1 + test/JDBC/upgrade/15_11/schedule | 1 + test/JDBC/upgrade/15_7/schedule | 2 -- test/JDBC/upgrade/15_8/schedule | 1 + test/JDBC/upgrade/16_3/schedule | 1 + test/JDBC/upgrade/16_4/schedule | 1 + test/JDBC/upgrade/16_6/schedule | 1 + test/JDBC/upgrade/16_7/schedule | 1 + test/JDBC/upgrade/17_2/schedule | 1 + 12 files changed, 11 insertions(+), 2 deletions(-) diff --git a/test/JDBC/upgrade/14_13/schedule b/test/JDBC/upgrade/14_13/schedule index 8668b8a9ce..bf517f5e58 100644 --- a/test/JDBC/upgrade/14_13/schedule +++ b/test/JDBC/upgrade/14_13/schedule @@ -479,4 +479,5 @@ test_conv_string_to_datetime2-before-17_3 test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/14_15/schedule b/test/JDBC/upgrade/14_15/schedule index 32ef3702e4..eeb48f4b37 100644 --- a/test/JDBC/upgrade/14_15/schedule +++ b/test/JDBC/upgrade/14_15/schedule @@ -475,3 +475,4 @@ test_conv_string_to_datetime2-before-17_3 test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/14_16/schedule b/test/JDBC/upgrade/14_16/schedule index d1df5e536e..c4641c1314 100644 --- a/test/JDBC/upgrade/14_16/schedule +++ b/test/JDBC/upgrade/14_16/schedule @@ -475,3 +475,4 @@ test_conv_string_to_datetime2-before-17_3 test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/15_10/schedule b/test/JDBC/upgrade/15_10/schedule index 08e9474a64..205399d5cf 100644 --- a/test/JDBC/upgrade/15_10/schedule +++ b/test/JDBC/upgrade/15_10/schedule @@ -564,3 +564,4 @@ test_conv_string_to_datetime2-before-17_3 test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/15_11/schedule b/test/JDBC/upgrade/15_11/schedule index df49c22f67..6da3ede6b0 100644 --- a/test/JDBC/upgrade/15_11/schedule +++ b/test/JDBC/upgrade/15_11/schedule @@ -564,3 +564,4 @@ test_conv_string_to_datetime2-before-17_3 test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/15_7/schedule b/test/JDBC/upgrade/15_7/schedule index 59883cbe96..80e008ac3e 100644 --- a/test/JDBC/upgrade/15_7/schedule +++ b/test/JDBC/upgrade/15_7/schedule @@ -573,7 +573,5 @@ test_conv_string_to_datetime2-before-17_3 test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 -BABEL-3401 -babel_726 BABEL-5031 diff --git a/test/JDBC/upgrade/15_8/schedule b/test/JDBC/upgrade/15_8/schedule index 8cc1aff639..aa286e8d8c 100644 --- a/test/JDBC/upgrade/15_8/schedule +++ b/test/JDBC/upgrade/15_8/schedule @@ -564,4 +564,5 @@ test_conv_string_to_datetime2-before-17_3 test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/16_3/schedule b/test/JDBC/upgrade/16_3/schedule index d63a908359..94515f4f1d 100644 --- a/test/JDBC/upgrade/16_3/schedule +++ b/test/JDBC/upgrade/16_3/schedule @@ -578,4 +578,5 @@ test_conv_string_to_datetime2-before-17_3 test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/16_4/schedule b/test/JDBC/upgrade/16_4/schedule index 826bc44975..540c53619d 100644 --- a/test/JDBC/upgrade/16_4/schedule +++ b/test/JDBC/upgrade/16_4/schedule @@ -591,4 +591,5 @@ test_conv_string_to_datetime2-before-17_3 test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/16_6/schedule b/test/JDBC/upgrade/16_6/schedule index d219b64901..f045d59e7f 100644 --- a/test/JDBC/upgrade/16_6/schedule +++ b/test/JDBC/upgrade/16_6/schedule @@ -594,3 +594,4 @@ test_conv_string_to_datetime2-before-17_3 test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 +BABEL-5031 diff --git a/test/JDBC/upgrade/16_7/schedule b/test/JDBC/upgrade/16_7/schedule index 6811d36da3..1b631630f8 100644 --- a/test/JDBC/upgrade/16_7/schedule +++ b/test/JDBC/upgrade/16_7/schedule @@ -599,3 +599,4 @@ test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 db_owner +BABEL-5031 diff --git a/test/JDBC/upgrade/17_2/schedule b/test/JDBC/upgrade/17_2/schedule index 87fb906ce1..435bae1a70 100644 --- a/test/JDBC/upgrade/17_2/schedule +++ b/test/JDBC/upgrade/17_2/schedule @@ -597,4 +597,5 @@ test_conv_string_to_datetime2-before-17_3 test_conv_string_to_datetimeoffset-before-17_3 test_conv_string_to_smalldatetime test_conv_string_to_time-before-17_3 +BABEL-5031 From 08ea42308baf0c730c2c06868b70bd1d9b2513f8 Mon Sep 17 00:00:00 2001 From: Rohit Bhagat Date: Mon, 6 Jan 2025 19:12:37 +0000 Subject: [PATCH 08/10] fix upgrade script after git merge Signed-off-by: Rohit Bhagat --- .../sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql index 321175906f..ab40a2aec4 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql @@ -135,6 +135,10 @@ $$; CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_money_to_string(IN p_datatype TEXT, IN p_moneyval NUMERIC, IN p_style NUMERIC DEFAULT 0) +RETURNS TEXT +AS +$BODY$ +DECLARE v_style SMALLINT; v_format VARCHAR COLLATE "C"; v_moneyval NUMERIC(19,4) := p_moneyval::NUMERIC(19,4); From 28c6765b089cd9cceaed1b17cde5a5490e38fb61 Mon Sep 17 00:00:00 2001 From: Rohit Bhagat Date: Tue, 7 Jan 2025 04:45:52 +0000 Subject: [PATCH 09/10] fix test_conv_money_to_varchar test file Signed-off-by: Rohit Bhagat --- .../JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out | 6 +++--- .../JDBC/expected/test_conv_money_to_varchar-vu-prepare.out | 6 +++--- test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out | 6 +++--- .../functions/test_conv_money_to_varchar-vu-cleanup.sql | 6 +++--- .../functions/test_conv_money_to_varchar-vu-prepare.sql | 6 +++--- .../functions/test_conv_money_to_varchar-vu-verify.sql | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out b/test/JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out index de0c5e4c6e..f7f9931e9d 100644 --- a/test/JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out +++ b/test/JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out @@ -1,10 +1,10 @@ -DROP VIEW test_conv_string_to_date_v1 +DROP VIEW test_conv_money_to_string_v1 GO -DROP PROCEDURE test_conv_string_to_date_p1 +DROP PROCEDURE test_conv_money_to_string_p1 GO -DROP FUNCTION test_conv_string_to_date_f1 +DROP FUNCTION test_conv_money_to_string_f1 GO DROP TABLE test_conv_money_to_varchar_t1 diff --git a/test/JDBC/expected/test_conv_money_to_varchar-vu-prepare.out b/test/JDBC/expected/test_conv_money_to_varchar-vu-prepare.out index 559ceae53b..a90840abbd 100644 --- a/test/JDBC/expected/test_conv_money_to_varchar-vu-prepare.out +++ b/test/JDBC/expected/test_conv_money_to_varchar-vu-prepare.out @@ -6,7 +6,7 @@ GO ~~ROW COUNT: 4~~ -CREATE VIEW test_conv_string_to_date_v1 as ( +CREATE VIEW test_conv_money_to_string_v1 as ( SELECT val, val_convert = '$' + CONVERT(VARCHAR, val) , val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), @@ -16,7 +16,7 @@ CREATE VIEW test_conv_string_to_date_v1 as ( ); GO -CREATE PROCEDURE test_conv_string_to_date_p1 as ( +CREATE PROCEDURE test_conv_money_to_string_p1 as ( SELECT val, val_convert = '$' + CONVERT(VARCHAR, val) , val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), @@ -26,7 +26,7 @@ CREATE PROCEDURE test_conv_string_to_date_p1 as ( ); GO -CREATE FUNCTION test_conv_string_to_date_f1() +CREATE FUNCTION test_conv_money_to_string_f1() RETURNS TABLE AS RETURN ( SELECT val, diff --git a/test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out b/test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out index ba99be29c3..b9650447f2 100644 --- a/test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out +++ b/test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out @@ -385,7 +385,7 @@ money#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar -- Dependent objects -SELECT * FROM test_conv_string_to_date_v1 +SELECT * FROM test_conv_money_to_string_v1 GO ~~START~~ money#!#varchar#!#varchar#!#varchar#!#varchar @@ -396,7 +396,7 @@ money#!#varchar#!#varchar#!#varchar#!#varchar ~~END~~ -EXEC test_conv_string_to_date_p1 +EXEC test_conv_money_to_string_p1 GO ~~START~~ money#!#varchar#!#varchar#!#varchar#!#varchar @@ -407,7 +407,7 @@ money#!#varchar#!#varchar#!#varchar#!#varchar ~~END~~ -SELECT * FROM test_conv_string_to_date_f1() +SELECT * FROM test_conv_money_to_string_f1() GO ~~START~~ money#!#varchar#!#varchar#!#varchar#!#varchar diff --git a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-cleanup.sql index de0c5e4c6e..f7f9931e9d 100644 --- a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-cleanup.sql +++ b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-cleanup.sql @@ -1,10 +1,10 @@ -DROP VIEW test_conv_string_to_date_v1 +DROP VIEW test_conv_money_to_string_v1 GO -DROP PROCEDURE test_conv_string_to_date_p1 +DROP PROCEDURE test_conv_money_to_string_p1 GO -DROP FUNCTION test_conv_string_to_date_f1 +DROP FUNCTION test_conv_money_to_string_f1 GO DROP TABLE test_conv_money_to_varchar_t1 diff --git a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-prepare.sql b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-prepare.sql index 9cbe407788..50f5f1d3fa 100644 --- a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-prepare.sql +++ b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-prepare.sql @@ -4,7 +4,7 @@ GO INSERT INTO test_conv_money_to_varchar_t1 VALUES (1234), (0), (123.12), (0.12456) GO -CREATE VIEW test_conv_string_to_date_v1 as ( +CREATE VIEW test_conv_money_to_string_v1 as ( SELECT val, val_convert = '$' + CONVERT(VARCHAR, val) , val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), @@ -14,7 +14,7 @@ CREATE VIEW test_conv_string_to_date_v1 as ( ); GO -CREATE PROCEDURE test_conv_string_to_date_p1 as ( +CREATE PROCEDURE test_conv_money_to_string_p1 as ( SELECT val, val_convert = '$' + CONVERT(VARCHAR, val) , val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), @@ -24,7 +24,7 @@ CREATE PROCEDURE test_conv_string_to_date_p1 as ( ); GO -CREATE FUNCTION test_conv_string_to_date_f1() +CREATE FUNCTION test_conv_money_to_string_f1() RETURNS TABLE AS RETURN ( SELECT val, diff --git a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-verify.sql b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-verify.sql index 6c55387e03..42e6560ece 100644 --- a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-verify.sql +++ b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-verify.sql @@ -237,11 +237,11 @@ FROM test_conv_money_to_varchar_t1 GO -- Dependent objects -SELECT * FROM test_conv_string_to_date_v1 +SELECT * FROM test_conv_money_to_string_v1 GO -EXEC test_conv_string_to_date_p1 +EXEC test_conv_money_to_string_p1 GO -SELECT * FROM test_conv_string_to_date_f1() +SELECT * FROM test_conv_money_to_string_f1() GO From 6ae5ede692a8cc27b3b2348b4b6ffc0807cc4026 Mon Sep 17 00:00:00 2001 From: Rohit Bhagat Date: Tue, 7 Jan 2025 05:34:21 +0000 Subject: [PATCH 10/10] updated object name in test file and updated expected output Signed-off-by: Rohit Bhagat --- .../BABEL-3486-before-17_3-vu-verify.out | 4 +- .../test_conv_money_to_varchar-vu-cleanup.out | 6 +- .../test_conv_money_to_varchar-vu-prepare.out | 6 +- .../test_conv_money_to_varchar-vu-verify.out | 6 +- ..._string_to_date-before-13_6-vu-cleanup.out | 60 +++++++++---------- ..._string_to_date-before-13_6-vu-prepare.out | 60 +++++++++---------- ...v_string_to_date-before-13_6-vu-verify.out | 60 +++++++++---------- ..._string_to_date-before-17_3-vu-cleanup.out | 58 +++++++++--------- ..._string_to_date-before-17_3-vu-prepare.out | 58 +++++++++--------- ...v_string_to_date-before-17_3-vu-verify.out | 58 +++++++++--------- .../test_conv_string_to_date-vu-cleanup.out | 60 +++++++++---------- .../test_conv_string_to_date-vu-prepare.out | 60 +++++++++---------- .../test_conv_string_to_date-vu-verify.out | 60 +++++++++---------- .../test_conv_money_to_varchar-vu-cleanup.sql | 6 +- .../test_conv_money_to_varchar-vu-prepare.sql | 6 +- .../test_conv_money_to_varchar-vu-verify.sql | 6 +- ..._string_to_date-before-13_6-vu-cleanup.sql | 60 +++++++++---------- ..._string_to_date-before-13_6-vu-prepare.sql | 60 +++++++++---------- ...v_string_to_date-before-13_6-vu-verify.sql | 60 +++++++++---------- ..._string_to_date-before-17_3-vu-cleanup.sql | 58 +++++++++--------- ..._string_to_date-before-17_3-vu-prepare.sql | 58 +++++++++--------- ...v_string_to_date-before-17_3-vu-verify.sql | 58 +++++++++--------- .../test_conv_string_to_date-vu-cleanup.sql | 60 +++++++++---------- .../test_conv_string_to_date-vu-prepare.sql | 60 +++++++++---------- .../test_conv_string_to_date-vu-verify.sql | 60 +++++++++---------- 25 files changed, 554 insertions(+), 554 deletions(-) diff --git a/test/JDBC/expected/BABEL-3486-before-17_3-vu-verify.out b/test/JDBC/expected/BABEL-3486-before-17_3-vu-verify.out index d2de0277ef..3e9f386070 100644 --- a/test/JDBC/expected/BABEL-3486-before-17_3-vu-verify.out +++ b/test/JDBC/expected/BABEL-3486-before-17_3-vu-verify.out @@ -1316,7 +1316,7 @@ SELECT * FROM BABEL_3486_vu_prepare_v54 GO ~~START~~ varchar - 5.00 +5.00 ~~END~~ DROP VIEW BABEL_3486_vu_prepare_v54 @@ -1326,7 +1326,7 @@ EXEC BABEL_3486_vu_prepare_p54 GO ~~START~~ varchar - 5.00 +5.00 ~~END~~ DROP PROCEDURE BABEL_3486_vu_prepare_p54 diff --git a/test/JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out b/test/JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out index f7f9931e9d..de0c5e4c6e 100644 --- a/test/JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out +++ b/test/JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out @@ -1,10 +1,10 @@ -DROP VIEW test_conv_money_to_string_v1 +DROP VIEW test_conv_string_to_date_v1 GO -DROP PROCEDURE test_conv_money_to_string_p1 +DROP PROCEDURE test_conv_string_to_date_p1 GO -DROP FUNCTION test_conv_money_to_string_f1 +DROP FUNCTION test_conv_string_to_date_f1 GO DROP TABLE test_conv_money_to_varchar_t1 diff --git a/test/JDBC/expected/test_conv_money_to_varchar-vu-prepare.out b/test/JDBC/expected/test_conv_money_to_varchar-vu-prepare.out index a90840abbd..559ceae53b 100644 --- a/test/JDBC/expected/test_conv_money_to_varchar-vu-prepare.out +++ b/test/JDBC/expected/test_conv_money_to_varchar-vu-prepare.out @@ -6,7 +6,7 @@ GO ~~ROW COUNT: 4~~ -CREATE VIEW test_conv_money_to_string_v1 as ( +CREATE VIEW test_conv_string_to_date_v1 as ( SELECT val, val_convert = '$' + CONVERT(VARCHAR, val) , val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), @@ -16,7 +16,7 @@ CREATE VIEW test_conv_money_to_string_v1 as ( ); GO -CREATE PROCEDURE test_conv_money_to_string_p1 as ( +CREATE PROCEDURE test_conv_string_to_date_p1 as ( SELECT val, val_convert = '$' + CONVERT(VARCHAR, val) , val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), @@ -26,7 +26,7 @@ CREATE PROCEDURE test_conv_money_to_string_p1 as ( ); GO -CREATE FUNCTION test_conv_money_to_string_f1() +CREATE FUNCTION test_conv_string_to_date_f1() RETURNS TABLE AS RETURN ( SELECT val, diff --git a/test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out b/test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out index b9650447f2..ba99be29c3 100644 --- a/test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out +++ b/test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out @@ -385,7 +385,7 @@ money#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar -- Dependent objects -SELECT * FROM test_conv_money_to_string_v1 +SELECT * FROM test_conv_string_to_date_v1 GO ~~START~~ money#!#varchar#!#varchar#!#varchar#!#varchar @@ -396,7 +396,7 @@ money#!#varchar#!#varchar#!#varchar#!#varchar ~~END~~ -EXEC test_conv_money_to_string_p1 +EXEC test_conv_string_to_date_p1 GO ~~START~~ money#!#varchar#!#varchar#!#varchar#!#varchar @@ -407,7 +407,7 @@ money#!#varchar#!#varchar#!#varchar#!#varchar ~~END~~ -SELECT * FROM test_conv_money_to_string_f1() +SELECT * FROM test_conv_string_to_date_f1() GO ~~START~~ money#!#varchar#!#varchar#!#varchar#!#varchar diff --git a/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-cleanup.out index 886da40797..07d38aedb9 100644 --- a/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-cleanup.out +++ b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-cleanup.out @@ -1,71 +1,71 @@ -DROP VIEW test_conv_string_to_date_v1 +DROP VIEW babel_4896_test_conv_string_to_date_v1 GO -DROP PROCEDURE test_conv_string_to_date_p1 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p1 GO -DROP FUNCTION test_conv_string_to_date_f1() +DROP FUNCTION babel_4896_test_conv_string_to_date_f1() GO -DROP VIEW test_conv_string_to_date_v2 +DROP VIEW babel_4896_test_conv_string_to_date_v2 GO -DROP PROCEDURE test_conv_string_to_date_p2 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p2 GO -DROP FUNCTION test_conv_string_to_date_f2() +DROP FUNCTION babel_4896_test_conv_string_to_date_f2() GO -DROP VIEW test_conv_string_to_date_v3 +DROP VIEW babel_4896_test_conv_string_to_date_v3 GO -DROP PROCEDURE test_conv_string_to_date_p3 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p3 GO -DROP FUNCTION test_conv_string_to_date_f3() +DROP FUNCTION babel_4896_test_conv_string_to_date_f3() GO -DROP VIEW test_conv_string_to_date_v4 +DROP VIEW babel_4896_test_conv_string_to_date_v4 GO -DROP PROCEDURE test_conv_string_to_date_p4 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p4 GO -DROP FUNCTION test_conv_string_to_date_f4() +DROP FUNCTION babel_4896_test_conv_string_to_date_f4() GO -DROP VIEW test_conv_string_to_date_v5 +DROP VIEW babel_4896_test_conv_string_to_date_v5 GO -DROP PROCEDURE test_conv_string_to_date_p5 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p5 GO -DROP FUNCTION test_conv_string_to_date_f5() +DROP FUNCTION babel_4896_test_conv_string_to_date_f5() GO -DROP VIEW test_conv_string_to_date_v6 +DROP VIEW babel_4896_test_conv_string_to_date_v6 GO -DROP PROCEDURE test_conv_string_to_date_p6 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p6 GO -DROP FUNCTION test_conv_string_to_date_f6() +DROP FUNCTION babel_4896_test_conv_string_to_date_f6() GO -DROP VIEW test_conv_string_to_date_v7 +DROP VIEW babel_4896_test_conv_string_to_date_v7 GO -DROP PROCEDURE test_conv_string_to_date_p7 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p7 GO -DROP FUNCTION test_conv_string_to_date_f7() +DROP FUNCTION babel_4896_test_conv_string_to_date_f7() GO -DROP VIEW test_conv_string_to_date_v8 +DROP VIEW babel_4896_test_conv_string_to_date_v8 GO -DROP PROCEDURE test_conv_string_to_date_p8 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p8 GO -DROP FUNCTION test_conv_string_to_date_f8() +DROP FUNCTION babel_4896_test_conv_string_to_date_f8() GO -DROP VIEW test_conv_string_to_date_v9 +DROP VIEW babel_4896_test_conv_string_to_date_v9 GO -DROP PROCEDURE test_conv_string_to_date_p9 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p9 GO -DROP FUNCTION test_conv_string_to_date_f9() +DROP FUNCTION babel_4896_test_conv_string_to_date_f9() GO -DROP VIEW test_conv_string_to_date_v10 +DROP VIEW babel_4896_test_conv_string_to_date_v10 GO -DROP VIEW test_conv_string_to_date_v11 +DROP VIEW babel_4896_test_conv_string_to_date_v11 GO -DROP VIEW test_conv_string_to_date_v12 +DROP VIEW babel_4896_test_conv_string_to_date_v12 GO diff --git a/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-prepare.out index b6ba0b7f72..1a15d02fc0 100644 --- a/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-prepare.out +++ b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-prepare.out @@ -1,107 +1,107 @@ -CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f1() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f1() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '2017-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f2() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f2() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '9999-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +CREATE VIEW babel_4896_test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE FUNCTION test_conv_string_to_date_f3() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f3() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '13:01:59')); END GO -CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE VIEW babel_4896_test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE FUNCTION test_conv_string_to_date_f4() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f4() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); END GO -CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f5() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f5() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f6() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f6() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f7() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f7() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE FUNCTION test_conv_string_to_date_f8() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f8() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); END GO -CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f9() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f9() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +CREATE VIEW babel_4896_test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); GO -CREATE VIEW test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); +CREATE VIEW babel_4896_test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); GO -CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); GO diff --git a/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out index b9fa5eb983..eaffc2b1d1 100644 --- a/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out +++ b/test/JDBC/expected/test_conv_string_to_date-before-13_6-vu-verify.out @@ -3524,21 +3524,21 @@ date -- Dependent objects -SELECT * FROM test_conv_string_to_date_v1 +SELECT * FROM babel_4896_test_conv_string_to_date_v1 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p1 +EXEC babel_4896_test_conv_string_to_date_p1 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f1() +SELECT babel_4896_test_conv_string_to_date_f1() GO ~~START~~ date @@ -3546,21 +3546,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v2 +SELECT * FROM babel_4896_test_conv_string_to_date_v2 GO ~~START~~ date 9999-08-25 ~~END~~ -EXEC test_conv_string_to_date_p2 +EXEC babel_4896_test_conv_string_to_date_p2 GO ~~START~~ date 9999-08-25 ~~END~~ -SELECT test_conv_string_to_date_f2() +SELECT babel_4896_test_conv_string_to_date_f2() GO ~~START~~ date @@ -3568,21 +3568,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v3 +SELECT * FROM babel_4896_test_conv_string_to_date_v3 GO ~~START~~ date 1900-01-01 ~~END~~ -EXEC test_conv_string_to_date_p3 +EXEC babel_4896_test_conv_string_to_date_p3 GO ~~START~~ date 1900-01-01 ~~END~~ -SELECT test_conv_string_to_date_f3() +SELECT babel_4896_test_conv_string_to_date_f3() GO ~~START~~ date @@ -3590,21 +3590,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v4 +SELECT * FROM babel_4896_test_conv_string_to_date_v4 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p4 +EXEC babel_4896_test_conv_string_to_date_p4 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f4() +SELECT babel_4896_test_conv_string_to_date_f4() GO ~~START~~ date @@ -3612,21 +3612,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v5 +SELECT * FROM babel_4896_test_conv_string_to_date_v5 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p5 +EXEC babel_4896_test_conv_string_to_date_p5 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f5() +SELECT babel_4896_test_conv_string_to_date_f5() GO ~~START~~ date @@ -3634,21 +3634,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v6 +SELECT * FROM babel_4896_test_conv_string_to_date_v6 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p6 +EXEC babel_4896_test_conv_string_to_date_p6 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f6() +SELECT babel_4896_test_conv_string_to_date_f6() GO ~~START~~ date @@ -3656,21 +3656,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v7 +SELECT * FROM babel_4896_test_conv_string_to_date_v7 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p7 +EXEC babel_4896_test_conv_string_to_date_p7 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f7() +SELECT babel_4896_test_conv_string_to_date_f7() GO ~~START~~ date @@ -3678,19 +3678,19 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v8 +SELECT * FROM babel_4896_test_conv_string_to_date_v8 GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ -EXEC test_conv_string_to_date_p8 +EXEC babel_4896_test_conv_string_to_date_p8 GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ -SELECT test_conv_string_to_date_f8() +SELECT babel_4896_test_conv_string_to_date_f8() GO ~~START~~ date @@ -3699,21 +3699,21 @@ date ~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ -SELECT * FROM test_conv_string_to_date_v9 +SELECT * FROM babel_4896_test_conv_string_to_date_v9 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p9 +EXEC babel_4896_test_conv_string_to_date_p9 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f9() +SELECT babel_4896_test_conv_string_to_date_f9() GO ~~START~~ date @@ -3721,21 +3721,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v10 +SELECT * FROM babel_4896_test_conv_string_to_date_v10 GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ -SELECT * FROM test_conv_string_to_date_v11 +SELECT * FROM babel_4896_test_conv_string_to_date_v11 GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ -SELECT * FROM test_conv_string_to_date_v12 +SELECT * FROM babel_4896_test_conv_string_to_date_v12 GO ~~ERROR (Code: 33557097)~~ diff --git a/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-cleanup.out index 9b75accd45..49032ca5a4 100644 --- a/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-cleanup.out +++ b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-cleanup.out @@ -1,68 +1,68 @@ -DROP VIEW test_conv_string_to_date_v1 +DROP VIEW babel_4896_test_conv_string_to_date_v1 GO -DROP PROCEDURE test_conv_string_to_date_p1 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p1 GO -DROP FUNCTION test_conv_string_to_date_f1() +DROP FUNCTION babel_4896_test_conv_string_to_date_f1() GO -DROP VIEW test_conv_string_to_date_v2 +DROP VIEW babel_4896_test_conv_string_to_date_v2 GO -DROP PROCEDURE test_conv_string_to_date_p2 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p2 GO -DROP FUNCTION test_conv_string_to_date_f2() +DROP FUNCTION babel_4896_test_conv_string_to_date_f2() GO -DROP VIEW test_conv_string_to_date_v3 +DROP VIEW babel_4896_test_conv_string_to_date_v3 GO -DROP PROCEDURE test_conv_string_to_date_p3 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p3 GO -DROP FUNCTION test_conv_string_to_date_f3() +DROP FUNCTION babel_4896_test_conv_string_to_date_f3() GO -DROP VIEW test_conv_string_to_date_v4 +DROP VIEW babel_4896_test_conv_string_to_date_v4 GO -DROP PROCEDURE test_conv_string_to_date_p4 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p4 GO -DROP FUNCTION test_conv_string_to_date_f4() +DROP FUNCTION babel_4896_test_conv_string_to_date_f4() GO -DROP VIEW test_conv_string_to_date_v5 +DROP VIEW babel_4896_test_conv_string_to_date_v5 GO -DROP PROCEDURE test_conv_string_to_date_p5 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p5 GO -DROP FUNCTION test_conv_string_to_date_f5() +DROP FUNCTION babel_4896_test_conv_string_to_date_f5() GO -DROP VIEW test_conv_string_to_date_v6 +DROP VIEW babel_4896_test_conv_string_to_date_v6 GO -DROP PROCEDURE test_conv_string_to_date_p6 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p6 GO -DROP FUNCTION test_conv_string_to_date_f6() +DROP FUNCTION babel_4896_test_conv_string_to_date_f6() GO -DROP VIEW test_conv_string_to_date_v7 +DROP VIEW babel_4896_test_conv_string_to_date_v7 GO -DROP PROCEDURE test_conv_string_to_date_p7 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p7 GO -DROP FUNCTION test_conv_string_to_date_f7() +DROP FUNCTION babel_4896_test_conv_string_to_date_f7() GO -DROP VIEW test_conv_string_to_date_v8 +DROP VIEW babel_4896_test_conv_string_to_date_v8 GO -DROP PROCEDURE test_conv_string_to_date_p8 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p8 GO -DROP FUNCTION test_conv_string_to_date_f8() +DROP FUNCTION babel_4896_test_conv_string_to_date_f8() GO -DROP VIEW test_conv_string_to_date_v9 +DROP VIEW babel_4896_test_conv_string_to_date_v9 GO -DROP PROCEDURE test_conv_string_to_date_p9 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p9 GO -DROP FUNCTION test_conv_string_to_date_f9() +DROP FUNCTION babel_4896_test_conv_string_to_date_f9() GO -DROP VIEW test_conv_string_to_date_v10 +DROP VIEW babel_4896_test_conv_string_to_date_v10 GO -DROP VIEW test_conv_string_to_date_v12 +DROP VIEW babel_4896_test_conv_string_to_date_v12 GO diff --git a/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-prepare.out index fa4fbdf743..e61d2500bd 100644 --- a/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-prepare.out +++ b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-prepare.out @@ -1,104 +1,104 @@ -CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f1() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f1() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '2017-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f2() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f2() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '9999-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +CREATE VIEW babel_4896_test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE FUNCTION test_conv_string_to_date_f3() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f3() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '13:01:59')); END GO -CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE VIEW babel_4896_test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE FUNCTION test_conv_string_to_date_f4() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f4() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); END GO -CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f5() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f5() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f6() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f6() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f7() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f7() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE FUNCTION test_conv_string_to_date_f8() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f8() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); END GO -CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f9() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f9() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +CREATE VIEW babel_4896_test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); GO -CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); GO diff --git a/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out index 4fb732d83b..1f967ff171 100644 --- a/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out +++ b/test/JDBC/expected/test_conv_string_to_date-before-17_3-vu-verify.out @@ -3524,21 +3524,21 @@ date -- Dependent objects -SELECT * FROM test_conv_string_to_date_v1 +SELECT * FROM babel_4896_test_conv_string_to_date_v1 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p1 +EXEC babel_4896_test_conv_string_to_date_p1 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f1() +SELECT babel_4896_test_conv_string_to_date_f1() GO ~~START~~ date @@ -3546,21 +3546,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v2 +SELECT * FROM babel_4896_test_conv_string_to_date_v2 GO ~~START~~ date 9999-08-25 ~~END~~ -EXEC test_conv_string_to_date_p2 +EXEC babel_4896_test_conv_string_to_date_p2 GO ~~START~~ date 9999-08-25 ~~END~~ -SELECT test_conv_string_to_date_f2() +SELECT babel_4896_test_conv_string_to_date_f2() GO ~~START~~ date @@ -3568,21 +3568,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v3 +SELECT * FROM babel_4896_test_conv_string_to_date_v3 GO ~~START~~ date 1900-01-01 ~~END~~ -EXEC test_conv_string_to_date_p3 +EXEC babel_4896_test_conv_string_to_date_p3 GO ~~START~~ date 1900-01-01 ~~END~~ -SELECT test_conv_string_to_date_f3() +SELECT babel_4896_test_conv_string_to_date_f3() GO ~~START~~ date @@ -3590,21 +3590,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v4 +SELECT * FROM babel_4896_test_conv_string_to_date_v4 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p4 +EXEC babel_4896_test_conv_string_to_date_p4 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f4() +SELECT babel_4896_test_conv_string_to_date_f4() GO ~~START~~ date @@ -3612,21 +3612,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v5 +SELECT * FROM babel_4896_test_conv_string_to_date_v5 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p5 +EXEC babel_4896_test_conv_string_to_date_p5 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f5() +SELECT babel_4896_test_conv_string_to_date_f5() GO ~~START~~ date @@ -3634,21 +3634,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v6 +SELECT * FROM babel_4896_test_conv_string_to_date_v6 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p6 +EXEC babel_4896_test_conv_string_to_date_p6 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f6() +SELECT babel_4896_test_conv_string_to_date_f6() GO ~~START~~ date @@ -3656,21 +3656,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v7 +SELECT * FROM babel_4896_test_conv_string_to_date_v7 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p7 +EXEC babel_4896_test_conv_string_to_date_p7 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f7() +SELECT babel_4896_test_conv_string_to_date_f7() GO ~~START~~ date @@ -3678,19 +3678,19 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v8 +SELECT * FROM babel_4896_test_conv_string_to_date_v8 GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ -EXEC test_conv_string_to_date_p8 +EXEC babel_4896_test_conv_string_to_date_p8 GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ -SELECT test_conv_string_to_date_f8() +SELECT babel_4896_test_conv_string_to_date_f8() GO ~~START~~ date @@ -3699,21 +3699,21 @@ date ~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ -SELECT * FROM test_conv_string_to_date_v9 +SELECT * FROM babel_4896_test_conv_string_to_date_v9 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p9 +EXEC babel_4896_test_conv_string_to_date_p9 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f9() +SELECT babel_4896_test_conv_string_to_date_f9() GO ~~START~~ date @@ -3721,14 +3721,14 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v10 +SELECT * FROM babel_4896_test_conv_string_to_date_v10 GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ -SELECT * FROM test_conv_string_to_date_v12 +SELECT * FROM babel_4896_test_conv_string_to_date_v12 GO ~~ERROR (Code: 33557097)~~ diff --git a/test/JDBC/expected/test_conv_string_to_date-vu-cleanup.out b/test/JDBC/expected/test_conv_string_to_date-vu-cleanup.out index 886da40797..07d38aedb9 100644 --- a/test/JDBC/expected/test_conv_string_to_date-vu-cleanup.out +++ b/test/JDBC/expected/test_conv_string_to_date-vu-cleanup.out @@ -1,71 +1,71 @@ -DROP VIEW test_conv_string_to_date_v1 +DROP VIEW babel_4896_test_conv_string_to_date_v1 GO -DROP PROCEDURE test_conv_string_to_date_p1 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p1 GO -DROP FUNCTION test_conv_string_to_date_f1() +DROP FUNCTION babel_4896_test_conv_string_to_date_f1() GO -DROP VIEW test_conv_string_to_date_v2 +DROP VIEW babel_4896_test_conv_string_to_date_v2 GO -DROP PROCEDURE test_conv_string_to_date_p2 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p2 GO -DROP FUNCTION test_conv_string_to_date_f2() +DROP FUNCTION babel_4896_test_conv_string_to_date_f2() GO -DROP VIEW test_conv_string_to_date_v3 +DROP VIEW babel_4896_test_conv_string_to_date_v3 GO -DROP PROCEDURE test_conv_string_to_date_p3 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p3 GO -DROP FUNCTION test_conv_string_to_date_f3() +DROP FUNCTION babel_4896_test_conv_string_to_date_f3() GO -DROP VIEW test_conv_string_to_date_v4 +DROP VIEW babel_4896_test_conv_string_to_date_v4 GO -DROP PROCEDURE test_conv_string_to_date_p4 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p4 GO -DROP FUNCTION test_conv_string_to_date_f4() +DROP FUNCTION babel_4896_test_conv_string_to_date_f4() GO -DROP VIEW test_conv_string_to_date_v5 +DROP VIEW babel_4896_test_conv_string_to_date_v5 GO -DROP PROCEDURE test_conv_string_to_date_p5 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p5 GO -DROP FUNCTION test_conv_string_to_date_f5() +DROP FUNCTION babel_4896_test_conv_string_to_date_f5() GO -DROP VIEW test_conv_string_to_date_v6 +DROP VIEW babel_4896_test_conv_string_to_date_v6 GO -DROP PROCEDURE test_conv_string_to_date_p6 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p6 GO -DROP FUNCTION test_conv_string_to_date_f6() +DROP FUNCTION babel_4896_test_conv_string_to_date_f6() GO -DROP VIEW test_conv_string_to_date_v7 +DROP VIEW babel_4896_test_conv_string_to_date_v7 GO -DROP PROCEDURE test_conv_string_to_date_p7 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p7 GO -DROP FUNCTION test_conv_string_to_date_f7() +DROP FUNCTION babel_4896_test_conv_string_to_date_f7() GO -DROP VIEW test_conv_string_to_date_v8 +DROP VIEW babel_4896_test_conv_string_to_date_v8 GO -DROP PROCEDURE test_conv_string_to_date_p8 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p8 GO -DROP FUNCTION test_conv_string_to_date_f8() +DROP FUNCTION babel_4896_test_conv_string_to_date_f8() GO -DROP VIEW test_conv_string_to_date_v9 +DROP VIEW babel_4896_test_conv_string_to_date_v9 GO -DROP PROCEDURE test_conv_string_to_date_p9 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p9 GO -DROP FUNCTION test_conv_string_to_date_f9() +DROP FUNCTION babel_4896_test_conv_string_to_date_f9() GO -DROP VIEW test_conv_string_to_date_v10 +DROP VIEW babel_4896_test_conv_string_to_date_v10 GO -DROP VIEW test_conv_string_to_date_v11 +DROP VIEW babel_4896_test_conv_string_to_date_v11 GO -DROP VIEW test_conv_string_to_date_v12 +DROP VIEW babel_4896_test_conv_string_to_date_v12 GO diff --git a/test/JDBC/expected/test_conv_string_to_date-vu-prepare.out b/test/JDBC/expected/test_conv_string_to_date-vu-prepare.out index b6ba0b7f72..1a15d02fc0 100644 --- a/test/JDBC/expected/test_conv_string_to_date-vu-prepare.out +++ b/test/JDBC/expected/test_conv_string_to_date-vu-prepare.out @@ -1,107 +1,107 @@ -CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f1() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f1() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '2017-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f2() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f2() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '9999-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +CREATE VIEW babel_4896_test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE FUNCTION test_conv_string_to_date_f3() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f3() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '13:01:59')); END GO -CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE VIEW babel_4896_test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE FUNCTION test_conv_string_to_date_f4() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f4() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); END GO -CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f5() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f5() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f6() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f6() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f7() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f7() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE FUNCTION test_conv_string_to_date_f8() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f8() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); END GO -CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f9() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f9() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +CREATE VIEW babel_4896_test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); GO -CREATE VIEW test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); +CREATE VIEW babel_4896_test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); GO -CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); GO diff --git a/test/JDBC/expected/test_conv_string_to_date-vu-verify.out b/test/JDBC/expected/test_conv_string_to_date-vu-verify.out index b9fa5eb983..eaffc2b1d1 100644 --- a/test/JDBC/expected/test_conv_string_to_date-vu-verify.out +++ b/test/JDBC/expected/test_conv_string_to_date-vu-verify.out @@ -3524,21 +3524,21 @@ date -- Dependent objects -SELECT * FROM test_conv_string_to_date_v1 +SELECT * FROM babel_4896_test_conv_string_to_date_v1 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p1 +EXEC babel_4896_test_conv_string_to_date_p1 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f1() +SELECT babel_4896_test_conv_string_to_date_f1() GO ~~START~~ date @@ -3546,21 +3546,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v2 +SELECT * FROM babel_4896_test_conv_string_to_date_v2 GO ~~START~~ date 9999-08-25 ~~END~~ -EXEC test_conv_string_to_date_p2 +EXEC babel_4896_test_conv_string_to_date_p2 GO ~~START~~ date 9999-08-25 ~~END~~ -SELECT test_conv_string_to_date_f2() +SELECT babel_4896_test_conv_string_to_date_f2() GO ~~START~~ date @@ -3568,21 +3568,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v3 +SELECT * FROM babel_4896_test_conv_string_to_date_v3 GO ~~START~~ date 1900-01-01 ~~END~~ -EXEC test_conv_string_to_date_p3 +EXEC babel_4896_test_conv_string_to_date_p3 GO ~~START~~ date 1900-01-01 ~~END~~ -SELECT test_conv_string_to_date_f3() +SELECT babel_4896_test_conv_string_to_date_f3() GO ~~START~~ date @@ -3590,21 +3590,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v4 +SELECT * FROM babel_4896_test_conv_string_to_date_v4 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p4 +EXEC babel_4896_test_conv_string_to_date_p4 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f4() +SELECT babel_4896_test_conv_string_to_date_f4() GO ~~START~~ date @@ -3612,21 +3612,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v5 +SELECT * FROM babel_4896_test_conv_string_to_date_v5 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p5 +EXEC babel_4896_test_conv_string_to_date_p5 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f5() +SELECT babel_4896_test_conv_string_to_date_f5() GO ~~START~~ date @@ -3634,21 +3634,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v6 +SELECT * FROM babel_4896_test_conv_string_to_date_v6 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p6 +EXEC babel_4896_test_conv_string_to_date_p6 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f6() +SELECT babel_4896_test_conv_string_to_date_f6() GO ~~START~~ date @@ -3656,21 +3656,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v7 +SELECT * FROM babel_4896_test_conv_string_to_date_v7 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p7 +EXEC babel_4896_test_conv_string_to_date_p7 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f7() +SELECT babel_4896_test_conv_string_to_date_f7() GO ~~START~~ date @@ -3678,19 +3678,19 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v8 +SELECT * FROM babel_4896_test_conv_string_to_date_v8 GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ -EXEC test_conv_string_to_date_p8 +EXEC babel_4896_test_conv_string_to_date_p8 GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ -SELECT test_conv_string_to_date_f8() +SELECT babel_4896_test_conv_string_to_date_f8() GO ~~START~~ date @@ -3699,21 +3699,21 @@ date ~~ERROR (Message: Explicit conversion from data type integer to date is not allowed.)~~ -SELECT * FROM test_conv_string_to_date_v9 +SELECT * FROM babel_4896_test_conv_string_to_date_v9 GO ~~START~~ date 2017-08-25 ~~END~~ -EXEC test_conv_string_to_date_p9 +EXEC babel_4896_test_conv_string_to_date_p9 GO ~~START~~ date 2017-08-25 ~~END~~ -SELECT test_conv_string_to_date_f9() +SELECT babel_4896_test_conv_string_to_date_f9() GO ~~START~~ date @@ -3721,21 +3721,21 @@ date ~~END~~ -SELECT * FROM test_conv_string_to_date_v10 +SELECT * FROM babel_4896_test_conv_string_to_date_v10 GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ -SELECT * FROM test_conv_string_to_date_v11 +SELECT * FROM babel_4896_test_conv_string_to_date_v11 GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The input character string does not follow style 130, either change the input character string or use a different style.)~~ -SELECT * FROM test_conv_string_to_date_v12 +SELECT * FROM babel_4896_test_conv_string_to_date_v12 GO ~~ERROR (Code: 33557097)~~ diff --git a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-cleanup.sql index f7f9931e9d..de0c5e4c6e 100644 --- a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-cleanup.sql +++ b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-cleanup.sql @@ -1,10 +1,10 @@ -DROP VIEW test_conv_money_to_string_v1 +DROP VIEW test_conv_string_to_date_v1 GO -DROP PROCEDURE test_conv_money_to_string_p1 +DROP PROCEDURE test_conv_string_to_date_p1 GO -DROP FUNCTION test_conv_money_to_string_f1 +DROP FUNCTION test_conv_string_to_date_f1 GO DROP TABLE test_conv_money_to_varchar_t1 diff --git a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-prepare.sql b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-prepare.sql index 50f5f1d3fa..9cbe407788 100644 --- a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-prepare.sql +++ b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-prepare.sql @@ -4,7 +4,7 @@ GO INSERT INTO test_conv_money_to_varchar_t1 VALUES (1234), (0), (123.12), (0.12456) GO -CREATE VIEW test_conv_money_to_string_v1 as ( +CREATE VIEW test_conv_string_to_date_v1 as ( SELECT val, val_convert = '$' + CONVERT(VARCHAR, val) , val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), @@ -14,7 +14,7 @@ CREATE VIEW test_conv_money_to_string_v1 as ( ); GO -CREATE PROCEDURE test_conv_money_to_string_p1 as ( +CREATE PROCEDURE test_conv_string_to_date_p1 as ( SELECT val, val_convert = '$' + CONVERT(VARCHAR, val) , val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), @@ -24,7 +24,7 @@ CREATE PROCEDURE test_conv_money_to_string_p1 as ( ); GO -CREATE FUNCTION test_conv_money_to_string_f1() +CREATE FUNCTION test_conv_string_to_date_f1() RETURNS TABLE AS RETURN ( SELECT val, diff --git a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-verify.sql b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-verify.sql index 42e6560ece..6c55387e03 100644 --- a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-verify.sql +++ b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-verify.sql @@ -237,11 +237,11 @@ FROM test_conv_money_to_varchar_t1 GO -- Dependent objects -SELECT * FROM test_conv_money_to_string_v1 +SELECT * FROM test_conv_string_to_date_v1 GO -EXEC test_conv_money_to_string_p1 +EXEC test_conv_string_to_date_p1 GO -SELECT * FROM test_conv_money_to_string_f1() +SELECT * FROM test_conv_string_to_date_f1() GO diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-cleanup.sql index c6ca5aedf4..187be36612 100644 --- a/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-cleanup.sql +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-cleanup.sql @@ -1,71 +1,71 @@ -DROP VIEW test_conv_string_to_date_v1 +DROP VIEW babel_4896_test_conv_string_to_date_v1 GO -DROP PROCEDURE test_conv_string_to_date_p1 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p1 GO -DROP FUNCTION test_conv_string_to_date_f1() +DROP FUNCTION babel_4896_test_conv_string_to_date_f1() GO -DROP VIEW test_conv_string_to_date_v2 +DROP VIEW babel_4896_test_conv_string_to_date_v2 GO -DROP PROCEDURE test_conv_string_to_date_p2 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p2 GO -DROP FUNCTION test_conv_string_to_date_f2() +DROP FUNCTION babel_4896_test_conv_string_to_date_f2() GO -DROP VIEW test_conv_string_to_date_v3 +DROP VIEW babel_4896_test_conv_string_to_date_v3 GO -DROP PROCEDURE test_conv_string_to_date_p3 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p3 GO -DROP FUNCTION test_conv_string_to_date_f3() +DROP FUNCTION babel_4896_test_conv_string_to_date_f3() GO -DROP VIEW test_conv_string_to_date_v4 +DROP VIEW babel_4896_test_conv_string_to_date_v4 GO -DROP PROCEDURE test_conv_string_to_date_p4 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p4 GO -DROP FUNCTION test_conv_string_to_date_f4() +DROP FUNCTION babel_4896_test_conv_string_to_date_f4() GO -DROP VIEW test_conv_string_to_date_v5 +DROP VIEW babel_4896_test_conv_string_to_date_v5 GO -DROP PROCEDURE test_conv_string_to_date_p5 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p5 GO -DROP FUNCTION test_conv_string_to_date_f5() +DROP FUNCTION babel_4896_test_conv_string_to_date_f5() GO -DROP VIEW test_conv_string_to_date_v6 +DROP VIEW babel_4896_test_conv_string_to_date_v6 GO -DROP PROCEDURE test_conv_string_to_date_p6 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p6 GO -DROP FUNCTION test_conv_string_to_date_f6() +DROP FUNCTION babel_4896_test_conv_string_to_date_f6() GO -DROP VIEW test_conv_string_to_date_v7 +DROP VIEW babel_4896_test_conv_string_to_date_v7 GO -DROP PROCEDURE test_conv_string_to_date_p7 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p7 GO -DROP FUNCTION test_conv_string_to_date_f7() +DROP FUNCTION babel_4896_test_conv_string_to_date_f7() GO -DROP VIEW test_conv_string_to_date_v8 +DROP VIEW babel_4896_test_conv_string_to_date_v8 GO -DROP PROCEDURE test_conv_string_to_date_p8 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p8 GO -DROP FUNCTION test_conv_string_to_date_f8() +DROP FUNCTION babel_4896_test_conv_string_to_date_f8() GO -DROP VIEW test_conv_string_to_date_v9 +DROP VIEW babel_4896_test_conv_string_to_date_v9 GO -DROP PROCEDURE test_conv_string_to_date_p9 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p9 GO -DROP FUNCTION test_conv_string_to_date_f9() +DROP FUNCTION babel_4896_test_conv_string_to_date_f9() GO -DROP VIEW test_conv_string_to_date_v10 +DROP VIEW babel_4896_test_conv_string_to_date_v10 GO -DROP VIEW test_conv_string_to_date_v11 +DROP VIEW babel_4896_test_conv_string_to_date_v11 GO -DROP VIEW test_conv_string_to_date_v12 +DROP VIEW babel_4896_test_conv_string_to_date_v12 GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-prepare.sql index 7791067ede..3dae481af1 100644 --- a/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-prepare.sql +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-prepare.sql @@ -1,107 +1,107 @@ -CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f1() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f1() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '2017-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f2() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f2() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '9999-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +CREATE VIEW babel_4896_test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE FUNCTION test_conv_string_to_date_f3() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f3() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '13:01:59')); END GO -CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE VIEW babel_4896_test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE FUNCTION test_conv_string_to_date_f4() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f4() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); END GO -CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f5() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f5() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f6() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f6() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f7() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f7() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE FUNCTION test_conv_string_to_date_f8() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f8() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); END GO -CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f9() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f9() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +CREATE VIEW babel_4896_test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); GO -CREATE VIEW test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); +CREATE VIEW babel_4896_test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); GO -CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-verify.sql index c937660ad3..88ada2889a 100644 --- a/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-verify.sql +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-13_6-vu-verify.sql @@ -1408,74 +1408,74 @@ SELECT CONVERT(DATE, @TM_ICLO) GO -- Dependent objects -SELECT * FROM test_conv_string_to_date_v1 +SELECT * FROM babel_4896_test_conv_string_to_date_v1 GO -EXEC test_conv_string_to_date_p1 +EXEC babel_4896_test_conv_string_to_date_p1 GO -SELECT test_conv_string_to_date_f1() +SELECT babel_4896_test_conv_string_to_date_f1() GO -SELECT * FROM test_conv_string_to_date_v2 +SELECT * FROM babel_4896_test_conv_string_to_date_v2 GO -EXEC test_conv_string_to_date_p2 +EXEC babel_4896_test_conv_string_to_date_p2 GO -SELECT test_conv_string_to_date_f2() +SELECT babel_4896_test_conv_string_to_date_f2() GO -SELECT * FROM test_conv_string_to_date_v3 +SELECT * FROM babel_4896_test_conv_string_to_date_v3 GO -EXEC test_conv_string_to_date_p3 +EXEC babel_4896_test_conv_string_to_date_p3 GO -SELECT test_conv_string_to_date_f3() +SELECT babel_4896_test_conv_string_to_date_f3() GO -SELECT * FROM test_conv_string_to_date_v4 +SELECT * FROM babel_4896_test_conv_string_to_date_v4 GO -EXEC test_conv_string_to_date_p4 +EXEC babel_4896_test_conv_string_to_date_p4 GO -SELECT test_conv_string_to_date_f4() +SELECT babel_4896_test_conv_string_to_date_f4() GO -SELECT * FROM test_conv_string_to_date_v5 +SELECT * FROM babel_4896_test_conv_string_to_date_v5 GO -EXEC test_conv_string_to_date_p5 +EXEC babel_4896_test_conv_string_to_date_p5 GO -SELECT test_conv_string_to_date_f5() +SELECT babel_4896_test_conv_string_to_date_f5() GO -SELECT * FROM test_conv_string_to_date_v6 +SELECT * FROM babel_4896_test_conv_string_to_date_v6 GO -EXEC test_conv_string_to_date_p6 +EXEC babel_4896_test_conv_string_to_date_p6 GO -SELECT test_conv_string_to_date_f6() +SELECT babel_4896_test_conv_string_to_date_f6() GO -SELECT * FROM test_conv_string_to_date_v7 +SELECT * FROM babel_4896_test_conv_string_to_date_v7 GO -EXEC test_conv_string_to_date_p7 +EXEC babel_4896_test_conv_string_to_date_p7 GO -SELECT test_conv_string_to_date_f7() +SELECT babel_4896_test_conv_string_to_date_f7() GO -SELECT * FROM test_conv_string_to_date_v8 +SELECT * FROM babel_4896_test_conv_string_to_date_v8 GO -EXEC test_conv_string_to_date_p8 +EXEC babel_4896_test_conv_string_to_date_p8 GO -SELECT test_conv_string_to_date_f8() +SELECT babel_4896_test_conv_string_to_date_f8() GO -SELECT * FROM test_conv_string_to_date_v9 +SELECT * FROM babel_4896_test_conv_string_to_date_v9 GO -EXEC test_conv_string_to_date_p9 +EXEC babel_4896_test_conv_string_to_date_p9 GO -SELECT test_conv_string_to_date_f9() +SELECT babel_4896_test_conv_string_to_date_f9() GO -SELECT * FROM test_conv_string_to_date_v10 +SELECT * FROM babel_4896_test_conv_string_to_date_v10 GO -SELECT * FROM test_conv_string_to_date_v11 +SELECT * FROM babel_4896_test_conv_string_to_date_v11 GO -SELECT * FROM test_conv_string_to_date_v12 +SELECT * FROM babel_4896_test_conv_string_to_date_v12 GO diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-cleanup.sql index cee7023fa0..070f4513ae 100644 --- a/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-cleanup.sql +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-cleanup.sql @@ -1,68 +1,68 @@ -DROP VIEW test_conv_string_to_date_v1 +DROP VIEW babel_4896_test_conv_string_to_date_v1 GO -DROP PROCEDURE test_conv_string_to_date_p1 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p1 GO -DROP FUNCTION test_conv_string_to_date_f1() +DROP FUNCTION babel_4896_test_conv_string_to_date_f1() GO -DROP VIEW test_conv_string_to_date_v2 +DROP VIEW babel_4896_test_conv_string_to_date_v2 GO -DROP PROCEDURE test_conv_string_to_date_p2 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p2 GO -DROP FUNCTION test_conv_string_to_date_f2() +DROP FUNCTION babel_4896_test_conv_string_to_date_f2() GO -DROP VIEW test_conv_string_to_date_v3 +DROP VIEW babel_4896_test_conv_string_to_date_v3 GO -DROP PROCEDURE test_conv_string_to_date_p3 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p3 GO -DROP FUNCTION test_conv_string_to_date_f3() +DROP FUNCTION babel_4896_test_conv_string_to_date_f3() GO -DROP VIEW test_conv_string_to_date_v4 +DROP VIEW babel_4896_test_conv_string_to_date_v4 GO -DROP PROCEDURE test_conv_string_to_date_p4 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p4 GO -DROP FUNCTION test_conv_string_to_date_f4() +DROP FUNCTION babel_4896_test_conv_string_to_date_f4() GO -DROP VIEW test_conv_string_to_date_v5 +DROP VIEW babel_4896_test_conv_string_to_date_v5 GO -DROP PROCEDURE test_conv_string_to_date_p5 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p5 GO -DROP FUNCTION test_conv_string_to_date_f5() +DROP FUNCTION babel_4896_test_conv_string_to_date_f5() GO -DROP VIEW test_conv_string_to_date_v6 +DROP VIEW babel_4896_test_conv_string_to_date_v6 GO -DROP PROCEDURE test_conv_string_to_date_p6 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p6 GO -DROP FUNCTION test_conv_string_to_date_f6() +DROP FUNCTION babel_4896_test_conv_string_to_date_f6() GO -DROP VIEW test_conv_string_to_date_v7 +DROP VIEW babel_4896_test_conv_string_to_date_v7 GO -DROP PROCEDURE test_conv_string_to_date_p7 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p7 GO -DROP FUNCTION test_conv_string_to_date_f7() +DROP FUNCTION babel_4896_test_conv_string_to_date_f7() GO -DROP VIEW test_conv_string_to_date_v8 +DROP VIEW babel_4896_test_conv_string_to_date_v8 GO -DROP PROCEDURE test_conv_string_to_date_p8 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p8 GO -DROP FUNCTION test_conv_string_to_date_f8() +DROP FUNCTION babel_4896_test_conv_string_to_date_f8() GO -DROP VIEW test_conv_string_to_date_v9 +DROP VIEW babel_4896_test_conv_string_to_date_v9 GO -DROP PROCEDURE test_conv_string_to_date_p9 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p9 GO -DROP FUNCTION test_conv_string_to_date_f9() +DROP FUNCTION babel_4896_test_conv_string_to_date_f9() GO -DROP VIEW test_conv_string_to_date_v10 +DROP VIEW babel_4896_test_conv_string_to_date_v10 GO -DROP VIEW test_conv_string_to_date_v12 +DROP VIEW babel_4896_test_conv_string_to_date_v12 GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-prepare.sql index bec661977b..fc0068661c 100644 --- a/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-prepare.sql +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-prepare.sql @@ -1,104 +1,104 @@ -CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f1() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f1() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '2017-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f2() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f2() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '9999-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +CREATE VIEW babel_4896_test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE FUNCTION test_conv_string_to_date_f3() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f3() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '13:01:59')); END GO -CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE VIEW babel_4896_test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE FUNCTION test_conv_string_to_date_f4() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f4() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); END GO -CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f5() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f5() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f6() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f6() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f7() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f7() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE FUNCTION test_conv_string_to_date_f8() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f8() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); END GO -CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f9() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f9() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +CREATE VIEW babel_4896_test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); GO -CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-verify.sql index dfd5cd1a7f..d246accc89 100644 --- a/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-verify.sql +++ b/test/JDBC/input/functions/test_conv_string_to_date-before-17_3-vu-verify.sql @@ -1408,71 +1408,71 @@ SELECT CONVERT(DATE, @TM_ICLO) GO -- Dependent objects -SELECT * FROM test_conv_string_to_date_v1 +SELECT * FROM babel_4896_test_conv_string_to_date_v1 GO -EXEC test_conv_string_to_date_p1 +EXEC babel_4896_test_conv_string_to_date_p1 GO -SELECT test_conv_string_to_date_f1() +SELECT babel_4896_test_conv_string_to_date_f1() GO -SELECT * FROM test_conv_string_to_date_v2 +SELECT * FROM babel_4896_test_conv_string_to_date_v2 GO -EXEC test_conv_string_to_date_p2 +EXEC babel_4896_test_conv_string_to_date_p2 GO -SELECT test_conv_string_to_date_f2() +SELECT babel_4896_test_conv_string_to_date_f2() GO -SELECT * FROM test_conv_string_to_date_v3 +SELECT * FROM babel_4896_test_conv_string_to_date_v3 GO -EXEC test_conv_string_to_date_p3 +EXEC babel_4896_test_conv_string_to_date_p3 GO -SELECT test_conv_string_to_date_f3() +SELECT babel_4896_test_conv_string_to_date_f3() GO -SELECT * FROM test_conv_string_to_date_v4 +SELECT * FROM babel_4896_test_conv_string_to_date_v4 GO -EXEC test_conv_string_to_date_p4 +EXEC babel_4896_test_conv_string_to_date_p4 GO -SELECT test_conv_string_to_date_f4() +SELECT babel_4896_test_conv_string_to_date_f4() GO -SELECT * FROM test_conv_string_to_date_v5 +SELECT * FROM babel_4896_test_conv_string_to_date_v5 GO -EXEC test_conv_string_to_date_p5 +EXEC babel_4896_test_conv_string_to_date_p5 GO -SELECT test_conv_string_to_date_f5() +SELECT babel_4896_test_conv_string_to_date_f5() GO -SELECT * FROM test_conv_string_to_date_v6 +SELECT * FROM babel_4896_test_conv_string_to_date_v6 GO -EXEC test_conv_string_to_date_p6 +EXEC babel_4896_test_conv_string_to_date_p6 GO -SELECT test_conv_string_to_date_f6() +SELECT babel_4896_test_conv_string_to_date_f6() GO -SELECT * FROM test_conv_string_to_date_v7 +SELECT * FROM babel_4896_test_conv_string_to_date_v7 GO -EXEC test_conv_string_to_date_p7 +EXEC babel_4896_test_conv_string_to_date_p7 GO -SELECT test_conv_string_to_date_f7() +SELECT babel_4896_test_conv_string_to_date_f7() GO -SELECT * FROM test_conv_string_to_date_v8 +SELECT * FROM babel_4896_test_conv_string_to_date_v8 GO -EXEC test_conv_string_to_date_p8 +EXEC babel_4896_test_conv_string_to_date_p8 GO -SELECT test_conv_string_to_date_f8() +SELECT babel_4896_test_conv_string_to_date_f8() GO -SELECT * FROM test_conv_string_to_date_v9 +SELECT * FROM babel_4896_test_conv_string_to_date_v9 GO -EXEC test_conv_string_to_date_p9 +EXEC babel_4896_test_conv_string_to_date_p9 GO -SELECT test_conv_string_to_date_f9() +SELECT babel_4896_test_conv_string_to_date_f9() GO -SELECT * FROM test_conv_string_to_date_v10 +SELECT * FROM babel_4896_test_conv_string_to_date_v10 GO -SELECT * FROM test_conv_string_to_date_v12 +SELECT * FROM babel_4896_test_conv_string_to_date_v12 GO diff --git a/test/JDBC/input/functions/test_conv_string_to_date-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_string_to_date-vu-cleanup.sql index c6ca5aedf4..187be36612 100644 --- a/test/JDBC/input/functions/test_conv_string_to_date-vu-cleanup.sql +++ b/test/JDBC/input/functions/test_conv_string_to_date-vu-cleanup.sql @@ -1,71 +1,71 @@ -DROP VIEW test_conv_string_to_date_v1 +DROP VIEW babel_4896_test_conv_string_to_date_v1 GO -DROP PROCEDURE test_conv_string_to_date_p1 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p1 GO -DROP FUNCTION test_conv_string_to_date_f1() +DROP FUNCTION babel_4896_test_conv_string_to_date_f1() GO -DROP VIEW test_conv_string_to_date_v2 +DROP VIEW babel_4896_test_conv_string_to_date_v2 GO -DROP PROCEDURE test_conv_string_to_date_p2 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p2 GO -DROP FUNCTION test_conv_string_to_date_f2() +DROP FUNCTION babel_4896_test_conv_string_to_date_f2() GO -DROP VIEW test_conv_string_to_date_v3 +DROP VIEW babel_4896_test_conv_string_to_date_v3 GO -DROP PROCEDURE test_conv_string_to_date_p3 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p3 GO -DROP FUNCTION test_conv_string_to_date_f3() +DROP FUNCTION babel_4896_test_conv_string_to_date_f3() GO -DROP VIEW test_conv_string_to_date_v4 +DROP VIEW babel_4896_test_conv_string_to_date_v4 GO -DROP PROCEDURE test_conv_string_to_date_p4 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p4 GO -DROP FUNCTION test_conv_string_to_date_f4() +DROP FUNCTION babel_4896_test_conv_string_to_date_f4() GO -DROP VIEW test_conv_string_to_date_v5 +DROP VIEW babel_4896_test_conv_string_to_date_v5 GO -DROP PROCEDURE test_conv_string_to_date_p5 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p5 GO -DROP FUNCTION test_conv_string_to_date_f5() +DROP FUNCTION babel_4896_test_conv_string_to_date_f5() GO -DROP VIEW test_conv_string_to_date_v6 +DROP VIEW babel_4896_test_conv_string_to_date_v6 GO -DROP PROCEDURE test_conv_string_to_date_p6 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p6 GO -DROP FUNCTION test_conv_string_to_date_f6() +DROP FUNCTION babel_4896_test_conv_string_to_date_f6() GO -DROP VIEW test_conv_string_to_date_v7 +DROP VIEW babel_4896_test_conv_string_to_date_v7 GO -DROP PROCEDURE test_conv_string_to_date_p7 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p7 GO -DROP FUNCTION test_conv_string_to_date_f7() +DROP FUNCTION babel_4896_test_conv_string_to_date_f7() GO -DROP VIEW test_conv_string_to_date_v8 +DROP VIEW babel_4896_test_conv_string_to_date_v8 GO -DROP PROCEDURE test_conv_string_to_date_p8 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p8 GO -DROP FUNCTION test_conv_string_to_date_f8() +DROP FUNCTION babel_4896_test_conv_string_to_date_f8() GO -DROP VIEW test_conv_string_to_date_v9 +DROP VIEW babel_4896_test_conv_string_to_date_v9 GO -DROP PROCEDURE test_conv_string_to_date_p9 +DROP PROCEDURE babel_4896_test_conv_string_to_date_p9 GO -DROP FUNCTION test_conv_string_to_date_f9() +DROP FUNCTION babel_4896_test_conv_string_to_date_f9() GO -DROP VIEW test_conv_string_to_date_v10 +DROP VIEW babel_4896_test_conv_string_to_date_v10 GO -DROP VIEW test_conv_string_to_date_v11 +DROP VIEW babel_4896_test_conv_string_to_date_v11 GO -DROP VIEW test_conv_string_to_date_v12 +DROP VIEW babel_4896_test_conv_string_to_date_v12 GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-vu-prepare.sql b/test/JDBC/input/functions/test_conv_string_to_date-vu-prepare.sql index 7791067ede..3dae481af1 100644 --- a/test/JDBC/input/functions/test_conv_string_to_date-vu-prepare.sql +++ b/test/JDBC/input/functions/test_conv_string_to_date-vu-prepare.sql @@ -1,107 +1,107 @@ -CREATE VIEW test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p1 as (SELECT CONVERT(date, '2017-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f1() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f1() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '2017-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE VIEW babel_4896_test_conv_string_to_date_v2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE PROCEDURE test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p2 as (SELECT CONVERT(date, '9999-08-25')); GO -CREATE FUNCTION test_conv_string_to_date_f2() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f2() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '9999-08-25')); END GO -CREATE VIEW test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); +CREATE VIEW babel_4896_test_conv_string_to_date_v3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE PROCEDURE test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p3 as (SELECT CONVERT(date, '13:01:59')); GO -CREATE FUNCTION test_conv_string_to_date_f3() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f3() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, '13:01:59')); END GO -CREATE VIEW test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE VIEW babel_4896_test_conv_string_to_date_v4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE PROCEDURE test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p4 as (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); GO -CREATE FUNCTION test_conv_string_to_date_f4() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f4() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as TEXT))); END GO -CREATE VIEW test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p5 as (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f5() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f5() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as CHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p6 as (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f6() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f6() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p7 as (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f7() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f7() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as NVARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE PROCEDURE test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p8 as (SELECT CONVERT(date, cast('2002' as INTEGER))); GO -CREATE FUNCTION test_conv_string_to_date_f8() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f8() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2002' as INTEGER))); END GO -CREATE VIEW test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE VIEW babel_4896_test_conv_string_to_date_v9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE PROCEDURE test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); +CREATE PROCEDURE babel_4896_test_conv_string_to_date_p9 as (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); GO -CREATE FUNCTION test_conv_string_to_date_f9() +CREATE FUNCTION babel_4896_test_conv_string_to_date_f9() RETURNS date AS BEGIN RETURN (SELECT CONVERT(date, cast('2017-08-25' as VARCHAR(10)))); END GO -CREATE VIEW test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); +CREATE VIEW babel_4896_test_conv_string_to_date_v10 as (SELECT CONVERT(date, '02-03-2003 11:11:11 +11:11', 130)); GO -CREATE VIEW test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); +CREATE VIEW babel_4896_test_conv_string_to_date_v11 as (SELECT CONVERT(date, cast('02-03-2003 11:11:11 +11:11' as sys.varchar(100)), 130)); GO -CREATE VIEW test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); +CREATE VIEW babel_4896_test_conv_string_to_date_v12 as (SELECT CONVERT(date, CAST('20' as INTEGER))); GO \ No newline at end of file diff --git a/test/JDBC/input/functions/test_conv_string_to_date-vu-verify.sql b/test/JDBC/input/functions/test_conv_string_to_date-vu-verify.sql index 7e2bc354aa..7ed3f06f8c 100644 --- a/test/JDBC/input/functions/test_conv_string_to_date-vu-verify.sql +++ b/test/JDBC/input/functions/test_conv_string_to_date-vu-verify.sql @@ -1409,74 +1409,74 @@ SELECT CONVERT(DATE, @TM_ICLO) GO -- Dependent objects -SELECT * FROM test_conv_string_to_date_v1 +SELECT * FROM babel_4896_test_conv_string_to_date_v1 GO -EXEC test_conv_string_to_date_p1 +EXEC babel_4896_test_conv_string_to_date_p1 GO -SELECT test_conv_string_to_date_f1() +SELECT babel_4896_test_conv_string_to_date_f1() GO -SELECT * FROM test_conv_string_to_date_v2 +SELECT * FROM babel_4896_test_conv_string_to_date_v2 GO -EXEC test_conv_string_to_date_p2 +EXEC babel_4896_test_conv_string_to_date_p2 GO -SELECT test_conv_string_to_date_f2() +SELECT babel_4896_test_conv_string_to_date_f2() GO -SELECT * FROM test_conv_string_to_date_v3 +SELECT * FROM babel_4896_test_conv_string_to_date_v3 GO -EXEC test_conv_string_to_date_p3 +EXEC babel_4896_test_conv_string_to_date_p3 GO -SELECT test_conv_string_to_date_f3() +SELECT babel_4896_test_conv_string_to_date_f3() GO -SELECT * FROM test_conv_string_to_date_v4 +SELECT * FROM babel_4896_test_conv_string_to_date_v4 GO -EXEC test_conv_string_to_date_p4 +EXEC babel_4896_test_conv_string_to_date_p4 GO -SELECT test_conv_string_to_date_f4() +SELECT babel_4896_test_conv_string_to_date_f4() GO -SELECT * FROM test_conv_string_to_date_v5 +SELECT * FROM babel_4896_test_conv_string_to_date_v5 GO -EXEC test_conv_string_to_date_p5 +EXEC babel_4896_test_conv_string_to_date_p5 GO -SELECT test_conv_string_to_date_f5() +SELECT babel_4896_test_conv_string_to_date_f5() GO -SELECT * FROM test_conv_string_to_date_v6 +SELECT * FROM babel_4896_test_conv_string_to_date_v6 GO -EXEC test_conv_string_to_date_p6 +EXEC babel_4896_test_conv_string_to_date_p6 GO -SELECT test_conv_string_to_date_f6() +SELECT babel_4896_test_conv_string_to_date_f6() GO -SELECT * FROM test_conv_string_to_date_v7 +SELECT * FROM babel_4896_test_conv_string_to_date_v7 GO -EXEC test_conv_string_to_date_p7 +EXEC babel_4896_test_conv_string_to_date_p7 GO -SELECT test_conv_string_to_date_f7() +SELECT babel_4896_test_conv_string_to_date_f7() GO -SELECT * FROM test_conv_string_to_date_v8 +SELECT * FROM babel_4896_test_conv_string_to_date_v8 GO -EXEC test_conv_string_to_date_p8 +EXEC babel_4896_test_conv_string_to_date_p8 GO -SELECT test_conv_string_to_date_f8() +SELECT babel_4896_test_conv_string_to_date_f8() GO -SELECT * FROM test_conv_string_to_date_v9 +SELECT * FROM babel_4896_test_conv_string_to_date_v9 GO -EXEC test_conv_string_to_date_p9 +EXEC babel_4896_test_conv_string_to_date_p9 GO -SELECT test_conv_string_to_date_f9() +SELECT babel_4896_test_conv_string_to_date_f9() GO -SELECT * FROM test_conv_string_to_date_v10 +SELECT * FROM babel_4896_test_conv_string_to_date_v10 GO -SELECT * FROM test_conv_string_to_date_v11 +SELECT * FROM babel_4896_test_conv_string_to_date_v11 GO -SELECT * FROM test_conv_string_to_date_v12 +SELECT * FROM babel_4896_test_conv_string_to_date_v12 GO