Question: I am trying to filter a SELECT statament based on whether a variable is a number or not. The behavior I want is that if the parameter @productId is not a number then I want the WHERE clause to do the following:

```
WHERE (DTH.TaskId IS NULL OR PDT.PK_Product LIKE @productId)

```

If @productId is a number I want the following WHERE clause:

```
WHERE (PDT.PK_Product = @productId)

```

I thought the following would work:

```
    WHERE (ISNUMERIC(@productId) = 0 AND DTH.TaskId IS NULL
            OR PDT.PK_Product LIKE @productId)
    AND (ISNUMERIC(@productId) = 1 AND PDT.PK_Product = @productId)

```

because if ISNUMERIC(@productId) evaluates to 0 it would not use the second part of the statement and if 1 the first. 

Edit:

The problem I have is that if productId is numeric (and ISNUMERIC(@productId) evaluates to 1) I am still getting results where DTH.TaskId IS NULL.

Answer: 
```
WHERE 1 =
  CASE ISNUMERIC(@productId)
    WHEN 0 THEN
      CASE WHEN DTH.TaskId IS NULL OR PDT.PK_Product LIKE @productId THEN 1 END
    WHEN 1 THEN
      CASE WHEN DTH.TaskId IS NOT NULL AND PDT.PK_Product = @productId THEN 1 END
  END

```
you are close, this should do the trick

```
WHERE (ISNUMERIC(@productId) = 1 AND PDT.PK_Product = @productId AND DTH.TaskId IS NOT NULL) OR
      (ISNUMERIC(@productId) = 0 AND (DTH.TaskId IS NULL OR PDT.PK_Product LIKE @productId))

```