Re: Divide By Zero Error Trapping

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: John Bell (jbellnewsposts_at_hotmail.com)
Date: 04/08/04


Date: Thu, 8 Apr 2004 09:09:50 +0100

I did not put a string in there as you may well be expecting an integer
datatype that would possibly cause AVs in the Front End.

SELECT CASE WHEN @val = 0 THEN 0 ELSE 1/@val END AS Value,
CASE WHEN @val = 0 THEN 'Divide by Zero' ELSE 'ok' END AS ZeroDivide

or possible the following if you handle nulls in the F/E

SELECT CASE WHEN @val <> 0 THEN 1/@val END AS Value

John

"Raymond D'Anjou (raydan)" <raydan@canatrade.nospamcom> wrote in message
news:uJFAvMMHEHA.2720@TK2MSFTNGP11.phx.gbl...
> Or, if a 0 result has to be differentiated from division by 0:
> > SELECT CASE WHEN @val = 0 THEN 'division by 0' ELSE CAST(1/@val AS
> VARCHAR(15)) END AS Value
>
> "John Bell" <jbellnewsposts@hotmail.com> wrote in message
> news:O3YlvBMHEHA.3576@TK2MSFTNGP10.phx.gbl...
> > You may want to try something like:
> >
> > DECLARE @val int
> > SET @val = 0
> >
> > SELECT CASE WHEN @val = 0 THEN 0 ELSE 1/@val END AS Value
> >
> > John
> >
> > "Gjones" <anonymous@discussions.microsoft.com> wrote in message
> > news:1985901c41cba$92eff270$a501280a@phx.gbl...
> > > I am using a query that contains an aggregate calculation:
> > >
> > > SUM(Sales * [%Br Incr Sales Selling] / [%ACV])
> > >
> > > Some of my fields have zeros.
> > >
> > > Thanks,
> > >
> > > Greg
> >
> >
>
>



Relevant Pages

  • Re: Am not "Toot Sweet"
    ... John H ... I was referring to a post made in response to yours. ... I know what he's expecting. ... Just as those who blame every disagreement with 'bama on ...
    (rec.boats)
  • Re: Am not "Toot Sweet"
    ... John H ... I was referring to a post made in response to yours. ... I know what he's expecting. ... Just as those who blame every disagreement with 'bama on ...
    (rec.boats)
  • Re: Am not "Toot Sweet"
    ... John H ... I was referring to a post made in response to yours. ... newsgroup', as you erroneously claimed I claimed. ... I know what he's expecting. ...
    (rec.boats)
  • Re: Am not "Toot Sweet"
    ... John H ... I was referring to a post made in response to yours. ... I know what he's expecting. ... Just as those who blame every disagreement with 'bama on ...
    (rec.boats)
  • Re: Am not "Toot Sweet"
    ... John H ... I was referring to a post made in response to yours. ... I know what he's expecting. ... Just as those who blame every disagreement with 'bama on ...
    (rec.boats)