Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Fail to pass datetime value to store procedure

Guest
Apr 25, 2012 Apr 25, 2012

Hi,

I have a store procedure which will receive the date passmeter and I write it as following:

<cfif IsDefined("form.yy")>

     <cfprocparam cfsqltype="CF_SQL_TIMESTAMP" value="#CreateDate(form.yy, form.mm, form.dd)#">

<cfelse>

     <cfprocparam cfsqltype="CF_SQL_TIMESTAMP" value="null" null="yes">

</cfif>

When I did not input the day, it runs correctly.

However, it returns me the error when I input the day:

Conversion failed when converting datetime from character string.

How can I solve the problem?

1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Apr 26, 2012 Apr 26, 2012

Finally, I find that I can pass the parameter correctly. The problem is the dynamic sql in store procedure and already solved using CONVERT and CAST function. Thanks.

Translate
LEGEND ,
Apr 26, 2012 Apr 26, 2012

Your cf code looks ok.  What does the stored proc look like?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 26, 2012 Apr 26, 2012

Finally, I find that I can pass the parameter correctly. The problem is the dynamic sql in store procedure and already solved using CONVERT and CAST function. Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2012 Apr 27, 2012
LATEST

Fine. Please kindly mark the question as answered.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2012 Apr 26, 2012

Shouldn't the year be 4 digits instead of 2, that is, yyyy? In any case, you should validate the input values. (Update: The following example is a simple validation routine. You could make yours as sophisticated as you want.)

<!--- Validate form field values yy, mm and dd before passing them to stored procedure --->

<cfif IsDefined("form.yy") and isNumeric(form.yy & form.mm & form.dd) and isDate(form.mm & "/" & form.dd & "/" & form.yy)>

    <cfprocparam cfsqltype="CF_SQL_TIMESTAMP" value="#CreateDate(form.yy, form.mm, form.dd)#">

<cfelse>

    <cfprocparam cfsqltype="CF_SQL_TIMESTAMP" null="yes">

</cfif>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources