I need to exclude zeros from inside the values() statement. I need the minimum that is not zero.
How to exclude zero from list of values.
This statement works.. however, I want it to provide the min of the values, but NOT if it is zero. How would I exclude zero from this list?
CASE
WHEN (Patindex('%-%', od._snvalve) > 0
OR Patindex('%,%', od._snvalve) > 0) THEN Substring(od._snvalve, Len(od._snvalve)-
(SELECT min(xxx)
FROM (
VALUES (Patindex('%-%', Reverse(od._snvalve))), (Patindex('%,%', Reverse(od._snvalve))), (Patindex('% %', Reverse(od._snvalve)))) AS value(xxx)), Len(od._snvalve))
ELSE ''
END AS Last_SN
Rod
SQL Server Other
3 additional answers
Sort by: Most helpful
-
Rod Martin 136 Reputation points
2021-09-14T11:46:03.92+00:00 Well, i'm sure its a good idea. But, I dont have any idea what DDL and DML is.
in short, in a list of Values(), how do I exclude one that is zero?
-
Viorel 122.5K Reputation points
2021-09-14T13:02:19.127+00:00 To exclude zeroes from min(xxx), I think that there are two methods:
select min(xxx) from … where xxx <> 0
or
select min(nullif(xxx, 0)) from …
After you provide the details, I hope that these approaches will work.
-
Rod Martin 136 Reputation points
2021-09-14T21:19:19.33+00:00 @Tom Phillips , @Viorel ,
Great help here. THe WHERE method did not work. I could not get the full sql statement to resolve. However, the min(nullif(xxx,0)) produced EXACTLY what was needed! Well done. Thank you!
Rod