我有一个类似于下面的查询。我想要的是如果IN语句中没有特定值的记录,则选择null或空白。 有值由用户输入。检查IN语句中每个值的存在性
select system_code, max(last_update_timestamp) as [last_update_timestamp]
from table_name
where system_code in ('E1','E2','E3')
Group by system_code
E1 has 100 records
E2 has 20 records
E3 has no records
使用上面的查询我得到这个结果:
Sytem_code last_update_timestamp
E1 '2014-09-28 11:35:10.647'
E2 '2014-09-28 11:35:10.647'
预计reuslt
Sytem_code last_update_timestamp
E1 '2014-09-28 11:35:10.647'
E2 '2014-09-28 11:35:10.647'
E3 Null or Blank
任何帮助将不胜感激。
请注意,这只适用于2008年和更新。 –
@TimSchmelter是的,当然。如果他/她点击我的答案中引用的msdn页面上的*其他版本*,读者可以很容易地推断出这一点。 –
因为我已经提到过,所以不需要打开链接并点击“其他版本”。我认为这值得注意,因为OP没有提到他的版本。 (我仍然在2005年,所以这不适合我f.e.) –