Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Applying a rule through querys?

Discussion in 'Information Technology' started by Stefan, Jul 28, 2006.

  1. Stefan

    Stefan
    Expand Collapse
    Guest

    Hi,

    I've got a list with people who would be buying a house.

    The people who lives in the same town off the project gets a priority-rule.

    The rule is that these people can shift 50% forwards but the other ones can
    move backward only ones.

    Example:

    Nr Name Priority
    1 Pers1 yes
    2 Pers2 no
    3 Pers3 no
    4 Pers4 yes
    5 Pers5 yes


    After applying the rule:

    Nr Name Priority
    1 1 Pers1 yes
    2 4 Pers4 yes
    3 2 Pers2 no
    4 5 Pers5 yes
    5 3 Pers3 no

    Who can help me with this.
    --
    Stefan
     
  2. Loading...

    Similar Threads Forum Date
    Sikhism Brahmanical Way of Applying Gurbani Book Reviews & Editorials Jun 2, 2010
    Extract: The untold history of Sikh Rule under Ranjit Singh Ji in Lahore Sikh Personalities May 28, 2014
    Canada FIFA Rules in Favor of Religious Headgear Breaking News Mar 2, 2014
    USA Pentagon to relax rules on personal religious wear — including beards, turbans Breaking News Jan 23, 2014
    Sikh Coalition Sikh American Organizations Stand with Gurbaksh Singh on 36th Day of His Hunger Strike; Demand Rule Sikh Organisations Dec 21, 2013

  3. Jamie Collins

    Jamie Collins
    Expand Collapse
    Guest

    Stefan wrote:
    > I've got a list with people who would be buying a house.
    >
    > The people who lives in the same town off the project gets a priority-rule.
    >
    > The rule is that these people can shift 50% forwards but the other ones can
    > move backward only ones.
    >
    > Example:
    >
    > Nr Name Priority
    > 1 Pers1 yes
    > 2 Pers2 no
    > 3 Pers3 no
    > 4 Pers4 yes
    > 5 Pers5 yes
    >
    >
    > After applying the rule:
    >
    > Nr Name Priority
    > 1 1 Pers1 yes
    > 2 4 Pers4 yes
    > 3 2 Pers2 no
    > 4 5 Pers5 yes
    > 5 3 Pers3 no


    A quick stab (the really small DECIMAL value is to break ties in favour
    of Priority = 'Y'):

    SELECT H1.Nr, H1.Name, H1.Priority,
    IIF(H1.Priority = 'Y',
    H1.Nr * 0.5,
    H1.Nr + 0.00000000000000000001) AS new_rank
    FROM Housing AS H1;

    To get the new Nr i.e. an INTEGER rank rather than a DECIMAL, just plug
    the resultset back in (oh for CTE's in Jet <g>):

    SELECT DT1.Nr, DT1.Name, DT1.Priority,
    (
    SELECT COUNT(*)
    FROM
    (
    SELECT H1.Nr, H1.Name, H1.Priority,
    IIF(H1.Priority = 'Y',
    H1.Nr * 0.5,
    H1.Nr + 0.00000000000000000001) AS new_rank
    FROM Housing AS H1
    ) AS DT2
    WHERE DT2.new_rank <= DT1.new_rank
    ) AS new_Nr
    FROM
    (
    SELECT H1.Nr, H1.Name, H1.Priority,
    IIF(H1.Priority = 'Y',
    H1.Nr * 0.5,
    H1.Nr + 0.00000000000000000001) AS new_rank
    FROM Housing AS H1
    ) AS DT1;

    Jamie.

    --
     
  4. Stefan

    Stefan
    Expand Collapse
    Guest

    >
    > Stefan wrote:
    > > I've got a list with people who would be buying a house.
    > >
    > > The people who lives in the same town off the project gets a priority-rule.
    > >
    > > The rule is that these people can shift 50% forwards but the other ones can
    > > move backward only ones.
    > >
    > > Example:
    > >
    > > Nr Name Priority
    > > 1 Pers1 yes
    > > 2 Pers2 no
    > > 3 Pers3 no
    > > 4 Pers4 yes
    > > 5 Pers5 yes
    > >
    > >
    > > After applying the rule:
    > >
    > > Nr Name Priority
    > > 1 1 Pers1 yes
    > > 2 4 Pers4 yes
    > > 3 2 Pers2 no
    > > 4 5 Pers5 yes
    > > 5 3 Pers3 no

    >
    > A quick stab (the really small DECIMAL value is to break ties in favour
    > of Priority = 'Y'):
    >
    > SELECT H1.Nr, H1.Name, H1.Priority,
    > IIF(H1.Priority = 'Y',
    > H1.Nr * 0.5,
    > H1.Nr + 0.00000000000000000001) AS new_rank
    > FROM Housing AS H1;
    >


    Thanks,

    This code works fine.
    Monday i can compare this result with the manual result of my boss. On a
    first glimp it looks great.


    --
    Stefan
     

Share This Page