a表,有个date字段,值都是200605之类的,
id    taxid    date   ....
1      001      200609
2      001      200608
3      002      200609
4      003      200607b表,有两个字段startdate和enddate,里面是2006-10-11之类的时间
taxid      startdate        enddate
001         2006-9-6        2007-8-9
002         2006-5-9        2006-12-5
003         2006-1-4        2007-9-6
列出a表中date在b表中startdate和enddate之间的值
根据taxid对应
有个外在条件是b表的taxid=001这个是单一,每次都是输入一个值taxid,根据这个值查询该如何写啊,各位高手帮帮忙啊!

解决方案 »

  1.   

    select a.*
    from tableA a 
    join tableB b on a.taxid = b.taxid 
        and a.date between convert(varchar(6), b.startdate 112) and convert(varchar(6), b.enddate 112)
    where b.taxid = '001'
      

  2.   

    select
        a.* 
    from 
        a表 a,
        b表 b 
    where 
        a.taxid=b.taxid
        and
        a.taxid=@inputid
      

  3.   

    declare @inputid varchar(4)
    set @inputid='001'select
        a.* 
    from 
        a表 a
    inner join
        b表 b 
    on 
        a.taxid=b.taxid
    where
        a.taxid=@inputid
      

  4.   


    declare @vtaxid varchar(10)set @vtaxid='001'
    select * from A
    where exists(
    select top 1 0 from b 
    where a.taxid=b.taxid 
    and (a.date between b.startdate and b.enddate)
    and b.taxid=@vtaxid
    )
      

  5.   

    需要查询结果为什么样的?先给个转换给你('2006-09-02'-->'200609'):
    declare @str varchar(10)
    set @str='2006-09-02'
    select convert(varchar(6),convert(datetime,@str),112)--结果
    200609
      

  6.   

    a的date是月
    b也要精确到月,具体号就不用了!
      

  7.   

    select a.*,b.*
    from a,b
    where a.taxid = b.taxid and a.date between convert(varchar(6), b.startdate, 112) and convert(varchar(6), b.enddate, 112) and b.taxid='001'