34,838
社区成员




between cast(@begin_date as varchar) and cast(@end_date as varchar)
declare @begin_date int,@end_date int
set @begin_date=20090101
set @end_date=20090619
select b.date_id from table1 a join table2 b on a.id= b.id
where b.date_id between @begin_date and @end_date
declare @begin_date int,@end_date int
set @begin_date=20090101
set @end_date=20090619
select b.date_id from table1 a join table2 b on a.id= b.id
where b.date_id between @begin_date and @end_date
DECLARE @T1 TABLE(id int,name char)
insert @T1
SELECT 1,'t' UNION ALL
SELECT 2,'r' UNION ALL
SELECT 3,'c'
DECLARE @T2 TABLE(id int,date_id int)
insert @T2
SELECT 1,20090101 UNION ALL
SELECT 3,20080101 UNION ALL
SELECT 2,20091101 UNION ALL
SELECT 3,20090701 UNION ALL
SELECT 6,20090101 UNION ALL
SELECT 2,20090201
--经测试,这种表达没问题
declare @begin_date int,@end_date int
select @begin_date = 20090101,@end_date = 20090619
select b.date_id
from @T1 as a
join @T2 as b
on a.id= b.id
where (b.date_id between @begin_date and @end_date )
/*
date_id
-----------
20090101
20090201
(2 行受影响)*/
----------------------------------------------
----------------------------------------------
declare @begin_date int,@end_date int
select @begin_date = 20090101,@end_date = 20090619
select b.date_id
from @T1 as a
join @T2 as b
on a.id= b.id
where (b.date_id between @begin_date and 20090619)
/*
date_id
-----------
20090101
20090201
(2 行受影响)*/
declare @begin_date int,@end_date int
select @begin_date = 20090101
select @end_date = 20090619
select b.date_id
from table1 as a
join table2 as b
on a.id= b.id
where b.date_id between @begin_date and @end_date