Subject Re: [firebird-support] Using a query parameter before a sub query
Author Helen Borrie
At 04:16 PM 6/03/2007, you wrote:
>Hi!
>
>Using Firebird 2.0 I'm trying to do this query:
>
>SELECT count(*) as y0_ FROM Department this_ WHERE ? < (SELECT count(*)
>as y0_ FROM Product this_0_ WHERE this_0_.Department = this_.Number)
>
>But it fails when preparing the query with error code 804.
>
>These queries work just fine:
>
>SELECT count(*) as y0_ FROM Department this_ WHERE 0 < (SELECT count(*)
>as y0_ FROM Product this_0_ WHERE this_0_.Department = this_.Number)
>SELECT count(*) as y0_ FROM Department this_ WHERE (SELECT count(*) as
>y0_ FROM Product this_0_ WHERE this_0_.Department = this_.Number) > 0
>
>Is this a bug in Firebird? I tried it with NHibernate/.NETProvider as
>well as Delphi/IBObjects, so this seems not to be a problem of the
>client tools.

Yes and no, but not really. The ? symbol is a replaceable parameter,
not a variable. So a constant in that spot works, whereas a
non-typed unknown "thing" doesn't.

But I'm dead suspicious about what you want from this query. I think
perhaps what you are really after is the following:

SELECT count(*) as y0_ FROM Department this_
where exists (
select 1 from Product this_0_
where this_0_.Department = this_.Number)

./heLen