Forum Moderators: open

Message Too Old, No Replies

IsNull and Explanation

         

aax123

9:52 pm on May 22, 2006 (gmt 0)

10+ Year Member



Can someone please explain why the isNull(BLAH BLAH BLAH BLAH, in_date-1) would be used in the example below? For some instances I get this error message. "Arithmetic overflow error converting expression to data type smalldatetime." and for others it's fine. But if I take it out completely everything works. I really don't know why it should be there and how it is used.

and in_date > isNull((
select max(out_date)
from aax_vehicle (nolock) where vin = 'XXXXXXXXX' and status_id in (17,62)
and company_id in (select distinct gcr.company_id
from aax_group_company_rel gcr (nolock)
inner join aax_company c (nolock) on gcr.company_id = c.company_id and c.type_id = 15
where group_id = (select gcr.group_id
from aax_group_company_rel gcr (nolock)
inner join aax_group g (nolock) on gcr.group_id = g.group_id and g.type_id = 16
where gcr.company_id = 457)))
, in_date-1)

siMKin

7:23 am on May 23, 2006 (gmt 0)

10+ Year Member



first of all, a little bit of indentation, to make it a bit more readable:

AND in_date > isNull( 
(
SELECT max(out_date)
FROM aax_vehicle (nolock)
WHERE vin = 'XXXXXXXXX' AND status_id in (17,62)
AND company_id IN (
SELECT distinct gcr.company_id
FROM aax_group_company_rel gcr (nolock)
INNER JOIN aax_company c (nolock) ON gcr.company_id = c.company_id and c.type_id = 15
WHERE group_id = (
SELECT gcr.group_id
FROM aax_group_company_rel gcr (nolock)
INNER JOIN aax_group g (nolock) ON gcr.group_id = g.group_id and g.type_id = 16
WHERE gcr.company_id = 457
)
)
),
in_date-1
)

Can someone please explain why the isNull(BLAH BLAH BLAH BLAH, in_date-1) would be used in the example below?

isNull([something], [something else])
is the same as:
IF([something] IS NULL, [something else], [something])

In other words, if [something] appears to be NULL, use the value of the [something else] and otherwise just use [something]

I don't know though, why it's written down like it is, because it doesn't make much sense.
If the product of all those subqueries is NULL, what's left is:

in_date > in_date-1

which will always be true.

Maybe it has some logic in the bigger picture, but there's really no telling with the information you just gave. It might as well be a typo too