Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 29th, 2003, 07:02 PM
Igor Igor is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 1 Igor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Syntax error converting datetime from character string

Hi, I urgently need some help
I have written a .NET windows service that processes some XML's and updates some fields in an SQL Server 2000 DB. It works ok on my workstation. But at the Client's site it causes an exception with the following error: "Syntax error converting datetime from character string" I heard it might have something to do with regional settings for the workstation and SQL Server Language Settings but im not sure.
Could somebody please help with this issure?!
Thanks

Reply With Quote
  #2  
Old June 17th, 2004, 11:09 PM
mamikel mamikel is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 mamikel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Syntax error converting datetime to string

Hi Igor,

I have a similar issue. In my case I'm sending some XML as the argument to a stored procedure and using sp_xml_preparedocument and OPENXML to handle the xml in the stored proc. And as you've probably found it's only the date that causes an issue. i.e. Something to do with the format dates are written to the xml string by .NET. For instance 1/12/2004 is formatted as "2004-12-01T00:00:00.0000000+08:00".

I haven't played with it that much, but a hack is to perform an operation on the raw XML to set time formatting more to what SQL can deal with. In my case, I don't actually need the time components so I could just use

sXml = Replace(sXml, "T00:00:00.0000000+08:00", "")
or even
sXml = Replace(sXml, "T00:00:00.0000000+08:00", " 00:00:00")

Of course, this is not ideal - especially if you have a lot of data to parse. It would be better if you could tell .NET how to format the dates.

If you have found a better option, will you please let me know?

thanks

Matt

Reply With Quote
  #3  
Old June 17th, 2004, 11:13 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
try using the Cast or Convert functions.

Reply With Quote
  #4  
Old June 29th, 2004, 10:14 AM
ryandoah ryandoah is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Tallahassee, Florida
Posts: 14 ryandoah User rank is Private First Class (20 - 50 Reputation Level)ryandoah User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 20 m 50 sec
Reputation Power: 0
The solution that I found to this was that I had the @param name surrounded in apostrophies in the sp_insert statement.

Such as:

INSERT INTO Table(dataName)
VALUES ('@data')

Where it is not supposed to contain the variable delimiter ('):

INSERT INTO Table(dataName)
VALUES (@data)

Putting the ', circumvents any prior converting, as using ' tells SQL to read want is contained in the ' ' as a string.

The regional settings shouldn't really have any effect on the way your page processes, one because you should always perform error control with datatype conversions to insure that you always get the proper data format. Two, because you can not control/dictate what your user's machines are set to, as they may have local restrictions to there settings, admins,ignorance,etc. For my insert, I chose to just use the SQLServer getDate(), instead of sending extra data through the pipe.

I know is is an old thread, but hopefully it will help someone in the future.
ryandoah

Reply With Quote
  #5  
Old July 12th, 2004, 07:19 AM
ajegopinath's Avatar
ajegopinath ajegopinath is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 180 ajegopinath User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 51 m 19 sec
Reputation Power: 5
Hi,
use this query
Select convert(varchar(20),date_column,xxx) from table_name

xxx range from 101 to 114.

Regards
-Gopi

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Syntax error converting datetime from character string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT