Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Sybase ASA, ASE, IQ [игнор отключен] [закрыт для гостей] / mssql --> sybase / 4 сообщений из 4, страница 1 из 1
09.03.2009, 10:25
    #35857959
grippuyu
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
mssql --> sybase
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
set nocount on
go
use sobaka_pavlova
go

declare @mama_proc sysname, -- имя процедуры из которой идет вызов (мама)
        @daughter_proc sysname, -- имя вызываемой процедуры (дочка)
        @nested_level int, -- уровень вложенности, до которого будем раскручивать дерево
        @level int, -- счетчик вложенности
        @pid int -- id процедуры-мамы

select @mama_przoc = 'DocCasGen',
	 @nested_level =  4 


drop table #tree_table
create table #tree_table -- таблица, содержащая дерево процедур
   (
    nested_level int, -- уровень вложенности процедуры
    id int identity not null,            -- идентификатор поцедуры
    pid int,          -- идентификатор родительской процедуры
    proc_name sysname        -- имя самой процедуры
   )

-- вставим в таблицу первую строку с исходной процедурой
insert into #tree_table (nested_level, pid, proc_name)
 select  0 ,  0 , @mama_proc
 
-- установим счетчик вложенности в 0
select @level =  0 
while @level <= @nested_level
 begin
   --Начитаем список мам 
   -- курсор для начитки имен процедур из #tree_table с текущим уровнем
     declare mama_proc_name_cur cursor for 
       select id, proc_name from #tree_table
         where nested_level = @level

     open mama_proc_name_cur
       fetch next from mama_proc_name_cur into @pid, @mama_proc
        while @@fetch_status= 0 
          begin
              -- начитаем список дочек и вставим их в #tree_table
			-- курсор для начитки имен процедур (дочек), которые вызываются из процедуры (мамы), обозначенной в @mama_proc
			  declare daughter_proc_name_cur cursor for 
			       select distinct object_name(d.depid) 
			         from sysdepends d, sysobjects o
			         where d.depid = o.id
			          and o.xtype in ('P')
			            and d.id  = object_id(@mama_proc)

                open daughter_proc_name_cur
                    fetch next from daughter_proc_name_cur into @daughter_proc
                      while @@fetch_status= 0 
                        begin
                          insert into #tree_table (nested_level, pid, proc_name)
                            select @level +  1 , @pid, @daughter_proc

                          fetch next from daughter_proc_name_cur into @daughter_proc
                        end
                close daughter_proc_name_cur
                deallocate daughter_proc_name_cur
         fetch next from mama_proc_name_cur into @pid, @mama_proc
       end
     close mama_proc_name_cur
     deallocate mama_proc_name_cur

     select @level = @level +  1 
 end

select * from #tree_table
...
Рейтинг: 0 / 0
09.03.2009, 10:29
    #35857962
grippuyu
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
mssql --> sybase
Нужно переделать этот MSSQL-скрипт так, чтоб она работал в Sybase.
Вместо курсоров можно таблицы создать. Не важно как, важно - чтоб отработал.
Буду очень благодарен
...
Рейтинг: 0 / 0
09.03.2009, 14:54
    #35858277
MasterZiv
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
mssql --> sybase
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
drop procedure sp_depend_tree
go

create procedure sp_depend_tree
@parent_proc varchar( 32 ),
@nesting_level int
as 

declare @child_proc varchar( 32 ), 
        @level int,
        @pid int,
	@found_some_on_level int
	
if not exists (select  1  from sysobjects o where o.name = @parent_proc and o.type = 'P')
begin
  raiserror  20000  'There is no such procedure %1!', @parent_proc
  return  10 
end

create table #tree_table 
(
    nesting_level int, 
    pid int,
    proc_name varchar( 32 )
)

insert into #tree_table (nesting_level, pid, proc_name)
select  0 , object_id(@parent_proc), @parent_proc 
 
select @level =  0 
while @level <= @nesting_level
begin

     declare parent_procs cursor 
     for select proc_name, pid
     from #tree_table
     where nesting_level = @level

     open parent_procs
     select @found_some_on_level =  0 
     
     while  1 = 1  
     begin
     
	fetch parent_procs into @parent_proc, @pid
        if @@sqlstatus <>  0 
	  break
	
	select @found_some_on_level =  1 
	
	insert into #tree_table (nesting_level, pid, proc_name)
	select @level +  1 , o.id, chi.name
	from sysobjects o
	join sysdepends d on d.id = o.id
	join sysobjects chi on chi.id = d.depid and chi.type = 'P'
	where o.type = 'P'
	  and o.name  = @parent_proc
	  and not exists ( select  1  from #tree_table t
		           where t.pid = chi.id )
	  
     end
     
     close parent_procs
     deallocate cursor parent_procs

     select @level = @level +  1 
     
     if @found_some_on_level =  0 
       break
end

select * from #tree_table

go
...
Рейтинг: 0 / 0
11.03.2009, 18:21
    #35863002
grippuyu
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
mssql --> sybase
The command executed successfully with no results returned.
и всё...:(
...
Рейтинг: 0 / 0
Форумы / Sybase ASA, ASE, IQ [игнор отключен] [закрыт для гостей] / mssql --> sybase / 4 сообщений из 4, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]