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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NULL problem 1

Status
Not open for further replies.

mimi2

Technical User
Apr 2, 2002
407
0
0
CA
hello . is there a reason why my insert is always performed ?
my_variable is a textarea variable from a coldfusion form, sometimes it is not filled.

IF @my_variable IS not NULL
BEGIN
INSERT INTO table1(t_ID,RID,Other)
VALUES (@ID,'99',@my_variable )
END





 
not filled and null are two different things.

Coldfusion is probably passing a empty string which is not the same as a null.

You might want to change your code to.

IF @my_variable IS not NULL and @my_variable <> ''
BEGIN
INSERT INTO table1(t_ID,RID,Other)
VALUES (@ID,'99',@my_variable )
END
 

hello, @reason is a list of checkboxes from a coldfusion form (example: '1,2,5' these values go from 1 to 16)
sometimes, none of the checkboxes is checked. in this case i set reason to &quot;&quot;.
what i am trying to do with this stored procedure is to insert as many rows as i have elements in my list (3 rows for this example)
my problem is that a zero ( 0 ) is inserted in my table when none of the checkboxes is checked.i just don't see from where this zero comes from.
thanks for any adcice.

set @CommaLocation= charindex(',',@reason)


IF @Reason <> ''
BEGIN
WHILE @CommaLocation > 0
BEGIN
set @NewInsert= left(@reason,@CommaLocation - 1)
Insert into table1 (t_ID,ReasonID)
values (@D1,@NewInsert)
set @reason = substring(@reason,@CommaLocation+ 1,50)
set @CommaLocation= charindex(',',@reason)
END
END
 
In ASP, it would be possible to pass a value null as a parameter to storedprocedure.

Inside the stored procedure, it is possible to evaluate(instead of IF @Reason <> '') as below:


IF @Reason is not null

so is it possible to set null for parameter, in sp. If so, that may, take care of your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top