質問

I have a stored procedure through which I am creating a dynamic .sql file on the server and the file have successfully generated. Now I want o execute the same file through query in the same stored procedure .

I have go through the links and found the below lines useful

osql -D db_name -S server_name -U username -P password -i sqlfile

or

sqlcmd -D db_name -S server_name -U username -P password -i sqlfile

I have tried to implement the above but it is giving me the error of

osql is not a recognized option

Please tell me the correct way. Thanks

役に立ちましたか?

解決

sqlcmd is a command line tool and cannot be called directly from inside a stored procedure.

Use xp_cmdshell to execute it:

EXEC master.dbo.xp_cmdshell ‘sqlcmd -D db_name -S server_name -U username -P password -i sqlfile’
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top