The conversion of a varchar data type to a datetime data type resulted in an out-of-range value when running T-SQL query
-1
votes
1
answer
10747
views
Please note I am not a coder by any means, I am simply trying to assist with a migration from SQL Server 2008 R2 and 2008 to SQL Server 2022 and 2019.
When I execute the following T-SQL query:
select convert(datetime,'08/15/2022',103)
I get an error:
> The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
When I change it to:
select convert(datetime,'08/15/2022',101)
...it works.
I know UK English does not use mm/dd/yyyy, it was a test I was doing to see which default language SQL Server was using, so I could identify an issue in a website. I am looking therefore to set the default language in SQL to UK English instead of US English.
I did use backup/restore migration. It seems SQL Server 2019 interprets SQL queries slightly differently from SQL Server 2008. I have no access to the coded webpages, so I cannot make any changes to the ASP coding.
Is there *any* way I can run some T-SQL query to change the way SQL Server 2019 sees the date and force it to use UK English?
The server region settings are set correctly, to English South Africa (the same as UK English), so I am not sure where else I can make any changes so that we get the correct date and time format.
If I change the default language of the user in question, will this achieve my goal and do I need to restart SQL server in order to implement the change? The user I am referring to is the user set in SQL to connect to the database to run queries, set in the ODBC Driver settings.
This is in relation to a website we are running, which I cannot change coding for as I know nothing about ASP.
This is the code causing the issue:
-vb
sSQL = "UPDATE VR_UPLOAD SET clnt_status = 'O', clnt_date_send = '" &
Left(strDate, 2) & "-" & Mid(strDate, 5, 2) & "-" & Right(strDate, 4) & " " &
Left(strTime, 2) & ":" & Mid(strTime, 3, 2) & ":" & Right(strTime, 2) & ".000',
CLNT_OUTFILE = '" & strFileName &
"' where clnt_validated = '' and clnt_status = 'i'"
oConn.Execute(sSQL)
Asked by Mark de Wet
(13 rep)
Aug 15, 2022, 06:45 AM
Last activity: Aug 29, 2022, 06:09 AM
Last activity: Aug 29, 2022, 06:09 AM