code_junkie

What is the best way to convert an int or null to boolean value in an SQL query?

Nov 11th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. SELECT
  2. CASE WHEN ValueColumn IS NULL THEN 'FALSE' ELSE 'TRUE' END BooleanOutput
  3. FROM
  4. table
  5.  
  6. select (column_name is not null) as result from table_name;
  7.  
  8. SELECT
  9. CASE
  10. WHEN thevalue IS NULL THEN 0
  11. ELSE 1
  12. END AS newVal
  13. FROM .... (rest of select)
  14.  
  15. create function dbo.isNotNull(@a int)
  16. returns bit
  17. as
  18. begin
  19. return isnull(@a-@a+1,0)
  20. end
  21.  
  22. select dbo.isNotNull(myIntColumn) from myTable
  23.  
  24. isnull(column - column + 1, 0) != 0
  25.  
  26. SELECT DECODE( col, NULL, 0, 1) FROM ...
Add Comment
Please, Sign In to add comment