日期:2014-05-17 浏览次数:20492 次
select * from tb where convert(datetime,@str1,120) and convert(datetime,@str2,120)
USE test
GO
---->生成表tb
--
--if object_id('tb') is not null
-- drop table tb
--Go
--Create table tb([time] NVARCHAR(50))
--Insert into tb
--Select '2012-12-5 11:05:48'
--Union all Select '2012-12-5 11:08:29'
--Union all Select '2012-12-5 11:05:48'
DECLARE @t1 NVARCHAR(50) -- string
,@t2 NVARCHAR(50) -- string
SELECT @t1='2012-12-5'
,@t2='2012-12-10'
SELECT * FROM tb WHERE time BETWEEN CONVERT(DATETIME,@t1) AND CONVERT(DATETIME,@t2)
/*
time
-------------------
2012-12-5 11:05:48
2012-12-5 11:08:29
2012-12-5 11:05:48
*/
time BETWEEN CONVERT(DATETIME,@t1) AND CONVERT(DATETIME,@t2)
time >= CONVERT(DATETIME,@t1) AND time <= CONVERT(DATETIME,@t2)