[dba-SQLServer] Nulls in sprocs

Steven W. Erbach serbach at new.rr.com
Wed Jan 12 07:50:35 CST 2005


Dear Group,

I've run into a problem with UPDATE stored procedures that puzzles me. I have an sproc that looks like this:

CREATE PROCEDURE spUpdPosition 
(@DeptID int,
@Position nvarchar(50),
@Analyst1 int,
@Analyst2 int,
@Description varchar(8000),
@CreatedBy nvarchar(15),
@UpdatedBy nvarchar(15),
@DateUpdated datetime,
@PositionID int)
AS UPDATE tblPositionData
SET DeptID = @DeptID, Position = @Position, Analyst1 = @Analyst1, Analyst2 = @Analyst2, Description = @Description,
CreatedBy = @CreatedBy, UpdatedBy = @UpdatedBy, DateUpdated = @DateUpdated
WHERE (PositionID = @PositionID)
GO

The PositionID is the key field, and it has the Identity property set to yes.

My problem is this: if one of the fields to be updated is NULL, it seems that the sproc won't execute. I say "seems" because I get no indication back from SQL Server as to WHY the sproc failed. If there's a value for every field then it works fine, so I concluded that the problems arise from NULL values being written to the table.

Can anyone tell me how to modify the sproc to account for possible NULL values in any of the fields? The only fields that have been defined as disallowing NULLs are the PositionID itself (automatically generated) and the DeptID, the foreign key.

Regards,
 
Steve Erbach
Scientific Marketing
Neenah, WI







More information about the dba-SQLServer mailing list