469,622 Members | 1,445 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,622 developers. It's quick & easy.

stored procedure question

Hi

I am using the following code in a procedure

update bia
set bia.behovantal = convert(int, bia.behovantal) + (convert(int,
al.multipel) - (convert(int, bia.behovantal) % convert(int,
al.multipel)))
from al
where bia.artnr = al.artnr and
al.arthuvudavt = 1

I need a way to set al.multipel to 1 if it does not exist, to avoid a
divide by 0 error in the modulo function.

I am unsure how to do this since I cannot do this in a loop and assign
al.multipel to a variable and do if @multipel IS NULL then begin
@multipel = 1 end

I need another way of doing it iof possible

Any ideas would be helpful

Matt
Jul 20 '05 #1
1 1920
update bia
set bia.behovantal = convert(int, bia.behovantal) +
(convert(int, COALESCE(al.multipel, 1)) -
(convert(int, bia.behovantal) %
convert(int, COALESCE(al.multipel, 1))))
from al
where bia.artnr = al.artnr
and al.arthuvudavt = 1

Without any schema definitions to test against I can't say that this is
the anbswer but it should get you started.

See ISNULL or COALESCE in BOL for additional details.

HTH

=======================================
Everyone here speaks SQL; some are more fluent, others less. When
describing your SQL object (table, etc.), do so in the language that we
all understand - SQL, not English. It makes it easier to understand
your issue and makes it more likely that you will get the assistance
that you are asking for.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ryan.Chowdhury | last post: by
8 posts views Thread by Thomasb | last post: by
2 posts views Thread by Kent Lewandowski | last post: by
5 posts views Thread by Rhino | last post: by
5 posts views Thread by Andy G | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.