Results 1 to 3 of 3

Thread: qry

  1. #1
    Join Date
    Sep 2002
    Posts
    17

    Unanswered: qry

    SELECT A.FIRMNBR
    FROM TA_ALARM_D A, TA_RATE_D B
    WHERE B.PRODUCTID = A.PRODUCTID
    AND B.TRANSTYPE = A.TRANSTYPE
    AND B.RATE || ( SELECT OPERATOR FROM TA_ALARM_D C
    WHERE C.PRODUCTID = A.PRODUCTID
    AND C.TRANSTYPE = A.TRANSTYPE ) || A.RATE ;
    Hi,

    In the above query, in the last condition of 'where clause', I want to pass some relational operators (like '=','<','>' etc.) dynamically from a table column and then parse the main query to get the result records
    from the outer main query.
    How could i achieve this ?
    `
    Thank You.

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: qry

    You cannot do it as you show it, but you could do this:

    SELECT A.FIRMNBR
    FROM TA_ALARM_D A, TA_RATE_D B, TA_ALARM_D C
    WHERE B.PRODUCTID = A.PRODUCTID
    AND B.TRANSTYPE = A.TRANSTYPE
    AND C.PRODUCTID = A.PRODUCTID
    AND C.TRANSTYPE = A.TRANSTYPE
    AND ( ( C.OPERATOR = '=' AND B.RATE = A.RATE )
    OR ( C.OPERATOR = '>' AND B.RATE > A.RATE )
    OR ( C.OPERATOR = '<' AND B.RATE < A.RATE ) -- and so on
    );

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Correction to my previous reply (having now realised that aliases A and C were for the same table!):

    SELECT A.FIRMNBR
    FROM TA_ALARM_D A, TA_RATE_D B
    WHERE B.PRODUCTID = A.PRODUCTID
    AND B.TRANSTYPE = A.TRANSTYPE
    AND ( ( A.OPERATOR = '=' AND B.RATE = A.RATE )
    OR ( A.OPERATOR = '>' AND B.RATE > A.RATE )
    OR ( A.OPERATOR = '<' AND B.RATE < A.RATE )
    );

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •