日期:2014-05-18 浏览次数:20494 次
--> 测试数据:# if object_id('tempdb.dbo.#') is not null drop table # create table #(Id int, state varchar(8), flag int, createtime datetime, updatetime1 datetime, deletetime datetime, updatetime3 datetime) insert into # select 1, '创建', null, '2011-07-07', null, null, null union all select 2, '删除', null, null, null, '2011-08-07', null union all select 3, '更新', 1, null, '2011-08-13', null, null union all select 4, '更新', 3, null, null, null, '2011-08-08' select Id, state, dealtme=coalesce(createtime, updatetime1, deletetime, updatetime3) from # /* Id state dealtme ----------- -------- ----------------------- 1 创建 2011-07-07 00:00:00.000 2 删除 2011-08-07 00:00:00.000 3 更新 2011-08-13 00:00:00.000 4 更新 2011-08-08 00:00:00.000 */