t-sql include column if condition exists
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
精彩评论