Welcome to Sign in | Help

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

  •  09-21-2007, 5:51 PM

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

    problema nu era de numerotarea liniilor neaparat ci de ce intoarce selectul respectiv

    am rezolvat astfel.....am renuntat la cursor si folosesc o tabela temporara astfel

    --alter procedure spr_gprListaPerioade

    declare @datainit varchar(10),

    @datasf varchar(10)

    set @datainit = '12/03/2007'

    set @datasf = '05/08/2007'

    --as

    begin

    declare @perioade2 table (nr_rand 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=1;

    set @an=cast(substring(@datainit,7,4)as int)

    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)

    while (@an<=cast(substring(@datasf,7,4)as int) and @luna<=cast(substring(@datasf,4,2) as int)) -- ) or (@an=cast(substring(@datasf,7,4)as int)

    begin

    insert into @perioade2(nr_rand, an, descr, begindate, enddate)

    select @nr,@an, case @luna

    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

    when (@luna=cast(substring(@datainit,4,2) as int) and @an=cast(substring(@datainit,7,4)as int)) then @datainit

    else '01/'+ (case when @luna<10 then '0' else '' end) + cast(@luna as varchar(2))+'/'+cast(@an as varchar(4))

    end,

    case

    when (@luna=cast(substring(@datasf,4,2) as int) and @an=cast(substring(@datasf,7,4)as int)) then @datasf

    when @luna=1 then '31/01/'+cast(@an as varchar(4))

    when @luna=2 then cast(@anbisect as varchar(2))+'/02/'+cast(@an as varchar(4))

    when @luna=3 then '31/03/'+cast(@an as varchar(4))

    when @luna=4 then '30/04/'+cast(@an as varchar(4))

    when @luna=5 then '31/05/'+cast(@an as varchar(4))

    when @luna=6 then '30/06/'+cast(@an as varchar(4))

    when @luna=7 then '31/07/'+cast(@an as varchar(4))

    when @luna=8 then '31/08/'+cast(@an as varchar(4))

    when @luna=9 then '30/09/'+cast(@an as varchar(4))

    when @luna=10 then '31/10/'+cast(@an as varchar(4))

    when @luna=11 then '30/11/'+cast(@an as varchar(4))

    when @luna=12 then '31/12/'+cast(@an as varchar(4))

    end

    set @luna=@luna+1

    if @luna=13 begin

    set @luna=1

    set @an=@an+1

    end

    set @nr=@nr+1

    end

    select * from @perioade2 order by nr_rand

    end

    Multumesc mult

    Alex.

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