sql server mseq:
Hi, I received a csv file which has a date column. The date format in this column is 6-Mar (6 stands for 2006 which means Mar 2006). I will import this data to an sql table and i want to date to look like 3/1/2006. Is it possible. Kindly advise.
If this is a one time issue, and depending upon the filesize, the easiest way to handle this just might be to load the file into MS Excel and use the Edit| Find/Replace capabilitiy to transform the data, save the file as a csv, and then load it into SQL Server using DTS or however you were planning to do so. For example, with the following Replace steps, set the 'By Column' search criteria, replace 6-mar with 3/1/2006. Obviously, there will be a few repeated steps to cover all dates, but it may be quicker than trying to find a way to code SQL to do it. (Yes, it is possible, but it may not be worth the time and effort.) Regards, -- Arnie Rowland, YACE* "To be successful, your heart must accompany your knowledge." *Yet Another Certification Exam [quoted text, click to view] "Tiffany" <Tiffany@discussions.microsoft.com> wrote in message news:E2B0CE2B-C4BF-40CA-A095-D685D780819C@microsoft.com... > Hi, > > I received a csv file which has a date column. The date format in this > column is 6-Mar (6 stands for 2006 which means Mar 2006). I will import > this > data to an sql table and i want to date to look like 3/1/2006. Is it > possible. Kindly advise. > > Thank you
Hi Arnie, Thanks for your suggestions, however the csv file is extremely large and is impossible to load the entire database in excel application. Hence, I have to convert it in sql. Any solution available? [quoted text, click to view] "Arnie Rowland" wrote: > If this is a one time issue, and depending upon the filesize, the easiest > way to handle this just might be to load the file into MS Excel and use the > Edit| Find/Replace capabilitiy to transform the data, save the file as a > csv, and then load it into SQL Server using DTS or however you were planning > to do so. > > For example, with the following Replace steps, set the 'By Column' search > criteria, replace 6-mar with 3/1/2006. > > Obviously, there will be a few repeated steps to cover all dates, but it may > be quicker than trying to find a way to code SQL to do it. (Yes, it is > possible, but it may not be worth the time and effort.) > > Regards, > > -- > Arnie Rowland, YACE* > "To be successful, your heart must accompany your knowledge." > > *Yet Another Certification Exam > > > "Tiffany" <Tiffany@discussions.microsoft.com> wrote in message > news:E2B0CE2B-C4BF-40CA-A095-D685D780819C@microsoft.com... > > Hi, > > > > I received a csv file which has a date column. The date format in this > > column is 6-Mar (6 stands for 2006 which means Mar 2006). I will import > > this > > data to an sql table and i want to date to look like 3/1/2006. Is it > > possible. Kindly advise. > > > > Thank you > >
You could use repeated REPLACE() function calls; REPLACE( ColumnToChange, '6-Mar', '03/01/2006' ) OR UPDATE MyTable SET ColumnToChange =3D=20 CASE ColumnToChange=20 WHEN '6-Mar' THEN '03/01/2006' WHEN '6-Apr' THEN '04/01/2006' WHEN '6-May' THEN '05/01/2006' WHEN 'etc.' THEN 'Also etc.' END That will update the table in the most efficient manner -in one command. = You can more easily see the entire set of changes in one place this way. After you update the data, are you planning to change the column to a = datetime datatype? --=20 Arnie Rowland, YACE*=20 "To be successful, your heart must accompany your knowledge." *Yet Another Certification Exam [quoted text, click to view] "Tiffany" <Tiffany@discussions.microsoft.com> wrote in message = news:24844F2F-AF0C-4FFD-B357-E2B5ED029694@microsoft.com... > Hi Arnie, >=20 > Thanks for your suggestions, however the csv file is extremely large = and is=20 > impossible to load the entire database in excel application. Hence, I = have to=20 > convert it in sql. Any solution available?=20 >=20 >=20 >=20 > "Arnie Rowland" wrote: >=20 >> If this is a one time issue, and depending upon the filesize, the = easiest=20 >> way to handle this just might be to load the file into MS Excel and = use the=20 >> Edit| Find/Replace capabilitiy to transform the data, save the file = as a=20 >> csv, and then load it into SQL Server using DTS or however you were = planning=20 >> to do so. >>=20 >> For example, with the following Replace steps, set the 'By Column' = search=20 >> criteria, replace 6-mar with 3/1/2006. >>=20 >> Obviously, there will be a few repeated steps to cover all dates, but = it may=20 >> be quicker than trying to find a way to code SQL to do it. (Yes, it = is=20 >> possible, but it may not be worth the time and effort.) >>=20 >> Regards, >>=20 >> --=20 >> Arnie Rowland, YACE* >> "To be successful, your heart must accompany your knowledge." >>=20 >> *Yet Another Certification Exam >>=20 >>=20 >> "Tiffany" <Tiffany@discussions.microsoft.com> wrote in message=20 >> news:E2B0CE2B-C4BF-40CA-A095-D685D780819C@microsoft.com... >> > Hi, >> > >> > I received a csv file which has a date column. The date format in = this >> > column is 6-Mar (6 stands for 2006 which means Mar 2006). I will = import=20 >> > this >> > data to an sql table and i want to date to look like 3/1/2006. Is = it >> > possible. Kindly advise. >> > >> > Thank you=20 >>=20 >>=20
Tiffany, There are multiple ways to do this conversion, typically using various = date functions. If the range of possibilites is somewhat limited (a few = dozen), some think that the Update/CASE statement that I sent you may be = the easiest for to understand and work with.=20 While the option below may seem a bit more refined, it requires with = certainity that certain patterns are consistant. The Update/CASE just = doesn't change the exception rows, leaving them for you to find and = replair. Another option is: UPDATE MyTable SET ColumnToUpdate =3D REPLACE(ColumnToUpdate, '6-', '2006 ') + ' 01' WHERE ColumnToUpdate LIKE '6-%' And a similar statement for 2005, 2004, etc. (Note the 'blanks' in the = line above.) --=20 Arnie Rowland, YACE*=20 "To be successful, your heart must accompany your knowledge." *Yet Another Certification Exam [quoted text, click to view] "Tiffany" <Tiffany@discussions.microsoft.com> wrote in message = news:24844F2F-AF0C-4FFD-B357-E2B5ED029694@microsoft.com... > Hi Arnie, >=20 > Thanks for your suggestions, however the csv file is extremely large = and is=20 > impossible to load the entire database in excel application. Hence, I = have to=20 > convert it in sql. Any solution available?=20 >=20 >=20 >=20 > "Arnie Rowland" wrote: >=20 >> If this is a one time issue, and depending upon the filesize, the = easiest=20 >> way to handle this just might be to load the file into MS Excel and = use the=20 >> Edit| Find/Replace capabilitiy to transform the data, save the file = as a=20 >> csv, and then load it into SQL Server using DTS or however you were = planning=20 >> to do so. >>=20 >> For example, with the following Replace steps, set the 'By Column' = search=20 >> criteria, replace 6-mar with 3/1/2006. >>=20 >> Obviously, there will be a few repeated steps to cover all dates, but = it may=20 >> be quicker than trying to find a way to code SQL to do it. (Yes, it = is=20 >> possible, but it may not be worth the time and effort.) >>=20 >> Regards, >>=20 >> --=20 >> Arnie Rowland, YACE* >> "To be successful, your heart must accompany your knowledge." >>=20 >> *Yet Another Certification Exam >>=20 >>=20 >> "Tiffany" <Tiffany@discussions.microsoft.com> wrote in message=20 >> news:E2B0CE2B-C4BF-40CA-A095-D685D780819C@microsoft.com... >> > Hi, >> > >> > I received a csv file which has a date column. The date format in = this >> > column is 6-Mar (6 stands for 2006 which means Mar 2006). I will = import=20 >> > this >> > data to an sql table and i want to date to look like 3/1/2006. Is = it >> > possible. Kindly advise. >> > >> > Thank you=20 >>=20 >>=20
[quoted text, click to view] On Tue, 20 Jun 2006 22:28:01 -0700, Tiffany wrote: >Hi, > >I received a csv file which has a date column. The date format in this >column is 6-Mar (6 stands for 2006 which means Mar 2006). I will import this >data to an sql table and i want to date to look like 3/1/2006. Is it >possible. Kindly advise. > >Thank you
Hi Tiffany, If the format is always one numeric character, one dash, three letters for the month (using stnadard English abbreviations), then try this (changing the variable to your column name, of course) DECLARE @TheDate char(5) SET @TheDate = '6-Mar' SELECT CONVERT(datetime, '1 ' + RIGHT(@TheDate, 3) + ' 200' + LEFT(@TheDate, 1)) --
Don't see what you're looking for? Try a search.
|