34,588
社区成员
发帖
与我相关
我的任务
分享
select a.*
from info a, user b
where a.userid = b.userid and convert(varchar(10),b.enddt,120) between '2008-11-01' and '2009-11-01'
--> 测试数据: @user
declare @user table (userid int,enddt datetime)
insert into @user
select 66,'2008-08-04' union all
select 22,'2008-11-01' union all
select 11,'2010-11-01'
--> 测试数据: @info
declare @info table (userid int,name varchar(2),[add ]int,code int)
insert into @info
select 44,'a1',1,2 union all
select 22,'b4',2,5 union all
select 11,'c3',6,4
select a.* from @info a,@user b where a.userid=b.userid and b.enddt between '2008-11-01' and '2009-11-01'
select t1.userid,t2.name,t2.[add],t2.code
from talbe1 t1 ,table2 t2 where t1.userid=t2.userid and t1.enddt between '2008-11-01' and '2009-11-01'
create table [user](userid int, enddt datetime)
insert into [user] values(66 , '2008-08-04')
insert into [user] values(22 , '2008-11-01')
insert into [user] values(11 , '2010-11-01')
create table info(userid int, name varchar(10) , [add] int, code int)
insert into info values(44 , 'a1' , 1 , 2 )
insert into info values(22 , 'b4' , 2 , 5 )
insert into info values(11 , 'c3' , 6 , 4 )
go
select info.* from info , [user] where info.userid = [user].userid and enddt between '2008-11-01' and '2009-11-01'
--drop table [user] , info
/*
userid name add code
----------- ---------- ----------- -----------
22 b4 2 5
(所影响的行数为 1 行)
*/
select info.* from info , user where info.userid = user.userid and enddt between '2008-11-01' and '2009-11-01'