Hi,
With the query above yu get 2 rows like:
2011
2012
You want your result to look like:
2011,2012
To do this you need to use a cursor. the cursor will loop through your results and perform an action on them:
declare @result varchar(max)
declare @rowdata varchar(4)
declare c1 cursor for select
case
when monthid = 4 AND yearid = '2011' and typeid ='A'
then '2011'
when monthid = 3 AND yearid = '2012' and typeid ='A'
then '2012'
end as FinYear
* from Employee
Where
( monthid = 4 AND yearid = '2011' and typeid ='A'
) or
(monthid = 3 AND yearid = '2012' and typeid ='A'
)
open c1
fetch c1 into @rowdata
while @@fetch_status=0
Begin
if @result is null
Select @Result=@rowdata
else
Select @Result=@Result + ','+@rowdata
fetch c1 into @rowdata
End
Close c1
deallocate c1
This will give you the result 2011,2012