March 12, 2010 at 4:52 pm
I have YYYYMMDD stored in dob column in table h.
The line below gives me MMDDYYYY
substr(h.dob,5,2) || right(h.dob,2) || left(h.dob,4) as Birth_Date,
What should I change/add to insert slashes into the Birth_Date?
MM/DD/YYYY
thanks
March 12, 2010 at 5:01 pm
Please see BOL (BooksOnline, the SQL Server help system usually installed toegther with SQL Server) section "CONVERT".
March 12, 2010 at 9:24 pm
monitor89 (3/12/2010)
I have YYYYMMDD stored in dob column in table h.The line below gives me MMDDYYYY
substr(h.dob,5,2) || right(h.dob,2) || left(h.dob,4) as Birth_Date,
What should I change/add to insert slashes into the Birth_Date?
MM/DD/YYYY
thanks
Ummmm.... SQL Server is quite a bit different than Oracle... you might want to try an Oracle forum for your question. I believe that you'll need to lookup To_Date and To_Char in order to pull this off correctly using date formatting.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 15, 2010 at 3:49 pm
Got it figured out...
Original
substr(h.dob,5,2) || right(h.dob,2) || left(h.dob,4) as Birth_Date,
New
substr(h.dob,5,2) || '/' || right(h.dob,2) || '/' || left(h.dob,4) as Birth_Date,
...pretty easy actually.
March 15, 2010 at 7:55 pm
monitor89 (3/15/2010)
Got it figured out...Original
substr(h.dob,5,2) || right(h.dob,2) || left(h.dob,4) as Birth_Date,
New
substr(h.dob,5,2) || '/' || right(h.dob,2) || '/' || left(h.dob,4) as Birth_Date,
...pretty easy actually.
How about ...
TO_CHAR(TO_DATE(h.dob,'yyyymmdd'), 'mm/dd/yyyy') AS Birth_Date
😉
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply