I have the following code but I can not get the reults to populate Excel even though they return results in query editor. Its a slow query but should't cause a problem
declare @dbs table (db varchar(20))
insert into @dbs
select upper(wdname) from csmaster.scheme.workdirm where dgroup = 'sys'
and (upper(wdname) not like 'PR006%' and upper(wdname) not like 'HWK013%' and upper(wdname) not like 'ZB%')
declare @jrns table (company varchar(20),journal_no varchar(20),period_from varchar(2),period_to varchar(2),post_date varchar(20))
declare @sql varchar(1000)
declare @dbname varchar(20)
declare getdb cursor for select db from @dbs
open getdb
fetch next from getdb into @dbname
while @@FETCH_STATUS = 0
begin
set @sql = 'select distinct ''' + @dbname + ''' company, journal_number,from_period , trans_period, post_date from ' + @dbname + '.scheme.nltranm where nlyear = 13 and (nlyear + from_period ) > (nlyear + trans_period)and origin =''NJ''and from_period != ''12'''
insert into @jrns
exec (@sql)
fetch next from getdb into @dbname
end
select * from @jrns
declare @dbs table (db varchar(20))
insert into @dbs
select upper(wdname) from csmaster.scheme.workdirm where dgroup = 'sys'
and (upper(wdname) not like 'PR006%' and upper(wdname) not like 'HWK013%' and upper(wdname) not like 'ZB%')
declare @jrns table (company varchar(20),journal_no varchar(20),period_from varchar(2),period_to varchar(2),post_date varchar(20))
declare @sql varchar(1000)
declare @dbname varchar(20)
declare getdb cursor for select db from @dbs
open getdb
fetch next from getdb into @dbname
while @@FETCH_STATUS = 0
begin
set @sql = 'select distinct ''' + @dbname + ''' company, journal_number,from_period , trans_period, post_date from ' + @dbname + '.scheme.nltranm where nlyear = 13 and (nlyear + from_period ) > (nlyear + trans_period)and origin =''NJ''and from_period != ''12'''
insert into @jrns
exec (@sql)
fetch next from getdb into @dbname
end
select * from @jrns