I've adapted the following from a question I asked on here to convert nvarchar to a date into a new table:
SELECT *
INTO T_1213_Pres_Start_Date
FROM (
SELECT *, convert(smalldatetime,Pres_Start, 103) as Pres_Start_date
FROM T_1213_OnlySSN
WHERE ISDATE(Pres_Start) = 1
) as Pres_Start_Date;
The resulting table doesn't have all the records in it that I would expect, e.g. for one record, the original Pres_Start was 26/01/2013 and that record isn't copied over. I really don't understand why as I've used "103" to signify a British date format.
Please could someone tell me where I'm going wrong?
That works perfectly, thanks. Presumably, if I put it at the beginning of the query, it will apply all the way through and I won't have to keep typing it?
At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.
Hi Sarah
Setting the DATEFORMAT this way only makes it valid for that session.
You can set it globally for the server as follows:
EXEC sp_configure 'default language', 23 ; --23 = British English
OR for the user:
In Object Explorer, right-click a server and select Properties.
Click the Misc server settings node.
In the Default language for users box, choose the language in which Microsoft SQL Server should display system messages. The default language is English. You want British English.
Louis
0
ScuzzyJoAuthor Commented:
Hi
Thanks, Pratima, but Louis beat you to it.
Louis, I think it will be OK for the session for now.
Thanks for your help.
I'll be back in about 2 mins with a different question, no doubt - the joys of learning something new!
Sarah
0
ScuzzyJoAuthor Commented:
Louis answered really quickly and his solution worked with no problems. Fantastic result!
Thanks Sarah, any time!
Louis
p.s. Forgot to say: The reason for the SQL failing in the first place was on the ISDATE function. Unlike CONVERT where you can state the format (103 for dmy for instance) of the input or output, ISDATE uses the format dictated by the 'default language' setting of the server.
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.
SET DATEFORMAT dmy;