Solved

SQL Data Export to Excel

Posted on 2016-08-22
5
62 Views
Last Modified: 2016-09-26
i use ms sql >> sql agent >> create a job >> and export data into excel. See attached.
I want the columns inside of the cells inside of excel. Just like normal look.

How can I do that?
test3.xls
0
Comment
Question by:ITsolutionWizard
5 Comments
 
LVL 33

Assisted Solution

by:ste5an
ste5an earned 250 total points
ID: 41766546
Your attachment is not readable.

Either you concat(enate) the contents in a T-SQL statement(s) in your job or - depending on the kind of usage of those Excel files - use a macro to format it accordingly (in the personal workbook).
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 41766814
What's in the job?
0
 
LVL 28

Accepted Solution

by:
Ryan McCauley earned 250 total points
ID: 41767635
I can't read your sheet (like others), but I'd recommend that you format a blank excel document the way you want, and then export the data into it using OPENROWSET. If you wanted to keep a copy of the template, you can have a step that uses xp_cmdshell to make a copy of the file first with a new name, then exports the data into the new file and leaves the original intact.

There's an example available at this SO question:

DECLARE @myfile varchar(800)

SET @myfile = 'C:\template.xls'

EXEC ('
insert into OPENROWSET(''Microsoft.Jet.OLEDB.4.0'', 
''Excel 8.0;Database=' + @myfile + ';'', 
''SELECT * FROM [SheetName$]'') 
select * from myTable
')

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now