Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [RES] Case @Parameter is null Then @Parameter = 1

Author  Topic 

terbs
Starting Member

29 Posts

Posted - 2007-08-09 : 01:32:55
I have a stored procedure that increments a Job Number for a Service call which works fine, unless this jobnumber is the first. In which case it trys to increment off null.

Is there a way, Im assuimg CASE WHEN, to test whether the value is equal to null if so value = 1?


(
@CallNumber int,
@Engineer varchar(50),
@Description varchar(200),
@Date datetime,
@tmpJobNumber int
)

AS

Select @tmpJobNumber = max(JobNumber) + 1 From TABservjob

WHERE CallNumber = @CallNumber

/** Case WHEN Statement here to test if @tmpJobNumber is null??**/

INSERT INTO TABservjob

(
CallNumber,
JobNumber,
Engineer,
Description,
Date
)

VALUES

(
@CallNumber,
@tmpJobNumber,
@Engineer,
@Description,
@Date
)

RETURN


cheers

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2007-08-09 : 01:39:04
use isnull()
Select @tmpJobNumber = isnull(max(JobNumber),0) + 1 From TABservjob

WHERE CallNumber = @CallNumber

Go to Top of Page

terbs
Starting Member

29 Posts

Posted - 2007-08-09 : 02:05:21
thanks shallu1, works perfectly
Go to Top of Page
   

- Advertisement -