Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Read a result of an SQL.

Author  Topic 

csmoniz
Starting Member

5 Posts

Posted - 2010-07-14 : 14:50:55
Dear Friends.

How can I read a result of an SQL query directly to an Excel table?
I'm using SQL Server 2000.

Thanks
Cezar Moniz

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-14 : 15:02:04
You can easily do this via bcp.exe, which is a command line executable. Is that a possibility or are you looking for something else?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

csmoniz
Starting Member

5 Posts

Posted - 2010-07-14 : 15:43:56
Tara Kizer.
Basically I need the following:
Draw a graph in Excel with the results of queries. Perhaps even better to make a dynamic table, but I have read from a table in SQL.
Do you have any suggestions?
Thank´s a lot

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-14 : 17:29:57
I can only help exporting data from SQL Server into a csv file (Excel can read a csv file). I haven't a clue how you would graph it.

Here's an example of bcp:

bcp.exe Db1.dbo.Tbl1 out C:\temp\SomeFile.csv -t, -Sserver1\instance1 -T -c -r\r\n

Run bcp /? from a command window to see its options or check Books Online. Alternatively you could use SSIS to create the Excel file, but bcp is so simple with a csv file. You can even do queries instead of an entire table:

bcp.exe "select * from Db1.dbo.Tbl1 where column1 > 999" queryout C:\temp\SomeFile.csv -t, -Sserver1\instance1 -T -c -r\r\n

If the query becomes too complex for bcp, then you would need to wrap it into a view and then bcp the view out.

SSIS can do very fancy transformations and exports, so maybe you should look into that if bcp.exe isn't enough for your issue.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

csmoniz
Starting Member

5 Posts

Posted - 2010-07-14 : 18:25:18
My friend.

I think you could see the problem and i agreed with the solution.
I will follow your suggestion. I will do the queries and views and try.
I was trying with WebComponet. But it did not work.

Thank´s a lot.
Go to Top of Page
   

- Advertisement -