在sql server
,如果我有这样的表:
id | name
-------------
1 | x
2 | y
3 | z
我想创建一个存储过程以在一行中返回结果,如下所示:
x | y | z
我的代码是:
alter PROCEDURE getSupervisorEvaluationPercentages
(
@FirstSupervisorNumber nvarchar(6),
@Year int
)
as
DECLARE @Count INT
DECLARE @OptionID INT
DECLARE @getOptionID CURSOR
declare @OptionCountTb table(c int)
SET @getOptionID = CURSOR FOR
SELECT Id FROM ObjectiveOption
OPEN @getOptionID
FETCH NEXT
FROM @getOptionID INTO @OptionID
WHILE @@FETCH_STATUS = 0
BEGIN
select @Count = (select COUNT(Id) from EvaluationProcess
where FirstSupervisorNumber = @FirstSupervisorNumber and Year = @Year and FirstSupervisorEvaluation = @OptionID)
insert into @OptionCountTb values(@Count)
FETCH NEXT
FROM @getOptionID INTO @OptionID
END
CLOSE @getOptionID
DEALLOCATE @getOptionID
我想将表格的值显示@OptionCountTb
为单行