zubinbalsara
Programmer
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
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