Change level of detail with temp table name.
DECLARE
@db_name SYSNAME,
@sql VARCHAR(1000),
@databaseNM varchar(50),
@ACOBJ int,
@ACLDA int
set @ACLDA=4
drop table #temp1
create table #temp1 (fld1 int,fld2 int)
DECLARE db_cursor CURSOR FOR
--SELECT Name FROM sys.databases where Name=@databaseNM
select ACOBJ obj from JDE_PRODUCTION.PRODDTA.F0909 where ACLDA=@ACLDA and acobj>00000 and acobj<100000 --and acobj=41110
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @db_name
WHILE (@@FETCH_STATUS = 0)
BEGIN
select @ACOBJ=MAX(ACOBJ) from JDE_PRODUCTION.PRODDTA.f0909 where ACLDA=@ACLDA-1 and ACOBJ <(select MAX(ACOBJ) from JDE_PRODUCTION.PRODDTA.f0909 where ACOBJ=@db_name and ACLDA=@ACLDA)
--select @ACOBJ=MAX(ACOBJ) from JDE_PRODUCTION.PRODDTA.f0909 where ACLDA=6 and ACOBJ <(select MAX(ACOBJ) from JDE_PRODUCTION.PRODDTA.f0909 where ACOBJ=@db_name and ACLDA=7)
Insert into #temp1 select @ACOBJ,@db_name
FETCH NEXT FROM db_cursor INTO @db_name
END
CLOSE db_cursor
DEALLOCATE db_cursor
--drop table #temp5
select * into #temp5 from #temp1
select * from #temp1
--select * from #temp5
--select * from #temp6
--select * from #temp7
--select * from #temp8
--drop table #temp4_1
select a7.fld1 A_071,a7.fld2 A_072,a8.fld1 A_081,a8.fld2 A_082 into #temp7_1 from #temp7 a7
left outer join #temp8 a8 on a7.fld2=a8.fld1
select fld1 A_061,fld2 A_062,A_071,A_072,A_081,A_082 into #temp6_1 from #temp7_1 a7
left outer join #temp6 a6 on a6.fld2=a7.A_071
select fld1 A_051,fld2 A_052,A_061,A_062,A_071,A_072,A_081,A_082 into #temp5_1
from #temp6_1
left outer join #temp5 a5 on a5.fld2=A_061
select A_051,A_061,A_062,A_072, ISNULL(A_082,'')A_082 from #temp5_1
No comments:
Post a Comment