--建立儲存資料臨時表
create table temp_dep(temp_depid varchar(50),temp_depname varchar(50),temp_name varchar(5000))
--向臨時表中插入前三列資料
insert into temp_dep(temp_depid,temp_depname) select distinct a.dept_no,b.dept_note from dbo.hes_employee a join dbo.hes_dept
b on a.dept_no = b.dept_no where status in ('zaizhi','shiyong')
--建立查詢小組編號的游標
declare somedepid_cusor cursor for
select distinct temp_depid from temp_dep
open somedepid_cusor
fetch next from somedepid_cusor into @temp_depid
while @@fetch_status=0
begin
--建立查詢員工資料游標
set @temp_somename=''
declare somename_cusor cursor for
select name from dbo.hes_employee where dept_no=@temp_depid and status in ('zaizhi','shiyong')
open somename_cusor
fetch next from somename_cusor into @temp_name
while @@fetch_status=0
begin
set @temp_somename=rtrim(@temp_somename)+rtrim(@temp_name)+','
fetch next from somename_cusor into @temp_name
endclose somename_cusor
deallocate somename_cusor
--更新資料
update dbo.temp_dep set temp_name=@temp_somename where temp_depid=@temp_depid
fetch next from somedepid_cusor into @temp_depid
endclose somedepid_cusor
deallocate somedepid_cusor
--查詢資料
select * from temp_dep
SQL Server雙層游標巢狀
在工作中解決乙個問題,想到用雙層游標巢狀來解決,我知道這個效率低,可沒想到好的解決辦法。下面貼出原始碼記錄一下吧 1.需要傳入的變數 tb bill.dt dealdate1 tb bill.dt dealdate2 tb draftbill.s draftor create proc myproc...
雙層巢狀GridView
展開前效果圖 展開後效果圖 js 此部分最重要 aspx commandargument 繫結 表示可以展開,繫結父gridview中資料的關鍵值 即id runat server onclientclick text 新增 將子gridview放在最後一列的模板中 style display no...
SQL裡的游標巢狀
是游標裡面巢狀游標嗎?資料量大的話最好不要採用這種方法!這是sql server的 declare cur 1 cursor 第一層游標宣告 for select c 1,c 2 from tablename open cur 1 fetch next from cur 1 into c 1,c 2...