Delphi 与 SQL Server 之间的冲突

发布于 2024-12-08 10:22:49 字数 1025 浏览 5 评论 0原文

我有一个在 SQL Server 中也可以工作的查询,但是当我将它保存在 delphi 中的 ado 查询中时,它不起作用并因此错误而停止:

Incorrect syntax near 'GO'

但是下面的代码是正确的并且没有任何错误。我在sql server 中测试了它。 下面的代码不是常规的,因为我从 delphi 复制并粘贴了它。

我的查询:

create function GetTedad(@pfcode INT, @pdcode INT) returns int
as begin declare @Tedad int;
select @Tedad= sum(t2.tedade_avalie) from Tbl_avalie_salon t2 where t2.FCode = @pfcode and t2.DCode = @pdcode
return (@Tedad); end;
GO
create function getSumBSen2(@pfcode INT, @pdcode INT, @pSen INT) returns int
as begin declare @r int;
select @r= sum(t2.t_shab + t2.t_rooz) from tbl_talafat_dan t2 where t2.FCode = @pfcode and t2.DCode = @pdcode and t2.sen <= @pSen;
return (@r); end;
GO
select t1.sen, sum(t1.d_rooz) as d1, sum(t1.d_shab) as d2, sum(t1.d_rooz + t1.d_shab) as d_sum,
Round((sum((1000*(t1.d_rooz+t1.d_shab)+0.01)/((dbo.GetTedad(81, 1))-(dbo.getSumBSen2(81, 1, t1.sen))))),1) as Saraneh
from tbl_talafat_dan t1 where t1.FCode =81 and t1.DCode = 1 group by t1.sen;

I have a Query that works in SQL Server as well but when i save it in ado query in delphi it doesn't work and stops with this error :

Incorrect syntax near 'GO'

But the below code is correct and has not any error . i was tested it in sql server .
The below code is not Regular because i copy and past it from delphi .

My Query :

create function GetTedad(@pfcode INT, @pdcode INT) returns int
as begin declare @Tedad int;
select @Tedad= sum(t2.tedade_avalie) from Tbl_avalie_salon t2 where t2.FCode = @pfcode and t2.DCode = @pdcode
return (@Tedad); end;
GO
create function getSumBSen2(@pfcode INT, @pdcode INT, @pSen INT) returns int
as begin declare @r int;
select @r= sum(t2.t_shab + t2.t_rooz) from tbl_talafat_dan t2 where t2.FCode = @pfcode and t2.DCode = @pdcode and t2.sen <= @pSen;
return (@r); end;
GO
select t1.sen, sum(t1.d_rooz) as d1, sum(t1.d_shab) as d2, sum(t1.d_rooz + t1.d_shab) as d_sum,
Round((sum((1000*(t1.d_rooz+t1.d_shab)+0.01)/((dbo.GetTedad(81, 1))-(dbo.getSumBSen2(81, 1, t1.sen))))),1) as Saraneh
from tbl_talafat_dan t1 where t1.FCode =81 and t1.DCode = 1 group by t1.sen;

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

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

发布评论

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

评论(3

起风了 2024-12-15 10:22:49

GO 关键字不是 SQL服务器声明

GO 不是 Transact-SQL 语句;这是一个被识别的命令
sqlcmd 和 osql 实用程序以及 SQL Server Management Studio 代码
编辑器。

您必须从 Delphi 代码中删除此语句才能执行您的 Sql 语句。检查此问题的示例 如何运行数据库来自 Delphi 的脚本文件?

The GO keyword is not a SQL Server statement

GO is not a Transact-SQL statement; it is a command recognized by the
sqlcmd and osql utilities and SQL Server Management Studio Code
editor.

You must remove this statement from your Delphi Code in order to execute your Sql sentence. check this question for an example How to run a database script file from Delphi?

梦冥 2024-12-15 10:22:49

您不能在 Delphi 查询中执行多个语句。
将每个块放在其自己的查询中的每个 go 之前,并按顺序运行它们。

那么它应该可以工作。
不要将 go 语句放入 Delphi 查询中,它会隐式执行 go 操作。

You cannot do multiple statements in a Delphi query.
Put each block before each go in its own query and run them in sequence.

Then it should work.
Do not put the go statement in the Delphi query, it does go implicitly.

云归处 2024-12-15 10:22:49

您正在执行的是一个脚本,其中每个单独的语句都用 GO 语句分隔。

  • SSMS 知道如何解释这些语句并一次执行它们。
  • ADO 不知道如何解释这些语句。

您可以

  • 自己解析该语句并使用 TADOQuery 执行每个单独的语句。
  • 将每个语句放入其自己的 TADOQuery 对象中。

来自 GO(Transact-SQL)

GO 不是 Transact-SQL 语句;这是一个被识别的命令
sqlcmd 和 osql 实用程序以及 SQL Server Management Studio 代码
编辑器。

SQL Server 实用程序将 GO 解释为它们应该发送的信号
SQL 实例的当前一批 Transact-SQL 语句
服务器。当前批次的语句由所有语句组成
自上次 GO 以来输入,或自临时会话开始以来输入,或
如果这是第一个 GO,则编写脚本。

What you are executing is a script where each individual statement is separated with a GOstatement.

  • SSMS knows how to interprete these statements and execute them one at the time.
  • ADO does not know how to interprete these statements.

You could either

  • parse the statement yourself and execute each individual statement with a TADOQuery.
  • place each statement in a TADOQuery object of its own.

From GO(Transact-SQL)

GO is not a Transact-SQL statement; it is a command recognized by the
sqlcmd and osql utilities and SQL Server Management Studio Code
editor.

SQL Server utilities interpret GO as a signal that they should send
the current batch of Transact-SQL statements to an instance of SQL
Server. The current batch of statements is composed of all statements
entered since the last GO, or since the start of the ad hoc session or
script if this is the first GO.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文