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,根据这个值查询该如何写啊,各位高手帮帮忙啊!
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,根据这个值查询该如何写啊,各位高手帮帮忙啊!
解决方案 »
- 请教一个SQL语句,思路也行。。。。。。。~~~
- 子陌红尘:我很想用你的那条语句,我大概知道你那条语句的意思,但还是不会用。
- sqlserver表中如何得到查询集列的个数?以及每列的列名?类似这样的操作怎么做呀?
- sql server 2000 高手请进~!高难度问题!在线急等
- 我重装sql server后,添加同样的登录用户名再付于相同权限时会提示“user already exists"
- 【【【突然脑袋卡住了 谁帮我清醒一下?】】】
- 關於自定義函數,參數列表為什麼不能用系統函數?
- 一个关于数据导入的问题????
- 批处理 执行sql语句
- 该如何连接才能达到这个效果
- 学SQL之前需要什么基本功?求救
- 这个语句执行结果为什么不一样呢?指点一下。
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'
a.*
from
a表 a,
b表 b
where
a.taxid=b.taxid
and
a.taxid=@inputid
set @inputid='001'select
a.*
from
a表 a
inner join
b表 b
on
a.taxid=b.taxid
where
a.taxid=@inputid
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
)
declare @str varchar(10)
set @str='2006-09-02'
select convert(varchar(6),convert(datetime,@str),112)--结果
200609
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'