CREATE TABLE #T(filename nvarchar(1024)); INSERT #T EXEC xp_cmdshell N'dir C:/T_SQL_Script /b'; DELETE #T WHERE filename IS NULL; DECLARE @FILENAME NVARCHAR(1024); DECLARE cur CURSOR FOR SELECT filename FROM #T; OPEN cur; DECLARE @sql NVARCHAR(1000); FETCH NEXT FROM cur INTO @FILENAME; WHILE @@FETCH_STATUS=0 BEGIN SET @sql=N'sqlcmd -E -SinstanceName -i'+@FILENAME; EXEC xp_cmdshell @sql; FETCH NEXT FROM cur INTO @FILENAME; END CLOSE cur; DEALLOCATE cur;
循环文件夹 读入文件内语句并执行
最新推荐文章于 2021-08-21 12:09:22 发布