In sql server, if I have a table like this :
id | name
-------------
1 | x
2 | y
3 | z
I want to create a stored procedure to return the result in one row like this :
x | y | z
my code is :
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
I want to display the values of the table @OptionCountTb as single row