日期:2014-05-17 浏览次数:20726 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-01-16 22:03:27
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86)
-- Jun 17 2011 00:57:23
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([XH] varchar(4),[Dt1] datetime,[Dt2] datetime)
insert [huang]
select '0001','2013-01-11','2013-01-16' union all
select '0002','2013-01-08','2013-01-16' union all
select '0003','2013-01-11','2013-01-17' union all
select '0004','2013-01-06','2013-01-13' union all
select '0005','2013-01-19','2013-01-23' union all
select '0006','2013-01-20','2013-01-26'
--------------开始查询--------------------------
--SELECT * FROM huang
DECLARE @a DATETIME
DECLARE @b DATETIME
SET @a='2013-01-10'
SET @b='2013-01-15'
select *,'' from [huang]
WHERE DT1<=@b AND DT2>=@a
----------------结果----------------------------
/*
XH Dt1 Dt2
---- ----------------------- ----------------------- ----
0001 2013-01-11 00:00:00.000 2013-01-16 00:00:00.000
0002 2013-01-08 00:00:00.000 2013-01-16 00:00:00.000
0003 2013-01-11 00:00:00.000 2013-01-17 00:00:00.000
0004 2013-01-06 00:00:00.000 2013-01-13 00:00:00.000
(4 行受影响)
*/