SELECT *
FROM OPENQUERY(ETOOL, 'SELECT * FROM LS.ecnseqno_pe')
在sql 中執行 oracle dblink 的查詢,“”中的字符關鍵字必須大寫
一个SQL的递归查询
表t1的结构是:
bom_no prd_no bom_name
001 100 aaa
001 101 bbb
001 102 kkk
002 200 ccc
002 201 ddd
003 300 eee
100 1010 fff
101 1011 ggg
300 3030 hhh
现在要查询所有父结点的数据,即已知bom_no=001就可以查出:
bom_no prd_no bom_name
001 100 aaa
100 1010 fff
101 1011 ggg问题补充:
我用的是MSSQL,没有connect by piror,能写个递归函数吗?谢谢
最佳答案
create procedure GetData(@a nvarchar(50))
as
begin
create table #Temp(
a nvarchar(50),
b nvarchar(50),
c nvarchar(50)
)
declare @tempB nvarchar(50)
insert into #Temp select a,b,c from T where a in(@a)
declare cur cursor for select b from #Temp
open cur
fetch next from cur into @tempB
while @@fetch_status = 0
begin
insert into #Temp select a,b,c from T where a in(@tempB)
fetch next from cur into @tempB
end
close cur
deallocate cur
select * from #Temp
end
=====================================================
上面的是假设表结构如下的:
a b c
=========================
1 2 aa
1 3 dfd
2 4 fdas
3 5 fds
4 7 fds
exec GetData '2'
返回
a b c
2 4 fdas
4 7 fds
"Cannot add an entity with a key that is already in use."
string leConnStr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=|DataDirectory|aa.mdb";
鏈接到excel的字串
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/183242/viewspace-680733/ ,如需转载,请注明出处,否则将追究法律责任。