SQL Server Management Studio -- Script that executes other scripts? -
so have been looking around way develop script execute other scripts within project folder using sql server management studio , far none of other solutions have worked. tried writing script had sqlcommandline stuff in it:
sqlcmd -s.\sqlexpress -imyscript.sql;
and didn't work , understanding using @\path\to\script.sql
won't work either other ideas? or should start looking writing procedure? in case, point me in right direction?
thank in advance assistance.
personally, i'd writing stored procedures. msdn documentation , there lots of resources on line if quick search.
alternatively make happen (you'll need have permission execute command shell, etc):
create table ##sqlfiles ( sqlfilename varchar(2000)) go insert ##sqlfiles execute master.dbo.xp_cmdshell 'dir /b "c:\sql scripts\*.sql"' go declare cfiles cursor local select distinct [sqlfilename] ##sqlfiles [sqlfilename] not null , [sqlfilename] != 'null' order [sqlfilename] declare @vfilename varchar(200) declare @vsqlstmt varchar(4000) open cfiles fetch next cfiles @vfilename while @@fetch_status = 0 begin -- following set command must on single line or else error generated. -- split in script readability purposes. set @vsqlstmt = 'master.dbo.xp_cmdshell ''osql -s server name -u user name -p password -d database name -i "c:\sql scripts\' + @vfilename + '"''' execute (@vsqlstmt) fetch next cfiles @vfilename end close cfiles deallocate cfiles go drop table ##sqlfiles go
Comments
Post a Comment