查询  AAA数据库中表1 表2
userid name    add   code
enddt 日期为2008-11-01至2009-11-01表1  user 
userid   enddt
66       2008-08-04
22       2008-11-01
11       2010-11-01表2  info  
userid  name    add   code44      a1       1     2
22      b4       2     5
11      c3       6     4--------------------
结果为 
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'
      

  2.   

    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 )
    goselect 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 行)
    */
      

  3.   

    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' 
      

  4.   

    --> 测试数据: @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'
      

  5.   

     select info.* from info ,user
             where enddt between (2008-11-01) to (2008-11-01)
      

  6.   

    select a.* from inf0 a where exists(select 1 from [user] b where (enddt between '2008-11-01' and '2009-11-01') and a.userid=b.userid)
      

  7.   

    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'