Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

UNABLE TO EXECUTE THE CMDSQL SCRIPT IN A STORE PROCEDURE.

$
0
0

I am trying to call a .sql file from sql cmd mode.

The requirement is to pass the .sql file as parameter value to the cmd script which I have able to achieve,here is the code which is working fine .

declare @x sysname
set @x = 'C:\Users\testuser\Desktop\testing.sql'

:OUT $(TEMP)\GetServerName1.sql
PRINT ':SETVAR FilePath'+ ' ' + @x
GO
:OUT stdout

:r $(TEMP)\GetServerName1.sql
GO
:r $(FilePath)

But when I try to wrap this code in store procedure it is giving the message fatal error but when I run it without wrapping it in store proc it is doing its job with no error . When I looked into the store proc I found the code as

ALTER proc [dbo].[testing]
as

declare @x sysname
set @x = 'C:\Users\testuser\Desktop\testing.sql'

PRINT ':SETVAR FilePath'+ ' ' + @x

It seems like the sqlcmd code disappears automatically. I have no clue why it is happening. 

Can anyone help in letting me knw how to wrap the above code in store proc.

Thanks Saurav 

 

Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>