改一条select查询语句?

来源:百度知道 编辑:UC知道 时间:2024/06/19 14:54:37
select @Date=dateadd(dd,-1,getdate())
如何将它设为从2008年6月1日至2008年6月30日?
谢啦
我用了
select @Date=dateadd(dd,30,1-June-2008)
select @Date between '2008-6-1' and '2008-6-30'
都不对呀---------

DATETIME类型的@DATE只能存放一个时间,不能存放时间段。
可以用VARCHAR类型
DECLARE @DATEVAR VARCHAR(21)
SET @DATEVAR='2008-6-1~2008-06-30'
或者:
SET @DATE=CONVERT(DATETIME,'2008-6-1',120)
SET @DATEVAR=CONVERT(VARCHAR(10),@DATE,120)+'~'+CONVERT(VARCHAR(10),DATEADD(DD,29,@DATE),120)

如果是查询内容就是
select * from 表名 where @Date between '2008-6-1' and '2008-6-30’

如果是查询数据条数就是
select count(*) from 表名 where @Date between '2008-6-1' and '2008-6-30’

是想查询2008年6月份的记录吗?
最简单的方法是:
select * from 表明 where @date like '06%2008%'

select 列名 from 表名 where 时间的列名>'2008-6-1' and 时间的列名<'2008-6-30'