RE: Casting in a where clause

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: The Ultimate Ozz (Ozz_at_discussions.microsoft.com)
Date: 11/19/04


Date: Fri, 19 Nov 2004 12:47:01 -0800

Looks like you never got the answer.

Here it should be:

  where ISNUMERIC(ISNULL(static_mos,'-999')) = 1 and CAST(
isnull(static_mos, '-999') AS decimal(4,2)) = uservalue

  From the pro....
  - Azhar

"scottrg" wrote:

> I'm having trouble in a SQL statement that queries from a view that has
> non-numeric, null, and zero-length data in a varchar column. I'm trying to
> cast numeric data as a real number to compare against a user-entered value.
> Part of my SQL looks like:
>
> where ISNUMERIC(static_mos) = 1 and CAST(static_mos AS decimal(4,2)) =
> uservalue
>
> For some reason the CAST always takes precedence and the query blows up on
> null values. Aren't "and" clauses supposed to be evaluated left-to-right? Is
> there any way I can get the ISNUMERIC to be evaluated first?
>