开发者

t-sql include column if condition exists

开发者 https://www.devze.com 2023-03-20 23:57 出处:网络
If I have an sql statement: select call_id, title, description, due_date from calls I want to include a column if the condition due_date < getdate() is true.

If I have an sql statement:

select call_id, title, description, due_date
from calls

I want to include a column if the condition due_date < getdate() is true.

I was thinking this column would be of type bit, and be set to 1 if condition is true and 0 if condition is false.开发者_开发知识库

Know how I can do this?


select
  call_id,
  title,
  description,
  due_date,
  case when due_date < getdate() then 1 else 0 end
from calls 


SELECT call_id, title, description, due_date, 
CASE WHEN due_date < getdate() THEN CAST(1 AS BIT) ELSE 0 END overdue
FROM calls
0

精彩评论

暂无评论...
验证码 换一张
取 消