如何使用 SQL CMD 并在每次在 sql server 中运行脚本时输出一个新文件?

发布于 2025-01-14 01:44:20 字数 265 浏览 2 评论 0原文

我有一个如下所示的脚本,我放入一个作业中,它运行并输出一个文件。

sqlcmd -E -i t:\export\test.sql -o t:\export\MyReport.txt

当我运行它时,它运行良好并将文件输出到指定的位置。

我想要做的是,有没有一种方法可以添加到代码中,以便每当此脚本运行时,它都会创建一个新文件,而不删除上次运行生成的旧文件?基本上,如果作业运行 10 次,我就会有 10 个不同的文件。

谢谢。

I have a script like below i put in a Job and it runs an outputs a file.

sqlcmd -E -i t:\export\test.sql -o t:\export\MyReport.txt

When i run this, it works well and outputs a file to the location specified.

What i am looking to do is, is there a way i can add to the code so that anytime this script runs, it will create a new file and not remove the old file the previous run generated? Basically if the job runs 10 times, i have 10 different files.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℡寂寞咖啡 2025-01-21 01:44:21

只需在文件名中添加一些时间即可。

sqlcmd -E -i t:\export\test.sql -o t:\export\MyReport-%DATE%.txt

Simply add some time added to your file name.

sqlcmd -E -i t:\export\test.sql -o t:\export\MyReport-%DATE%.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文