我在sql server中创建的存储过程下面是结构
ALTER PROCEDURE [dbo].[list_final_player_report]
-- Add the parameters for the stored procedure here
@teamid int
AS
BEGIN
CREATE TABLE #TempTable (
playername varchar(50),
RANK_in_speedladdar INT,
rank_in_120s int,
rank_in_cone int,
rank_in_beep int,
rank_in_cooper int,
rank_in_pushups int,
rank_in_situp int,
rank_in_pullup int,
rank_in_40s int,
rank_in_pushopbattle int,
rank_in_vertical_jump int,
rank_in_shuttle int
)
DECLARE @playerid int
DECLARE @firstname nvarchar(10)
-- Define the cursor
DECLARE cursor1 cursor for
select Players.PlayerID as PlayerID , players.firstname from Players where Teamid=@teamid
-- We should open the cursor
OPEN cursor1
-- We need to Fetch the rows into @EmpId variable
FETCH cursor1 into @playerid,@firstname
--Looping
WHILE(@@fetch_status=0)
BEGIN
insert into #TempTable
values(@firstname,
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =1 and ChallengeStats.PlayerID=@playerid ),
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =2 and ChallengeStats.PlayerID=@playerid ),
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =3 and ChallengeStats.PlayerID=@playerid ) ,
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =4 and ChallengeStats.PlayerID=@playerid ) ,
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =5 and ChallengeStats.PlayerID=@playerid ) ,
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =6 and ChallengeStats.PlayerID=@playerid ) ,
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =7 and ChallengeStats.PlayerID=@playerid ) ,
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =8 and ChallengeStats.PlayerID=@playerid ) ,
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =9 and ChallengeStats.PlayerID=@playerid ) ,
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =10 and ChallengeStats.PlayerID=@playerid ) ,
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =11 and ChallengeStats.PlayerID=@playerid ) ,
(select (sum(Total))/count(PlayerID) from ChallengeStats WHERE ChallengeStats.ChallengeID =12 and ChallengeStats.PlayerID=@playerid )
)
FETCH cursor1 into @playerid,@firstname
END
close cursor1
deallocate cursor1
select * from #TempTable
END
这个sp在sqlserver中完美执行
但现在的问题是如何将这个临时表数据转换为php resultset
答案 0 :(得分:0)
而不是使用临时表,为什么不使用Table变量。 为了实现这一点,您不必更改太多代码。
DECLARE @TempTable TABLE (
playername varchar(50),
RANK_in_speedladdar INT,
rank_in_120s int,
rank_in_cone int,
rank_in_beep int,
rank_in_cooper int,
rank_in_pushups int,
rank_in_situp int,
rank_in_pullup int,
rank_in_40s int,
rank_in_pushopbattle int,
rank_in_vertical_jump int,
rank_in_shuttle int
)
临时表只能在使用它们的范围内使用,这可能会导致您的问题。试试上面的内容,你会得到不同的结果。