Welcome to Sign in | Help

procedura + cursor = intoarce date calendaristice.....dar nu ce mi-as dori - SQL server 2000

  •  09-21-2007, 10:51 AM

    procedura + cursor = intoarce date calendaristice.....dar nu ce mi-as dori - SQL server 2000

    salut, am si eu o intrebare....unde e gresit scriptul asta

    --alter procedure spr_gprListaPerioade
    declare @datainit varchar(10),
     @datasf varchar(10)

    set @datainit = '12/03/2007'
    set @datasf = '05/08/2007'

    --as
     begin
       declare @perioade table (nrrand int, an int, descr varchar(50), begindate varchar(50), enddate varchar(50))
       declare @nrluni int
       declare @nr int, @anbisect int, @an int, @luna int
       declare @nr_cursor int, @an_cursor int, @descr_cursor varchar(50), @start_cursor varchar(50), @stop_cursor varchar(50)
      
       set @nr=0;
       set @an=cast(substring(@datasf,7,4)as int)
       set @nrluni=cast(substring(@datasf,4,2) as
    int)-cast(substring(@datainit,4,2) as int)+1
       if ( (cast(substring(@datasf,7,4) as int) % 4) = 0)
     set @anbisect=29
       else
     set @anbisect=28
       set @luna=cast(substring(@datainit,4,2) as int)-1
      
       declare tabel_perioade cursor for
        select @nr+1,@an,@luna+1, case @luna+1
                               when 1 then 'Ianuarie'
                               when 2 then 'Februarie'
                              when 3 then 'Martie'
                              when 4 then 'Aprilie'
                               when 5 then 'Mai'
                             when 6 then 'Iunie'
                             when 7 then 'Iulie'
                            when 8 then 'August'
                            when 9 then 'Septembrie'
                            when 10 then 'Octombrie'
                           when 11 then 'Noiembrie'
                         when 12 then 'Decembrie'
                         end, 
           case @luna+1
              when cast(substring(@datainit,4,2) as int) then @datainit
              else  '01/'+ cast(@luna as varchar(2))+'/'+cast(@an as varchar(4))
           end,
           case @luna+1
       when cast(substring(@datasf,4,2) as int) then @datasf
              when 1 then '31/01/'+cast(@an as varchar(4))
              when 2 then cast(@anbisect as varchar(2))+'/02/'+cast(@an as
    varchar(4))
       when 3 then '31/03/'+cast(@an as varchar(4))
       when 4 then '30/04/'+cast(@an as varchar(4))
        when 5 then '31/05/'+cast(@an as varchar(4))
       when 6 then '30/06/'+cast(@an as varchar(4))
       when 7 then '31/07/'+cast(@an as varchar(4))
       when 8 then '31/08/'+cast(@an as varchar(4))
       when 9 then '30/09/'+cast(@an as varchar(4))
              when 10 then '31/10/'+cast(@an as varchar(4))
       when 11 then '30/11/'+cast(@an as varchar(4))
       when 12 then '31/12/'+cast(@an as varchar(4))
          end

       open tabel_perioade
       fetch next from tabel_perioade into @nr, @an_cursor,@luna, @descr_cursor, @start_cursor, @stop_cursor

       while @@fetch_status = 0
       begin
            if(@nr < (@nrluni+1) )
             begin
      insert into @perioade(nrrand, an, descr, begindate, enddate)
             select @nr_cursor, @an_cursor, @descr_cursor, @start_cursor, @stop_cursor
             fetch next from tabel_perioade into @nr, @an_cursor,@luna, @descr_cursor, @start_cursor, @stop_cursor
     end
       end


       close tabel_perioade
       deallocate tabel_perioade
       
       select * from @perioade order by nrrand

     end

    el acum imi intoarce

    NULL 2007 Martie 12/03/2007 31/03/2007

    eu as vrea sa-mi intoarca

    1    2007   Martie  12/03/2007     31/03/2007

    2     2007   Aprilie   01/04/2007    30/04/2007

    3    2007    Mai     01/05/2007      31/05/2007

    .......

     6   2007   August  01/08/2007     05/08/2007

     

    Multumesc mult.

View Complete Thread
Powered by Community Server (Commercial Edition), by Telligent Systems