SQL Query to output formatted Excel file

I need to create a query (SQL 2000) that renders a formatted excel (xml or xls) file for each row that is outputted.

The details, I have a Campaign table that contains information for Auto and Life "Leads" and the data is submitted by telemarketers directly into the database. I need to render a file for each line, and it would be good if It were an Excel XML or XLS file, because that's what we've been using for a while.

[448 byte] By [TobiLehman] at [2007-12-22]
# 1

Hi Tobi,

Have you had a look at FOR XML? For example:

SELECT * FROM sys.objects FOR XML AUTO.

If indeed you wish to create a file automatically for each line then SSIS (DTS in 2000) will be able to do this.

Cheers,

Rob

RobertVarga at 2007-8-30 > top of Msdn Tech,SQL Server,Transact-SQL...
# 2

hi

try this query

Exec master..xp_cmdshell 'bcp "use dbName; select * from tableName" queryout "e:\test.xls" -c -CRAW'

hope this will help you

ArifHasan at 2007-8-30 > top of Msdn Tech,SQL Server,Transact-SQL...

SQL Server

Site Classified