1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| DECLARE @i INT;
DECLARE @j INT;
DECLARE @str char(10);
SET @str= 'Excel 8.0;Database=C:\test' + @j + '.xls;HDR=YES'
SET @i = 0;
SET @j = 1;
WHILE(@i < 3)
BEGIN
DECLARE @connectionString VARCHAR(255),
@requete VARCHAR(255),
@openRowSetCommand VARCHAR(512);
SELECT @connectionString = 'Microsoft.Jet.OLEDB.4.0,' + @str,
@requete = 'SELECT * FROM [Sheet1$]';
SET @openRowSetCommand = 'SELECT * FROM OPENROWSET(' + @connectionString + ',' + @str + ',' + @requete + ')'
PRINT @openRowSetCommand
INSERT INTO Test
EXEC (@openRowSetCommand)
SET @i = @i + 1
END |
Partager