문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top