field between field1 and field2

Posts   
 
    
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 23-Mar-2005 15:16:21   

Hi

Is it possible to make a query like that : SELECT * FROM MYTABLE WHERE FIELD BETWEEN FIELD1 AND FIELD2 ?

I know how to make a between predicate with values, but I've not see anything about using fields in the between.

Thanks for help!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 23-Mar-2005 16:06:33   

This predicate is planned, but not yet added. In the meantime you can either add it yourself or work around this by using a WHERE field >= field 1 AND field < field2

Frans Bouma | Lead developer LLBLGen Pro
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 24-Mar-2005 10:10:36   

ok thanks I'll try it But I ran into another problem

The SQL I want to generate is something like that :

SELECT T2.* FROM MYTABLE T1, MYTABLE T2 WHERE (T1.LEFT BETWEEN T2.LEFT AND T2.RIGTH) AND (T1.ID = XX)

For the between I'll use > and < it's ok But how to put the same table with alias in the FROM close ?

thanks for your help

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 24-Mar-2005 13:22:11   

By using the Add overload of the RelationCollection (or RelationPredicateBucket.Relations, which is a RelationCollection) where you can specify the aliases. You then also specify these aliasses for the fields in the predicates (for 'objectAlias').

Frans Bouma | Lead developer LLBLGen Pro
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 25-Mar-2005 11:50:22   

I tried to make something but there no field to put on join in my query so how can I do that ?

I've something like that :

 IEntityRelation        relation    = new EntityRelation(RelationType.OneToMany);
            relation.AddEntityFieldPair(EntityFieldFactory.Create(?), EntityFieldFactory.Create(?));
            relation.SetAliases("t1", "t2");

Remember my query :

SELECT T2.*
FROM MYTABLE T1, MYTABLE T2
WHERE
(T1.LEFT BETWEEN T2.LEFT AND T2.RIGTH) AND 
(T1.ID = XX)
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 25-Mar-2005 12:26:46   

Fabrice wrote:

I tried to make something but there no field to put on join in my query so how can I do that ?

I've something like that :

 IEntityRelation        relation    = new EntityRelation(RelationType.OneToMany);
            relation.AddEntityFieldPair(EntityFieldFactory.Create(?), EntityFieldFactory.Create(?));
            relation.SetAliases("t1", "t2");

Remember my query :

SELECT T2.*
FROM MYTABLE T1, MYTABLE T2
WHERE
(T1.LEFT BETWEEN T2.LEFT AND T2.RIGTH) AND 
(T1.ID = XX)

Let me rewrite that using ansi-joins, as you're using SqlServer: SELECT T2.* FROM MyTable T1 INNER JOIN MyTable T2 ON T1.somefield = T2.somefield WHERE (T1.LEFT BETWEEN T2.LEFT AND T2.RIGHT) AND (T1.ID = XX)

is this what you want or do you want this: SELECT T2.* FROM MyTable T1 INNER JOIN MyTable T2 ON (T1.LEFT BETWEEN T2.LEFT AND T2.RIGHT) WHERE (T1.ID = XX)

The first is doable by specifying MyTableFieldIndex.SomeField for the field index at the '?'.

The second isn't doable in 1.0.2004.1, this is only doable in 1.0.2004.2, I've added that feature yesterday by adding a simple flag what to do with the CustomFilter added to an entityrelation object: replace the ON filter or append it to the filter. (this build hasn't been uploaded though)

So as you specified it in non-ansi joins, it was a bit unclear to me what you want, as with non-ansi joins the ON clause is also specified in the where clause, though I suspect you want the second option.

Frans Bouma | Lead developer LLBLGen Pro
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 25-Mar-2005 13:39:12   

Yes I want the second query Ok so I'll use a stored procedure. Thanks for your help.