Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

input type=text + cfstoredproc + integer problems.

Status
Not open for further replies.

ingernet

Programmer
Feb 5, 2001
68
US
Perhaps one of you sagacious types can help me with this. I'm having problems with the value of '0' being passed to a database.

I have a form that tracks users' personal info - among other things, their weight and age.

I'm using CF 5 with MS SQL. The input fields for weight and age look like this:

Code:
User Age: <input type=text size=3 name=&quot;user_age&quot;> yrs.<br>
User weight: <input type=text size=3 name=&quot;user_weight&quot;> lbs.<br>

The patient_age and patient_weight variables get inserted via a stored procedure to the table MY_USERS, which looks like:
CREATE TABLE [dbo].[MY_USERS] (
[USER_ID] [int] NOT NULL ,
[USER_AGE] [int] NULL ,
[USER_WEIGHT] [int] NULL
) ON [PRIMARY]
GO

The stored procedure that is used to do the insert is:
CREATE proc spAddCase
@USER_ID int = 0,
@USER_AGE int =0,
@USER_WEIGHT int = 0
as
set nocount on
Declare @TimeCreated datetime
SELECT @TimeCreated = GetDate()
insert into MY_USERS
(
USER_ID,
USER_AGE,
USER_WEIGHT,
DTC)
values
(
@USER_ID,
@USER_AGE,
@USER_WEIGHT,
@TimeCreated)
GO

[/code]

Basically, the age and weight fields are nullable INT fields because they're obviously both supposed to be numbers, but they're both optional fields.

But when I try to pass a blank value (that is, &quot;&quot;) to MY_USERS.USER_AGE or MY_USERS.USER_WEIGHT, it says:

Code:
Invalid character value for cast specification

Here's what the stored procedure looks like:

Code:
<cfstoredproc  procedure=&quot;spAddUser&quot; datasource=&quot;#attributes.dsn#&quot; username=&quot;xxxx&quot; > 	
	<cfprocresult name = RS5>
	<cfprocparam type=&quot;In&quot; cfsqltype=&quot;CF_SQL_INTEGER&quot; maxlength=&quot;1&quot; value=#USER_ID#>
	<cfprocparam type=&quot;In&quot; cfsqltype=&quot;CF_SQL_INTEGER&quot; maxlength=&quot;1&quot; value=#USER_AGE#>
	<cfprocparam type=&quot;In&quot; cfsqltype=&quot;CF_SQL_INTEGER&quot; maxlength=&quot;1&quot; value=#USER_WEIGHT#>
</cfstoredproc>

I have tried using cfparam and cfif statements to set default values of 0, '0', (0), and &quot;0,&quot; but the INT field just isn't having any of that. I have stumped everyone in my office. Does anyone have any other ideas, short of changing the datatype in MY_USERS to VARCHAR?


 
Ingernet,

Did you try NULL? Evaluate the field for a blank, and replace it with NULL for the input parameter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top