August 10, 2007 at 3:39 pm
I have two date fields showing up as 'March 13, 2007 00:00:00', they are varchar (imported from a downloaded CSV file)
I can convert it into datetime by using the 'convert' statement, but am unable to update to insert that converted format
Here's my statement
SELECT [Email], [OptInDate], [OptedOut], [OptInDetails], [EmailType], [AOLSegment], [Address],
[City], [DBSource], convert(datetime, datein) as datein, [FirstName], [Flr22_Segment], [Industry], [LastName],
[Last_Clicked_Date], convert(datetime,Last_Open_Date) as Last_Open_Date,[Last_Sent_Date] , [LeadType], [Send_Hour_Reply],
[State], [ZIP] into masternew
FROM [SilverPop].[dbo].[NEWMaster]
August 10, 2007 at 3:51 pm
Did you read Jeff's comment to your previous topic?
http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=389085
_____________
Code for TallyGenerator
August 10, 2007 at 4:04 pm
Yes, I read the posting and was able to get the results I needed in the select,
but I can't actually modify the column during export using that select statement (syntax error converting datetime from character string) or use it in an update statement.... (same error)
How can I actually modify the existing data in the table?
I didn't see the answer to that in my prior post.
August 10, 2007 at 4:08 pm
Which table?
What's the datatype for date column in that table?
Are you doing import (as you said in first post) or export (as you said in the next one)?
_____________
Code for TallyGenerator
August 10, 2007 at 4:16 pm
As stated in my previous post below... I need to export the data from SQL Server so I can import it into a 3rd party software....
I was trying to insert into a newtable from the source table using the convert, but it erred out.
The only fields I'm still having an issue with are varchar...
But don't worry about it... Sounds like your a little miffed at this point.
I'll find my answers elsewhere!!
I currently have a date column showing up as 'Mar 20 2007 3:57pm' and need it to be
'2007/03/20' so I can import it into a third party application.
Can I make that modification directly to the column or do I need to do a convert while exporting the data?
If I can do it at the column level, would it be done via an update statement? or alter on the table?
Thanks in advance
Susan
August 10, 2007 at 4:19 pm
Is the column in the table of datetime datatype??
If so, why can't you simply open a connection on the remote APP directly to the server, or even a linked server between the servers and do a direct import?
August 10, 2007 at 4:28 pm
1st you need to convert string 'Mar 20 2007 3:57pm' to datetime.
You cannot do it in update because your column is "varchar", not "datetime" as it should be.
To convert it properly you need to use style for CONVERT function. See topic "CAST and CONVERT" in BOL.
Then you need to convert received datetime value into string using another style.
You may find the style you need in the same topic.
If your converts will still fail you need to check your data and take care about the rows where string does not represent date in proper format.
_____________
Code for TallyGenerator
August 10, 2007 at 6:18 pm
No, no... he's not miffed... it's a bit of a language barrier thing and, because of that, he comes off as being short... He's really trying to help you think outside the box...
If you need to export and the date is in the CHAR based format that you say it is, then do this as part of the export code (from previous post)...
SELECT CONVERT(CHAR(10),CAST(yourdatestringcolumn AS DATETIME),111)
FROM yourtable
...you can export the "bad" dates as nulls if you wish...
SELECT CASE
WHEN ISDATE(yourdatestringcolumn) = 1
THEN CONVERT(CHAR(10),CAST(yourdatestringcolumn AS DATETIME),111)
ELSE NULL
END AS TheDate
FROM yourtable
Of course, it would be beneficial to fix all of the bad dates and you can find them all like this...
SELECT
FROM yourtable
WHERE ISDATE(yourdatestringcolumn) = 0 --Has a bad date
--Jeff Moden
Change is inevitable... Change for the better is not.
August 11, 2007 at 8:28 pm
I have been using this site for many years and do appreciate all the help I get. Thanks for your comments and help.
Susan
August 12, 2007 at 1:35 am
Jeff, that would be
... ISDATE(...) = 0
right?
N 56°04'39.16"
E 12°55'05.25"
August 12, 2007 at 5:42 am
You can tell him up front... he's not gonna mind.
JEFF YOU SCREWED UP!
.
August 12, 2007 at 9:23 am
LMAO!!! Thanks guys... you were right and I corrected the entry.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 12, 2007 at 4:07 pm
Just to spoil everybody's celebration.
ISDATE sometimes is not good enough.
It's good if you locked inside of the world of American standards.
But imagine situation when you need to import files generated by American, German, Australian and all other sorts of origin software.
All at the same day, all into the same database.
For some of them string '13/08/2007' is absolutely legitimate date, for others - not quite.
Because of that ISDATE will return false results for some of files.
And you need to distinguish when it's wrong format causing misinterpretation in some rows of the file (in this case all other rows must be interpreted differently as well), and when it's just wrong data in the string (to be ignored according to the business rules).
Hello, globalism!
_____________
Code for TallyGenerator
August 12, 2007 at 4:11 pm
Yep... gotta agree... That's pretty much the reason for NOT storing dates as VARCHAR...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply