思路:將查詢到的記錄儲存進乙個臨時表,再在臨時表中進行查詢,用完後刪除臨時表;
select * from dbo.pe_nodes
create procedure [dbo].[pr_getnodeinfobynodeid]
@nodeid int
declare
@str varchar(300),
@id varchar(300),
@m int,
@n int
select * into temp from dbo.pe_nodes where 1=0--select * into 表a from 表b:只複製表解構,不複製資料;
set @str=substring((select arrchildid from dbo.pe_nodes where nodeidentifier = (select nodeidentifier from dbo.pe_nodes where nodeid =nodeid )),0,300)
set @m=charindex(',',@str)
set @n=1
while @m>0
begin
set @id=substring(@str,@n,@m-@n)
set @n=@m+1
set @m=charindex(',',@str,@n)
insertintotemp select * from dbo.pe_nodes where nodeid = @id --將查到的表資料插入到臨時表;
endselect * from temp
drop table temp--刪除臨時表
SQL多表彙總字段合併查詢
select nsrxx.nsrsbh,nsrxx.nsrmc,case when younum 0 then younum else 0 end as younum,case when fpnum 0 then fpnum else 0 end as fpnum,round younum fpnu...
sqlserver查詢執行過的SQL記錄
說明 僅支援sql server2008及以上版本 declare starttime datetime,endtime datetime set starttime 2020 10 14 00 00 00 set endtime 2020 10 15 00 00 00 select top 100...
SQL的多表查詢的連線
left join 連線 left join 連線 也稱左連線。假設table1的主鍵id有 1 2 3,table2的外來鍵id有 3 4 5。用table1的主鍵id和table2的外來鍵id連線,就返回table1 的主鍵id為1 2 3的三行資料。而table2的外來鍵id和table1的主...