我是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"
我想从错误和我的实验中我基本上不得不以某种方式将它放入存储过程中。有没有办法在保持代码不在数据库的同时做到这一点?
答案 0 :(得分:1)
您的代码可以简化为单个查询:
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用于转义异常字符,我在示例中没有看到这些字符。