Sql – set negative numbers in a view to zero and any positive should remain the same

casesql

select field1, field2, Field3,
case when exists
(select field1
from tbl1
where field < 0) then 0 else field1 end as Field2
from tbl1

Best Solution

Assuming its T-SQL, its similar to a question from earlier but here goes:

SELECT [your fields here] ,
CASE WHEN [COLUMN_NAME] <= 0 THEN 0 ELSE [COLUMN_NAME]  END AS [NEW_COL_NAME]
FROM [TABLE_NAME]
Related Question