这个过程哪错了?
---------------------------------------------------------
create proc sp_max
@return int output
as
declare
@maxcount int,
@slotno varchar(10),
@rowcount varchar(10)
begin
set @rowcount=(select @SlotNo = SlotNo from slot_0
union
select @SlotNo = SlotNo from slot_1
union
select @SlotNo = SlotNo from slot_2
union
select @SlotNo = SlotNo from slot_3
union
select @SlotNo = SlotNo from slot_4
union
select @SlotNo = SlotNo from slot_5
union
select @SlotNo = SlotNo from slot_6
union
select @SlotNo = SlotNo from slot_7
union
select @SlotNo = SlotNo from slot_8
union
select @SlotNo = SlotNo from slot_9)
select @maxcount = max(@rowcount)+1 if @@error <> 0
begin
set @return = -1
return
end
set @return = 0
return
end
go
-------------------------------------------
---------------------------------------------------------
create proc sp_max
@return int output
as
declare
@maxcount int,
@slotno varchar(10),
@rowcount varchar(10)
begin
set @rowcount=(select @SlotNo = SlotNo from slot_0
union
select @SlotNo = SlotNo from slot_1
union
select @SlotNo = SlotNo from slot_2
union
select @SlotNo = SlotNo from slot_3
union
select @SlotNo = SlotNo from slot_4
union
select @SlotNo = SlotNo from slot_5
union
select @SlotNo = SlotNo from slot_6
union
select @SlotNo = SlotNo from slot_7
union
select @SlotNo = SlotNo from slot_8
union
select @SlotNo = SlotNo from slot_9)
select @maxcount = max(@rowcount)+1 if @@error <> 0
begin
set @return = -1
return
end
set @return = 0
return
end
go
-------------------------------------------
create proc sp_max
@return int output
as
declare
@maxcount int,
@slotno varchar(10),
@rowcount varchar(10)
begin
select @SlotNo = SlotNo from slot_0
union
select @SlotNo = SlotNo from slot_1
union
select @SlotNo = SlotNo from slot_2
union
select @SlotNo = SlotNo from slot_3
union
select @SlotNo = SlotNo from slot_4
union
select @SlotNo = SlotNo from slot_5
union
select @SlotNo = SlotNo from slot_6
union
select @SlotNo = SlotNo from slot_7
union
select @SlotNo = SlotNo from slot_8
union
select @SlotNo = SlotNo from slot_9
select @maxcount = @@rowcount +1 if @@error <> 0
begin
set @return = -1
return
end
set @return = 0
return
end
go
--------------------------------
服务器: 消息 8122,级别 16,状态 1,过程 sp_max,行 11
只有 UNION 语句中的第一个查询才能使用带赋值的 SELECT。
select @SlotNo = count(1) from slot_0
select @SlotNo = @SlotNo + count(1) from slot_1
select @SlotNo = @SlotNo + count(1) from slot_2
select @SlotNo = @SlotNo + count(1) from slot_3
.....
select @maxcount = @SlotNo + 1
select @SlotNo = count(1) from slot_0
select @SlotNo = case when @SlotNo > count(1) then @SlotNo else count(1) end from slot_1
select @SlotNo = case when @SlotNo > count(1) then @SlotNo else count(1) end from slot_2
select @SlotNo = case when @SlotNo > count(1) then @SlotNo else count(1) end from slot_3
select @SlotNo = case when @SlotNo > count(1) then @SlotNo else count(1) end from slot_4
select @SlotNo = case when @SlotNo > count(1) then @SlotNo else count(1) end from slot_5
...
select @maxcount = @SlotNo + 1