Reputation: 1221
I have written a UDF function which will return a column (0 or 1) after processing 2 columns. I need to have my select query such that it returns those records for which this value is 1. I wrote the query as below:
SELECT number, myUDF(col1, col2) as result
FROM mytable
WHERE result is not null
However it doesn't recognize the column name 'result'. Is there any special syntax needed so that it recognizes this new output column? Thanks.
Upvotes: 0
Views: 323
Reputation: 2729
CASE statement should solve the problem here:
SELECT number,
CASE when myUDF(col1, col2) = 1 then myUDF(col1, col2) END as result
FROM mytable
Upvotes: 1