USoft Rule Language Examples: Query Statements With Join

Previous Next

In USoft Rule Language, the CONNECTED AS keyword  corresponds to the SQL RELATE keyword. In general, USoft Rule Language-specific keywords only appear in the main query or statement, that is to say, at the beginning of the statement. In contrast, CONNECTED AS can be used anywhere in the USoft Rule Language statement, including in subqueries.

USoft Rule Language

SQL Equivalent

FOR        drivers d
,          contracts c
,          "Business Parties" b
CONNECTED AS      
           b "PAYS FOR" c
DO NOT ALLOW THAT
           b.id = d.id
AND        c.paid = 'N'

SELECT    ''
FROM      driver d
,         contract c
,         business_party b
RELATE    b "PAYS FOR" c
WHERE     b.id = d.id
AND       c.paid = 'N'

In USoft Rule Language, RELATE may not be used immediately following the initial FOR clause. Only CONNECTED AS is allowed here:

USoft Rule Language, ILLEGAL

FOR        drivers d
,          contracts c
,          "business parties" b
RELATE     b "PAYS FOR" c
DO NOT ALLOW THAT
           b.id = d.id
AND        c.paid = 'N'

In USoft Rule Language subqueries, CONNECTED AS and RELATE are both legal:

FOR        drivers d
DO NOT ALLOW THAT EXISTS
(
   SELECT      ''
   FROM        contract c
   ,           business_party b
   CONNECTED AS
               b "PAYS FOR" c
   WHERE       b.id = d.id
   AND         c.paid = 'N'
)

In both USoft Rule Language and SQL, there is the alternative option to express relationships with equality conditions instead of a relationship keyword:

USoft Rule Language

SQL Equivalent

FOR    drivers d
,      contracts c
,      "Business Parties" b
DO NOT ALLOW THAT
       b.contract_code = c.code
AND    b.id = d.id
AND    c.paid = 'N'

SELECT    ''
FROM      driver d
,         contract c
,         business_party b
WHERE     b.contract_code = c.code
AND       b.id = d.id
AND       c.paid = 'N'

 

See Also

USoft Rule Language