Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare @tabela as table (obraid int, cronograma int, mes int, ano int)
- declare @teste as table (obraid int, cronograma int, mes int, ano int)
- insert into @tabela values(123,5,08,2013)
- insert into @tabela values(124,4,09,2013)
- insert into @tabela values(125,4,12,2013)
- declare @cronograma int,
- @obraid int ,
- @mes int,
- @ano int,
- @mesAlterado int,
- @Rownu int
- set @Rownu = 0
- DECLARE cursor_objects CURSOR FOR
- select obraid,cronograma,mes,ano
- from @tabela
- OPEN cursor_objects
- FETCH NEXT FROM cursor_objects INTO @obraid,@cronograma,@mes,@ano
- WHILE @@FETCH_STATUS = 0
- BEGIN
- while @cronograma > 0
- begin
- set @Rownu = @Rownu + 1
- if @Rownu = 1 set @mesAlterado = @mes
- if @Rownu > 1
- set @mesAlterado = @mes +1
- insert into @teste (obraid,cronograma,mes,ano ) values (@obraid,@Rownu,@mesAlterado, @ano)
- set @cronograma = @cronograma - 1
- set @mes = @mesAlterado
- end
- FETCH NEXT FROM cursor_objects INTO @obraid,@cronograma,@mes,@ano
- END
- CLOSE cursor_objects
- DEALLOCATE cursor_objects
- select * from @teste
Advertisement
Add Comment
Please, Sign In to add comment