Skip to main content
nikos101
Inspiring
November 3, 2008
Question

Is there a way to avoid the error and avoiding the need to write seperate queries

  • November 3, 2008
  • 4 replies
  • 991 views
Say I have a query that uses a param in the sql :

<cfqueryparam value="#arguments.forwardValue#" cfsqltype="cf_sql_integer">

However sometimes the value forwardValue will contain nothing ie nothing entered in the text input.

This will generate an error from the CF side. Is there a way to avoid the error and avoiding the need to write seperate queries?
This topic has been closed for replies.

4 replies

nikos101
nikos101Author
Inspiring
November 3, 2008
I just changed they type in CF to string and it wasn't fussy anymore
Inspiring
November 3, 2008
quote:

Originally posted by: nikos101
I just changed they type in CF to string and it wasn't fussy anymore

If the db field is integer, send your function a non-numeric string and see how fussy your db gets.
Inspiring
November 3, 2008
> you may have to resort to using val(arguments.forwardValue) in
> combination with the if/else logic for the null attribute

Hmm.. I guess I was wrong about that. I just tried it with MS SQL and it works just fine ... _without_ the val(..)
Participating Frequently
November 3, 2008
Try this.....

<cfqueryparam value="#arguments.forwardValue#" cfsqltype="cf_sql_integer" null=#not isNumeric(arguments.forwardValue)#>

Phil
Inspiring
November 3, 2008
Do some if/else logic to create a variable that will be either true or false, depending on whether or not arguments.forwardvalue is an integer. Then use that variable in the null attribute of cfqueryparam.
Inspiring
November 3, 2008
> Do some if/else logic to create a variable that will be either true or false, depending on whether
> or not arguments.forwardvalue is an integer. Then use that variable in the null attribute of cfqueryparam.

I think CF always validates the value, even when you are using the null attribute. So you may have to resort to using val(arguments.forwardValue) in combination with the if/else logic for the null attribute

<cfqueryparam value="#val(arguments.forwardValue)#"
cfsqltype="cf_sql_integer"
null="#not IsNumeric(arguments.forwardValue)#">