July 3, 2012 at 2:45 am
I'm sure this is embarassingly obvious, but I have a date issue on various servers which I can't figure out.
If I run an update statement with a date value of 13/05/2012 on one server it runs fine but fails on another with the following error:
Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.
On the other server I have to use 2012-05-13.
The servers in question appear to have the same settings on the server and instance level.
Any ideas?
July 3, 2012 at 2:54 am
Looks like a dateformat issue, maybe on one server your login is set to English (MDY) format and on the other British English (DMY) format.
So on the MDY server, your trying to insert a month value of 13 which doesnt exist, where as when you do 2012-05-13 SQL knows its in YMD format.
When it comes to dates it is always recommended to format your dates in an ISO standard which will not encounter issues like this.
July 3, 2012 at 2:56 am
This was removed by the editor as SPAM
July 3, 2012 at 3:02 am
Thanks for the info.
I can now see that the date format is different. The server with the issue has a format of mdy where as the one that is ok has dmy.
How can I change this?
July 3, 2012 at 3:18 am
Specify the date format at the start of the script as follow:
SET DATEFORMAT DMY;
<Your script>
.....
...
..
<YourScript>
Regards,
Basit A. Farooq (MSC Computing, MCITP SQL Server 2005 & 2008, MCDBA SQL Server 2000)
http://basitaalishan.comJuly 3, 2012 at 3:25 am
I'm afraid I need to change it at the instance level if possible.
The SQL code is wrapped in an app I don't have access to.
July 3, 2012 at 3:29 am
Change the logins default language to British, or change the properties of the server to British (right click server --> properties --> advanced), on both be sure that this doesnt break other things which might use a dateformat of MDY first though.
And as a point to remember use ISO date formats, not locale date formats.
July 3, 2012 at 3:33 am
Anthony - The langauge for the instance is already set to British English, as it is on the server that doesn't have the issue.
That is what confused me. I can't see how they can have different date formats if they have the same language setting. Unless something was run on the existing server sometime ago.
Although I can see the name is British on the server that's ok but us_english on the other.
July 3, 2012 at 3:35 am
whats the language of the login set to?
July 3, 2012 at 3:39 am
The login is set to British English.
I just added a note to my previous post to say that if I run sp_helplanguage @language = @@LANGUAGE, the name of the language on the server with the issue is us_english whereas it's British on the other server.
I'm sure I can use sp_configure to change this?
July 3, 2012 at 3:43 am
sp_configure will only change the default language for new logins created not at the server level.
http://coolkidsdoit.wordpress.com/2009/01/28/changing-the-default-languagelocale-sql-2005/
Relates to 2005 but just substitute \90\ with \100
Disclaimer - not tried, nor do I personally want to try this, just ensure you backup your registry before doing anything like this.
July 3, 2012 at 4:16 am
Should I not be able to use:
EXEC sp_configure 'default language', 23
RECONFIGURE WITH OVERRIDE
This doesn't appear to work though.
July 3, 2012 at 4:18 am
no as I said in my last post, that will only change the default language for any new logins which are created, not the actual instance.
July 3, 2012 at 4:30 am
Ok I see what you mean now.
At the moment it looks like a re-install.
July 3, 2012 at 4:34 am
Or change the registry, but as I say, I dont personally recommend doing that, but for something so small might be better than an uninstall reinstall. Might save you a couple hours work.
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply