I've got a bug in a CFStoredProc that's causing a crash whenever I try to send a decimal value to the stored procedure. The procedure simply inserts the value into a decimal(4,2) column in a SQL table. If I hard code a decimal value as the value of the cfprocparam, the procedure works. However, if the value is read in from a file, the I always get the error "Error converting data type decimal to decimal", no matter what I do to ensure the number is formatted correctly. Can anyone see what I'm doing wrong here?
My code essentially does the following:
I have tried:
Code samples of what I've tried:
<cfif structKeyExists(form, 'select_rHeight')>
<cfset headerName = form['select_rHeight']>
<cfset rHeight = csvQuery[headerName]>
<cfset rHeight = numberFormat(rHeight, "__.00")>
</cfif>
<cfstoredproc procedure="name" datasource="name">
<cfprocparam cfsqltype="CF_SQL_DECIMAL" dbvarname="@Height" scale="2" value=#rHeight# null="#NOT len(trim(rHeight))#" />
</cfstoredproc>
<cfif structKeyExists(form, 'select_rHeight')>
<cfset headerName = form['select_rHeight']>
<cfset rHeight = csvQuery[headerName]>
</cfif>
<cfstoredproc procedure="name" datasource="name">
<cfprocparam cfsqltype="CF_SQL_DECIMAL" dbvarname="@Height" scale="2" value=#decimalFormat(rHeight)# null="#NOT len(trim(rHeight))#" />
</cfstoredproc>
I've done cfdumps and outputs of the variable before it gets sent to the stored procedure, and it always appears to be formatted correctly, but I always get this error message:
[Macromedia][SQLServer JDBC Driver][SQLServer]Error converting data type decimal to decimal.
It turns out that the value being passed to the stored procedure was too large for the data type of the column into which it was being inserted. Data type was Decimal(3,2) and the value I was passing had more then three digits.
The solution was to check the size of the number being passed to the stored procedure, and give the user an error if the value is too large.
Thanks to @Tomalak for the help!