Home > database >  The stored procedure to generate failure, for which bosses advice below
The stored procedure to generate failure, for which bosses advice below

Time:04-23

Create out
Message 264, level 16, state 1, line process proc_show, 16
SET in the INSERT clause or multiple columns list specifies the column name "stationid", in the same clause shall not be more than one value for a column distribution, please amend this clause, to ensure that a column updates only once, if this statement in the view to update or INSERT column, column alias may conceal the repetition in your code.

Below is the SQL server code
The create proc proc_show
As
- create a cursor to get the station number, name of the station, borrow the car total number
Declare cur_show1 cursor scroll for the select t.com estationid, bs. Stationname, number of t. borrow the car at the station
The from bicyclestation bs inner join
(select t.com estationid, 'the station to borrow the car number=the count (*) from Travelrecords t group by t.com estationid) t
On bs. Estationid stationid=t.com

Declare @ stationid varchar (10), @ stationname varchar (10), @ sumlend int, @ sumreturn int
The open cur_show1
While 1=1
The begin
The fetch next from cur_show1 into @ stationid, @ stationname, @ sumlend
If @ @ FETCH_STATUS & lt;> 0 break
The set @ sumreturn=(select count (*) from Travelrecords t where t.o utstationid=@ stationid)
Insert into Station (stationid, stationid sumlend, sumreturn) values (@ stationid @ stationname, @ sumlend, @ sumreturn)

While 1=1
The begin
Declare cur_show3 cursor scroll for the select DATEPART (YYYY, cometime), DATEPART (MM, cometime) from where t.com estationid Travelrecords t=@ stationid order by cometime
Declare cur_show2 cursor scroll for select count (*) from where t.com estationid Travelrecords t=@ stationid
Declare @ lend int, @ return int, @ year varchar (10), @ the month varchar (10)
The open cur_show3
The open cur_show2
The fetch next from cur_show3 into @ year, @ the month
The fetch next from cur_show2 into @ lend
If @ @ FETCH_STATUS & lt;> 0 break
Set @ return=(select count (*) from Travelrecords t where t.o utstationid=@ stationid and cometime like (' % @ + % @ the month year % % '))
Insert into Station values (@ stationid @ stationname, @ lend, @ return, @ year + + @ the month '/')
End
The close cur_show3
The close cur_show2
Deallocate cur_show2
Deallocate cur_show3
End
The close cur_show1
Deallocate cur_show1
Go

CodePudding user response:

Insert into Station (stationid, stationid , sumlend sumreturn) values (@ stationid @ stationname, @ sumlend, @ sumreturn)

Instead of

Insert into Station (stationid, stationname , sumlend sumreturn) values (@ stationid @ stationname, @ sumlend, @ sumreturn)
  • Related