Groups | Blog | Home
all groups > sql server reporting services > november 2006 >

sql server reporting services : Stored Procedure ------> Excel Spreadsheet


pichula
11/9/2006 11:09:19 AM
I have a stored proc. that returns a variable number of fields and I
would like to be able to save it into an Excel spreadsheet (.xls). I
tried using reporting services but you cannot display fields (columns)
dynamically in the report (unless you have some method to hide and show
some of the columns).

Is there any other way to do this? Maybe XML/XSL.

Thanks,
Pablo
aaron.kempf NO[at]SPAM gmail.com
11/9/2006 12:04:29 PM
Access Data Projects can export to XLS without a problem

Don't overthink it

[quoted text, click to view]
Doownai
11/10/2006 10:08:02 AM
depending upon your views of xp_cmdshell, you could try something like this:

modify your stored procedure to return its data to a temporary table and
then use the following Stored Procedure to make a call to the bcp utility to
send it to a file.

create proc [EXPORT_TABLE]
(@TabName as varchar(30)
,@Filename varchar(100) output )
as
begin
set nocount on
declare
@Path varchar(2000),
@bcpCommand varchar(2000)

-- set your path to stored the file
set @Path = 'D:\temp\'
set @FileName = @Filename + '.xls'

-- export the data
-- you will have to make an edit or two for your environment.
set @bcpCommand = 'bcp [yourDBname].dbo.' + @TabName + ' out "' + @path +
@FileName + '" -c -T -U [username] -P [password]'
exec master..xp_cmdshell @bcpCommand--, no_output
end

go

[EXPORT_TABLE] <YourTabName>, <YourFileName>


Cheers,

pichula
11/10/2006 11:10:51 AM
Thanks Ian, I'll try it.


[quoted text, click to view]
aaron.kempf NO[at]SPAM gmail.com
11/10/2006 1:37:56 PM
or you could open your Access Data Project.. and TOOLS, Analyze with
Excel and presto, chango-- any data you've got in SQL, including views,
sprocs, forms, reports-- you can export to Excel

-Aaron



[quoted text, click to view]
AddThis Social Bookmark Button