消息 102,级别 15,状态 1 第 1 行 “n”附近的语法不正确
我有以下查询,我正在使用批处理文件运行。在批处理文件中,我使用以下语法:
echo populating Application table with values...
SET "installFile=%sqlDir%\Install\DataFiles\Insert_ApplicationNames.sql"
OSQL /n /i "%installFile%" /d%db% /U%user% /P%pswd% /S%serv%
echo
echo populated Application table with values in Insert_ApplicationNames.sql
echo
从 SQL Management Studio 执行时,下面显示的 sql 运行时没有任何错误,但作为批处理脚本的一部分运行时,它不断出错。有人可以帮我找出我可能做错了什么吗?
此外,行确实被插入,但我们的夜间 QA 安装由于批处理脚本抛出的错误而中断。
IF NOT EXISTS(SELECT * FROM Application WHERE name = '')
BEGIN
INSERT INTO Application
(Name)
VALUES
('')
END
GO
IF NOT EXISTS(SELECT * FROM Application WHERE name = 'App1.exe')
BEGIN
INSERT INTO Application
(Name)
VALUES
('App1.exe')
END
GO
IF NOT EXISTS(SELECT * FROM Application WHERE name = 'App2.exe')
BEGIN
INSERT INTO Application
(Name)
VALUES
('App2.exe')
END
I have the following query which I am running using a batch file. In the batch file I use the following syntax:
echo populating Application table with values...
SET "installFile=%sqlDir%\Install\DataFiles\Insert_ApplicationNames.sql"
OSQL /n /i "%installFile%" /d%db% /U%user% /P%pswd% /S%serv%
echo
echo populated Application table with values in Insert_ApplicationNames.sql
echo
The sql shown below runs without any errors when executed from the SQL Management Studio, but it keeps erroring out when run as a part of the batch script. Could some one help me find what I may be doing wrong here?
Also, the rows do get inserted, but our nightly QA install breaks because of the error thrown by the batch script.
IF NOT EXISTS(SELECT * FROM Application WHERE name = '')
BEGIN
INSERT INTO Application
(Name)
VALUES
('')
END
GO
IF NOT EXISTS(SELECT * FROM Application WHERE name = 'App1.exe')
BEGIN
INSERT INTO Application
(Name)
VALUES
('App1.exe')
END
GO
IF NOT EXISTS(SELECT * FROM Application WHERE name = 'App2.exe')
BEGIN
INSERT INTO Application
(Name)
VALUES
('App2.exe')
END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GO
是 Management Studio 中的(默认)批处理分隔符关键字,但它不是真正的 SQL 关键字(即 SQL Server 无法识别它)。从你的脚本中删除它们——在你提供的脚本中,它们无论如何都是无关紧要的——你应该很好,嗯,走。
GO
is the (default) batch separator keyword in Management Studio, but it isn't a real SQL keyword (i.e., SQL Server doesn't recognize it).Remove those from your script -- in the script you've provided, they are irrelevant anyway -- and you should be good to, um, go.
好奇你的变量是否应该与开关相对应。试试这个?
当您在命令中使用上面的行和已知的正确值时会发生什么?
Curious whether your variables should be right up against the switches. Try this?
What happens when you use the line above with your known good values right in the command?