Importing sql query output in excel

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
exppost
Posts: 3
Joined: 05 Oct 2021 14:51

Importing sql query output in excel

#1 Post by exppost » 06 Sep 2022 13:03

I have few queries writtern in different rows in excel like
In Sheet1
cell A1 - SELECT FROM DBO.EMP
cell A2 - select from dbo.dept
cell A3 -
select from dbo.emp
except
select from sa.emp
cell A4 - select * from sa.loc

now I want these queries to be fired in some test db in sql server 2017,

and the output for query should be writtern in new sheet (sheet2) like
in cell A1 - query should be there
and from cell B1 , output should get printed
The next query should get printed after the first query output. Like if the first query results ends in row - B12,
the second query output should start from row B13, and the second query in the new sheet should be displayed in cell A13
Similarly the query and output should get displayed as per attached Pic.
Any code in VBA should help?


Office version - Microsoft office Profession Plus 2016
Database Tool Version- SQL Server 2017
Attachments
excel_ouput.PNG
excel_ouput.PNG (29.67 KiB) Viewed 1960 times

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: Importing sql query output in excel

#2 Post by miskox » 08 Sep 2022 03:36

I think that VBA (in Excel) is what you need.

Saso

Post Reply