Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL STATEMENT WILL NOT RETURN RESULTS TO EXCEL FROM MSQUERY

Status
Not open for further replies.

PETEHO

Programmer
Jan 17, 2002
45
0
0
GB
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
 
How are you calling this code in Excel?

-----------
With business clients like mine, you'd be better off herding cats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top