Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using CONVERT() function
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
01666022
Message ID:
01666036
Vues:
35
>Hi,
>
>My stored procedure has the following code:
>
>SET @TargetDate = CONVERT(datetime, @TargetDate)
>
>Which converts a string @TargetDate to a datetime value.
>The above works when used with American customers
>
>But when using with a European customer where the string value of @TargetDate (before the conversion) is set by ToShortDateString(), the result is an error (The conversion of a varchar data type to a smalldatetime data type is out-of-range value).
>
>Is there a 3rd parameter I can use with the above CONVERT() function to get around the problem?
>
>TIA

This is the offending line:
SELECT @TargetDate = [Fld FldName].value('.','char(10)') FROM @XmlDocWo.nodes('/WORK_HIS/Fld') Fld([Fld FldName])  WHERE [Fld FldName].value('@name','varchar(20)') = 'DATE_TARG'
When I comment the above line, no error.

I wrote this line into the SQL Server SP a long time ago. The value in the XML is the string set on the ASP.NET side which converts a date to string using ToShortDateString():
TargetDate.Date.ToShortDateString()
And the above string conforms to the culture setting. Therefore, when the string is "13/02/2019 11:33:22" I get error.
So, I am assuming that the above line (offending line) converts the string into the DateTime.
Correct?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform