日期:2014-05-17 浏览次数:20486 次
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-12-27 13:56:05
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([id] varchar(3),[调整日期] datetime,[原来日期] datetime)
insert [huang]
select '001','2013-10-10','2013-10-11' union all
select '002','2013-10-11','2013-10-11' union all
select '003','2013-10-15','2013-10-15' union all
select '004','2013-10-14','2013-10-15'
--------------开始查询--------------------------
select id,CASE WHEN [调整日期]=[原来日期] THEN NULL ELSE [调整日期] END [调整日期],[原来日期]
from [huang]
----------------结果----------------------------
/*
id 调整日期 原来日期
---- ----------------------- -----------------------
001 2013-10-10 00:00:00.000 2013-10-11 00:00:00.000
002 NULL 201