Subject Re: [firebird-support] Using a query parameter before a sub query
Author Tobias Grimm
Helen Borrie schrieb:

> >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.
> >Is this a bug in Firebird?

> 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.


I really think, it should work. It's a valid expression, it works with a
constant on the left or the right side, it works with a parameter on the
right side and therefore it should also work with a parameter on the
left side of the subquery.


> But I'm dead suspicious about what you want from this query.


It's simply querying the number of departments that contain products.


> 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)


I'm working with FbEmbedded wnd NHibernate as ORM mapper, so this isn't
an option. The above query is generated by NHibernate Criterea Queries.
I can workaround the problem by using a HQL query, so this is currently
not a big show stopper. Maybe I should add an issue to the tracker.

Tobias