Solved

Export SQL Server Table to Excel File

Posted on 2010-09-20
12
718 Views
Last Modified: 2012-10-02
Hi: I need to export any SQL server Table or Query into a EXCEL file, Excel File will be created from scratch, basically I'm looking for a module I can attach to my ASP program.
Sql server Web version 2008
Excel File could be 2003 or 2007
No bulk mode may apply since I need to manipulate excel file after export.
I saw T-SQL, problem is excel file will need to contain file structure prior exporting process
Regards
0
Comment
Question by:rubensc
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 6

Expert Comment

by:maxy88
ID: 33719485
In Excel, go to Data->Import External Data. You have a number of choices:

1) Select Data->Import External Data->Import Data. Click on New Source button and go from there using the wizard. You can use an ODBC connector at this step if that makes it easier for you.
2) Select Data->Import External Data->New Database query.
3) Select Data->Import External Data->New Web query if this applies to you.
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 33719494
Hi,

If I understand correctly, you want your ASP app to have the ability to export table data to an Excel file?

In other words, you would like a like or an icon that says, "Export to Excel".

Is that what you are trying to do?
0
 

Author Comment

by:rubensc
ID: 33719507
Hi Maxy88, not usefull, export process needs to be programatically in asp environment, not manual
Regards
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:rubensc
ID: 33719559
ammySeltzer: I need to create the logic behind the icon, for SQL 2000 I developed a dll, it uses DTC pump, and it works ok, we are moving to a new server using SQL 2008 and library does not work.

The process to have a module/library/query that can extract data from SQL to EXCEL file
Regards
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 33719863
So, are you looking to do this using ASP?
0
 

Author Comment

by:rubensc
ID: 33720189
I can go two ways
1) A query  Transact SQL
2) A dll to invoke using server.createobject
regards
0
 
LVL 33

Expert Comment

by:Norie
ID: 33730411
If you already have something that does this and you know the logic behind that why not just apply that to the new situation.


Or is it actually the details of how to actually do the export?

You say the library you developed earlier won't work? How?

Could you not at least take any parts of it that do work as a basis?

Also how do you intend manipulating the newly created Excel file?

PS I assume it will be created because you seem to be saying that's what you need/want to do.
0
 

Author Comment

by:rubensc
ID: 33740262
imnorie: Imagine I don't have anything at all, I will need a new solution from scratch
Regards
0
 
LVL 33

Expert Comment

by:Norie
ID: 33740375
Well if I fully understood what you actually want to do I might make some suggestions but it's not clear, to me anyway.

In your first post you talked about wanting someting to  'attach to my ASP program', what do you mean by that.

You also seem to be ruling out certain methods eg 'no bulk method may apply'.

Then there's Excel, why does it need to contain a 'file structure' before export/import? What do you mean by 'file structure'?

One other thing you mention is that you want to manipulate what's been exported.

Do you simply mean you want Excel, with the exported data, to stay open after the export?
0
 

Accepted Solution

by:
rubensc earned 0 total points
ID: 33780429
HI: I resolve it using openrowset and creating the excel file before exporting data, now it works fine.
Thanks any way
0
 

Author Comment

by:rubensc
ID: 33780515
To export data use openrowset function, sql allows you to do that, review the following link

http://www.mssqltips.com/tip.asp?tip=1202

In other to export data the following conditions must meet
a) Excel file needs to be ready before exporting
b) Column Names need to match in query, not recomend to use select *, instead use select field1,field2,field3,... fieldn.
c) SQL property for this kind of query needs to be enable, as soon as you try the first query, SQL will tell whats wrong and the proper adjustment.

0
 
LVL 33

Expert Comment

by:Norie
ID: 33783051
I'm pretty sure you could have got that answer/suugestion a bit earlier if you had been a bit clearer in your question.
Anyway, you found a solution and that's the important thing.
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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

770 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