Don't use stored procedure, use Multistatement table-valued functions or Inline table-valued functions(I think, you need Multistatement...). You can read about user-defined functions in BOL.
--set dateformat dmy
select distinct school,
(select lost from tableName t2 where t2.school = t1.school and t2.[date] = '20/10/2003') as [20/10/03],
(select lost from tableName t2 where t2.school = t1.school and t2.[date] = '21/10/2003') as [21/10/03],
(select lost from tableName t2 where...
Try with CURSOR:
declare @var1 as type1, @var2 as type2, ...
declare cusrorName cursor for
your_select_statement
open cursorName
fetch next from cusorName into @var1, @var2...
while @@fetch_status = 0
begin
do_what_you_want_with_your_record...
fetch next from...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.