SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how open a excel from stored procedure


how open a excel from stored procedure

Author
Message
anonimato36
anonimato36
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 1
Hi all

i need open a excel file using store procedure, someone know how do it?

claudia
Lowell
Lowell
SSC Guru
SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)

Group: General Forum Members
Points: 71794 Visits: 40942
you posted in SQL2000, so be aware that if you meant 2008 or above, the ACE drivers would b eused instead.

typically, you will create a linked server, and reference theworksheet(s) via a four part naming convention inside the stored proc or other code.


--#################################################################################################
--Linked server Syntax for Excel
--#################################################################################################
DECLARE @server sysname,
@srvproduct nvarchar(256),
@provider nvarchar(256),
@datasrc nvarchar(100),
@location nvarchar(100),
@provstr nvarchar(100),
@catalog sysname,
@sql varchar(1000)

--add an excel spreadsheet as a linked server.
SET @server = 'HENNXLS'
SET @srvproduct = 'Jet 4.0'
SET @provider = 'Microsoft.Jet.OLEDB.4.0'
set @provstr = 'Excel 5.0;'
SET @datasrc ='C:\Clients\Hennepin\Scripts\Activity Types Client FINAL APPROVAL.xls'
EXEC sp_addlinkedserver @server,@srvproduct,@provider,@datasrc,NULL,@provstr
EXEC dbo.sp_AddLinkedSrvLogin @server, FALSE, NULL, Admin, NULL
--you MUST know the name of the spreadsheet;
--spreadsheet name has a dollar sign at the end of it!
--I've personally never got a spreadsheet that has a space in it
--for example "Activity Data" =ActivityData$ never got [Activity Data$] or [Activity Data]$ to work
--to work, so I end up editing the spreadsheet to remove spaces if that happens.
IF OBJECT_ID('dbo.HENN', 'SN') IS NOT NULL
DROP SYNONYM dbo.HENN;
CREATE SYNONYM dbo.HENN FOR HENNXLS...ActivityData$;
--list all the spreadsheets and their names
EXEC sp_tables_ex 'HENNXLS'
/*
cleanly access data taking advantage of synonyms in 2005
select * from HENNXLS...ActivityData$;
select * from HENN
*/
GO



Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search