SQL 检查空日期然后大小写切换
我有一个数据结果,我想按两个不同的日期进行过滤。
除非completion_date 为空,否则以下内容正常工作。如果它为空,我想使用另一个名为created_date的字段。
string strSQL = string.Format(@"select * from my_table
where user_Id = {0}
AND [completion_date] between {1} AND {2}
order by completion_status desc, [completion_date] asc"
, userId, dateStart, dateEnd, visibilityIndicator);
也许是这样的:
string strSQL = string.Format(@"select * from my_table
where user_Id = {0}
CASE completion_date
WHEN is null THEN [completion_date] between {1} AND {2}
ELSE [created_date] between {1} AND {2}
END
AND
order by completion_status desc, [completion_date] asc"
, userId, dateStart, dateEnd, visibilityIndicator);
检查该空值然后切换到created_date的最佳方法是什么?
I have a data result that I want to filter by two different dates.
The below is working except when completion_date is null. If it is null I want to use a different field called created_date.
string strSQL = string.Format(@"select * from my_table
where user_Id = {0}
AND [completion_date] between {1} AND {2}
order by completion_status desc, [completion_date] asc"
, userId, dateStart, dateEnd, visibilityIndicator);
Perhaps something like this:
string strSQL = string.Format(@"select * from my_table
where user_Id = {0}
CASE completion_date
WHEN is null THEN [completion_date] between {1} AND {2}
ELSE [created_date] between {1} AND {2}
END
AND
order by completion_status desc, [completion_date] asc"
, userId, dateStart, dateEnd, visibilityIndicator);
What is the best way to check for that null value and then switch to created_date?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应该有效
should work
符合 ANSI SQL 的版本:
An ANSI SQL compliant version: