[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 80
  • Last Modified:

SQL Data Export to Excel

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
ITsolutionWizard
Asked:
ITsolutionWizard
2 Solutions
 
ste5anSenior DeveloperCommented:
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
 
Vadim RappCommented:
What's in the job?
0
 
Ryan McCauleyCommented:
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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now