| Author |
Topic |
|
InNomina
Starting Member
40 Posts |
Posted - 2012-02-28 : 18:31:21
|
| I inherited a database where the date column has 2 types of date formats < no idea why>they are:a. 01JAN92b. 95I need to reformat all 24000 records to a standard of mm/dd/yyyyHelp!-------------------------"If you never fail, you're not trying hard enough" |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-28 : 18:35:37
|
| for dates like 95 what value does it represent? 01-01-1995?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
InNomina
Starting Member
40 Posts |
Posted - 2012-02-28 : 18:43:13
|
quote: Originally posted by visakh16 for dates like 95 what value does it represent? 01-01-1995?
Sorry yes...that would be 01/01/1995-------------------------"If you never fail, you're not trying hard enough" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-28 : 19:07:00
|
| [code]SELECT CONVERT(datetime,case when len(field)=7 then stuff(stuff(field,3,' ',0),6,' ',0) else '01 JAN ' + field end,106) from table [/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
InNomina
Starting Member
40 Posts |
Posted - 2012-02-28 : 19:46:51
|
quote: Originally posted by visakh16
SELECT CONVERT(datetime,case when len(field)=7 then stuff(stuff(field,3,' ',0),6,' ',0) else '01 JAN ' + field end,106) from table
Thank you!When I add the appropriate info and run I get....Msg 8116, Level 16, State 1, Line 1Argument data type varchar is invalid for argument 3 of stuff function.-------------------------"If you never fail, you're not trying hard enough" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-28 : 19:51:47
|
| [code]SELECT CONVERT(datetime,case when len(field)=7 then stuff(stuff(field,3,0,' '),6,0,' ') else '01 JAN ' + field end,106) from table[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
InNomina
Starting Member
40 Posts |
Posted - 2012-02-29 : 10:57:07
|
quote: Originally posted by visakh16
SELECT CONVERT(datetime,case when len(field)=7 then stuff(stuff(field,3,0,' '),6,0,' ') else '01 JAN ' + field end,106) from table
Thank you for the help!This is what I get when I run it...Msg 241, Level 16, State 1, Line 1Conversion failed when converting date and/or time from character string.-------------------------"If you never fail, you're not trying hard enough" |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-29 : 11:31:24
|
quote: Originally posted by InNomina
quote: Originally posted by visakh16
SELECT CONVERT(datetime,case when len(field)=7 then stuff(stuff(field,3,0,' '),6,0,' ') else '01 JAN ' + field end,106) from table
Thank you for the help!This is what I get when I run it...Msg 241, Level 16, State 1, Line 1Conversion failed when converting date and/or time from character string.-------------------------"If you never fail, you're not trying hard enough"
this is whole problem of mixing different date formats inside same field------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
InNomina
Starting Member
40 Posts |
Posted - 2012-02-29 : 12:01:03
|
quote: Originally posted by X002548 it is quite possible that you have other types of Data in thereAnd What's the actual name of the Column..it's not "field" is it?SELECT DISTINCT [field]FROM tableWHERE LEN([field]) < 7OR LEN([field]) > 7What does that give you? Post some of the results please Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/
There are 2 formats, the 2 digit year- 95 and 07AUG98 in that column called OpenDate-------------------------"If you never fail, you're not trying hard enough" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-29 : 12:06:26
|
what does this return?SELECT case when len(field)=7 then stuff(stuff(field,3,0,' '),6,0,' ') else '01 JAN ' + field end from table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
InNomina
Starting Member
40 Posts |
Posted - 2012-02-29 : 14:11:32
|
quote: Originally posted by visakh16 what does this return?SELECT case when len(field)=7 then stuff(stuff(field,3,0,' '),6,0,' ') else '01 JAN ' + field end from table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
01 JA N9201 JAN 9506 JU N9206 JU N9301 JA N9502 FE B9210 OC T9301 JAN 9501 JAN 9501 JAN 9501 JAN 9502 FE B9301 JAN 9604 AP R9412 DE C9209 SE P9401 JA N9401 JAN 95-------------------------"If you never fail, you're not trying hard enough" |
 |
|
|
InNomina
Starting Member
40 Posts |
Posted - 2012-02-29 : 14:14:30
|
quote: Originally posted by InNomina [quote]Originally posted by X002548 it is quite possible that you have other types of Data in thereAnd What's the actual name of the Column..it's not "field" is it?SELECT DISTINCT [field]FROM tableWHERE LEN([field]) < 7OR LEN([field]) > 7What does that give you? Post some of the results pleaseBrett
Sorry, it Returns...OpenDate05/968-3-108993200979DEC953/11009/969520068/7/07839080JUN962007129709/9604/1120080306/118192200200111219870903/9977068420117780100009607CA08/9604822/10/201992302/10/121001/01/08FEB 979420032000857/20109605/11DEC 9907/01/11089103/96201004/9520025AUG 96000098052098NOV 998/100288000097-------------------------"If you never fail, you're not trying hard enough" |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2012-02-29 : 14:29:08
|
| I wish I asked you to order them by LEN then FieldThis is the category of stuff you have. Each one needs to be addressed by itself-- Who knows what these are579-- 00 is just bogus00-- Could these be Months?010203040506070809101112-- Could these by Year?20212377787980818283848587888990919293949596979899-- Who knows what this isCA-- Bogus200-- The year?2000200120022003200620072008200920102011-- Actual Dates in mm/yy3/118/109/9603/9603/9904/1104/9505/1105/9606/1108/9609/96-- MONTH/YYDEC95JUN96-- Who knows000096000097000098-- some other formats7/20108-3-108/7/07-- MONTH/YY with spaceAUG 96DEC 99FEB 97NOV 99-- Other date formats01/01/0802/10/1207/01/11-- le Garbage?2/10/201Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
 |
|
|
InNomina
Starting Member
40 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
InNomina
Starting Member
40 Posts |
Posted - 2012-02-29 : 14:34:04
|
quote: Originally posted by X002548 I wish I asked you to order them by LEN then FieldThis is the category of stuff you have. Each one needs to be addressed by itself-- Who knows what these are579-- 00 is just bogus00-- Could these be Months?010203040506070809101112-- Could these by Year?20212377787980818283848587888990919293949596979899-- Who knows what this isCA-- Bogus200-- The year?2000200120022003200620072008200920102011-- Actual Dates in mm/yy3/118/109/9603/9603/9904/1104/9505/1105/9606/1108/9609/96-- MONTH/YYDEC95JUN96-- Who knows000096000097000098-- some other formats7/20108-3-108/7/07-- MONTH/YY with spaceAUG 96DEC 99FEB 97NOV 99-- Other date formats01/01/0802/10/1207/01/11-- le Garbage?2/10/201Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/
I am told it's all in years, 00 would be 2000, single digits no idea......sigh....ok thank you very much for the responses.-------------------------"If you never fail, you're not trying hard enough" |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
InNomina
Starting Member
40 Posts |
Posted - 2012-02-29 : 14:46:37
|
| Thank you all for your input, I believe I have enough to start piecing together my solution.So my starter was to create a new column and have sql convert everything it could convert which left me with far less to do :-)UPDATE Folders SET OPENDATE1 = CASE WHEN ISDATE(OpenDate) > 0 THEN cast(OpenDate as datetime) ENDThanks again!-------------------------"If you never fail, you're not trying hard enough" |
 |
|
|
Next Page
|