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

Set <cfargument> Default to Null

Explorer ,
Oct 12, 2007 Oct 12, 2007
In my Inserts (MS SQL 2005) for Position which is a number field, I always default it to 0 when there is no value. See below
<cfargument name="argtposition" type="any" required="No" default="0">

Is there a way I could set the Argument to default to "Null"?
When I set the default to Null it started throwing errors. How can I default it to null instead of 0 (zero)? see below
<cfargument name="argtposition" type="any" required="No" default="Null">
TOPICS
Getting started
3.0K
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

Explorer , Oct 12, 2007 Oct 12, 2007
Thanks Dan Bracuk
That did it
Below is the correct format which inserted a null value when the parameter passed is not a valid number.

Translate
LEGEND ,
Oct 12, 2007 Oct 12, 2007
eziokolo wrote:
> In my Inserts (MS SQL 2005) for Position which is a number field, I always
> default it to 0 when there is no value. See below
> <cfargument name="argtposition" type="any" required="No" default="0">
>
> Is there a way I could set the Argument to default to "Null"?
> When I set the default to Null it started throwing errors. How can I default
> it to null instead of 0 (zero)? see below
> <cfargument name="argtposition" type="any" required="No" default="Null">
>

Not that way. That will set argtPossition to the four character string
"NULL" not a null value.

In your SQL statement, I presume and hope you are using
<cfqueryparam...> . If so it has a NULL parameter. Thus you can put
this into your SQL query.

<cfqueryparam ... null="yes">

This will override any value or other content and set the field to null
in the database. Presumable you want to set this dynamically with some
expression that evaluates to a yes|no boolean true|false value.

<cfqueryparam ... null="#argtposition EQ 0#">
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
LEGEND ,
Oct 12, 2007 Oct 12, 2007
What you have is a good start. Assuming you're using cfqueryparam in your insert query, do something like:

null="not #IsNumeric(arguments.argtposition)#"
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
Explorer ,
Oct 12, 2007 Oct 12, 2007
LATEST
Thanks Dan Bracuk
That did it
Below is the correct format which inserted a null value when the parameter passed is not a valid number.

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