創建爆出
訊息 264,級別 16,狀態 1,程序 proc_show,第 16 行
在 INSERT 的 SET 子句或列串列中多次指定了列名“stationid”。在同一子句中不得為一個列分配多個值。請修改該子句,以確保一個列僅更新一次。如果此陳述句在視圖中更新或插入列,列別名可能掩蓋您的代碼中的重復情況。
下面是sql server代碼
create proc proc_show
as
--創建游標得到車站編號,車站名稱,借車總次數
declare cur_show1 cursor scroll for select t.comestationid,bs.stationname,t.車站借車數
from bicyclestation bs inner join
(select t.comestationid,'車站借車數'=count(*) from Travelrecords t group by t.comestationid) t
on bs.stationid = t.comestationid
declare @stationid varchar(10),@stationname varchar(10),@sumlend int,@sumreturn int
open cur_show1
while 1 = 1
begin
fetch next from cur_show1 into @stationid,@stationname,@sumlend
if @@FETCH_STATUS <>0 break
set @sumreturn = (select count(*) from Travelrecords t where t.outstationid = @stationid)
insert into Station(stationid,stationid,sumlend,sumreturn) values(@stationid,@stationname,@sumlend,@sumreturn)
while 1 = 1
begin
declare cur_show3 cursor scroll for select DATEPART(YYYY,cometime),DATEPART(MM,cometime) from Travelrecords t where t.comestationid = @stationid order by cometime
declare cur_show2 cursor scroll for select count(*) from Travelrecords t where t.comestationid = @stationid
declare @lend int,@return int,@year varchar(10),@month varchar(10)
open cur_show3
open cur_show2
fetch next from cur_show3 into @year,@month
fetch next from cur_show2 into @lend
if @@FETCH_STATUS <>0 break
set @return = (select count(*) from Travelrecords t where t.outstationid = @stationid and cometime like ('%@year%+%@month%'))
insert into Station values(@stationid,@stationname,@lend,@return,@year + '/'+@month)
end
close cur_show3
close cur_show2
deallocate cur_show2
deallocate cur_show3
end
close cur_show1
deallocate cur_show1
go
uj5u.com熱心網友回復:
insert into Station(stationid,stationid,sumlend,sumreturn) values(@stationid,@stationname,@sumlend,@sumreturn)改為
insert into Station(stationid,stationname,sumlend,sumreturn) values(@stationid,@stationname,@sumlend,@sumreturn)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/279118.html
標籤:疑難問題
上一篇:K ettle
下一篇:SQL資料同步
