将 SQL Server 查询转换为 Firebird 时遇到问题

发布于 2024-09-19 22:45:39 字数 468 浏览 2 评论 0原文

我是 Firebird 的新手,并且在将此 T-SQL 转换为 Firebird SQL 时遇到特别困难。此代码存储在数据库外部,而不是存储过程中。

DECLARE @NumTotal int
DECLARE @NumUsed int

SELECT @NumTotal = COUNT(*)
    FROM "some_Table"
    WHERE "CreatedOn"=@CreatedOn

SELECT @NumUsed = COUNT(*)
    FROM "some_Table"
    WHERE "CreatedOn"=@CreatedOn AND "UserID" IS NOT NULL

SELECT @NumUsed AS "NumUsed", @NumTotal AS "NumTotal"

我从错误和我的实验中猜想,我基本上被迫以某种方式将其放入存储过程中。有没有办法可以做到这一点,同时仍将代码保留在数据库之外?

I'm new to Firebird, and I'm having particular difficulty translating this T-SQL to Firebird SQL. This code is stored outside of the database, not in a stored procedure.

DECLARE @NumTotal int
DECLARE @NumUsed int

SELECT @NumTotal = COUNT(*)
    FROM "some_Table"
    WHERE "CreatedOn"=@CreatedOn

SELECT @NumUsed = COUNT(*)
    FROM "some_Table"
    WHERE "CreatedOn"=@CreatedOn AND "UserID" IS NOT NULL

SELECT @NumUsed AS "NumUsed", @NumTotal AS "NumTotal"

I guess from the errors and my experimentation that I'm basically forced to put this into a stored procedure somehow. Is there a way I can do this while still keeping the code out of the database?

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

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

发布评论

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

评论(1

嘦怹 2024-09-26 22:45:39

您的代码可以简化为单个查询:

SELECT COUNT(*) AS numTotal,
       (SELECT COUNT(*)
          FROM YOUR_TABLE
         WHERE userid IS NOT NULL
           AND createdon = @createdon) AS numUsed
  FROM YOUR_TABLE
 WHERE createdon = @createdon

使用双引号是 ANSI 转义异常字符的方法,我在示例中没有看到这些字符。

Your code can be simplified to a single query:

SELECT COUNT(*) AS numTotal,
       (SELECT COUNT(*)
          FROM YOUR_TABLE
         WHERE userid IS NOT NULL
           AND createdon = @createdon) AS numUsed
  FROM YOUR_TABLE
 WHERE createdon = @createdon

Using double quotes is ANSI for escaping unusual characters, none of which I see in the example.

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