Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable worksheet name in openrowset

Status
Not open for further replies.

zubinbalsara

Programmer
Jul 10, 2006
2
0
0
US
HI Guys,
Is there a way to use a variable worksheet name in the openrowset. I need to open an excel file in my cursor, my worsheet name is not constant all the time,so i need to place a variable instead. Here is a snippet from my code

declare @mysheet varchar(200)
set @mysheet='sheet1$'
Declare getDistrict cursor for
SELECT district, healthplan
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;HDR=Yes; IMEX=1;Database=D:\DatabaseUploads\Nexium\crestor.xls',
'SELECT * FROM ['''+@mysheet+''']')
WHERE [District] IS NOT NULL
set nocount on;
open getDistrict

Thanks for all your help
 
here is where you can find out:

forum183

ANSI SQL <> SQL Server

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top