开发者

Is there a way to get the currently executing file from sqlcmd?

If I call sqlcmd with the -i command line switch, I'd like to be able to get the name of the file. So, I call

sqlcmd -S <servername> -E -i filename.sql

I'd like to be able to somehow have the contents of the script be able to print the filename without having to hard code it in the file. Looking at the variables and commands that are documented in BOL, I don't see anything like this, bu开发者_开发百科t just wanted to make sure. Thanks in advance.


Among the list of sqlcmd Scripting Variables, I don't see anything that has the name for the input file.

But you can send the file name as a parameter when you call sqlcmd.

Input file (filename.sql)

PRINT '$(p1)' 

Sqlcmd:

sqlcmd -S .\Server -i filename.sql -v p1="filename.sql"


May be you should explore powershell for this

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜