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

Problem with variable

Status
Not open for further replies.

DKL01

Programmer
Sep 14, 2000
233
US
Hi Guys,

I'm wondering what could be the problem here.
Thanks


declare @ItemID int

select @ItemID = max(ItemID) from Table1

if @ItemID = null @ItemID = 0 // error here
 

You need the SET command in the last statement.

if @ItemID = null Set @ItemID = 0 Terry Broadbent
Please review faq183-874.

"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
 
Thanks for the response.
I changed my code to :

Declare @ItemID int

select @ItemID = max(ItemID) from Table1
if @ItemID = null set @ItemID = 0
select @ItemID

Actually I don't have any data in Table1. But o/p of the stored procedure is still NULL instead of 0
 

Change the Select statement to use the IsNull function. Then you won't need to test later.

Select @ItemID = IsNull(max(ItemID),0) from Table1
Print @ItemID Terry Broadbent
Please review faq183-874.

"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
 
Thanks it worked. I really appreciate your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top