按最原始的办法就是先split,然后再循环去数据库中一个一个取,这样要读三次数据库。。。而现在我想要一次性取同样数量的数据,在sql和access下分别怎么实现,求解了。。。。。
5 个解决方案
#1
只能去一个一个比对数据 我没有好的办法
帮你顶
帮你顶
#2
sql 拼接sql语句 where ... in ("+artIDs+")
access 拆分字符串变成id=1 Or id=2 Or id=3 Or ...
access 拆分字符串变成id=1 Or id=2 Or id=3 Or ...
#3
split,在循环里构造SQL语句,形式如“select * from 表 where id=1 or id=2 or id=3 ...“这样,循环结束再执行SQL语句,这样就行了。对MSS和MDB都没区别。
#4
这样行不能也,比如1下面取10条数据,2下面也取10条数据,3下面也是。。。你那样就不行。。。
#5
还是自己搞定了,用UNION来把SQL语句连起来
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=10
union
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=48
union
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=49
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=10
union
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=48
union
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=49
#1
只能去一个一个比对数据 我没有好的办法
帮你顶
帮你顶
#2
sql 拼接sql语句 where ... in ("+artIDs+")
access 拆分字符串变成id=1 Or id=2 Or id=3 Or ...
access 拆分字符串变成id=1 Or id=2 Or id=3 Or ...
#3
split,在循环里构造SQL语句,形式如“select * from 表 where id=1 or id=2 or id=3 ...“这样,循环结束再执行SQL语句,这样就行了。对MSS和MDB都没区别。
#4
这样行不能也,比如1下面取10条数据,2下面也取10条数据,3下面也是。。。你那样就不行。。。
#5
还是自己搞定了,用UNION来把SQL语句连起来
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=10
union
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=48
union
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=49
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=10
union
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=48
union
Select * from tb_News as ns
inner join tb_NewsType as nt
on ns.nsTreeID =nt.ntID
where nsState=1 and nsTreeID=49