FLAG

  • SELECT TOP 1000 [SubjectID]

    ,[Phase_ID]

    FROM [dbo].[TEST]

    SubjectIDPhase_ID

    1 2

    2 3

    2 2

    3 3

    4 3

    5 2

    6 2

    7 3

    7 2

    I would like to add one more column that shows if Subject Change their phase from 3 to 2 , I need to display yes.

    Can you help me ?

    Thanks

  • There's no way to know if it changed from 3 to 2 or from 2 to 3. There's no way to define the order in that table.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I need to change always 3 to 2.

  • patla4u (6/9/2016)


    SELECT TOP 1000 [SubjectID]

    ,[Phase_ID]

    FROM [dbo].[TEST]

    SubjectIDPhase_ID

    1 2

    2 3

    2 2

    3 3

    4 3

    5 2

    6 2

    7 3

    7 2

    I would like to add one more column that shows if Subject Change their phase from 3 to 2 , I need to display yes.

    Can you help me ?

    Thanks

    Update trigger on the source table to write change history would do the trick.

  • I didn't get it.

  • Manic Star (6/9/2016)


    patla4u (6/9/2016)


    SELECT TOP 1000 [SubjectID]

    ,[Phase_ID]

    FROM [dbo].[TEST]

    SubjectIDPhase_ID

    1 2

    2 3

    2 2

    3 3

    4 3

    5 2

    6 2

    7 3

    7 2

    I would like to add one more column that shows if Subject Change their phase from 3 to 2 , I need to display yes.

    Can you help me ?

    Thanks

    Update trigger on the source table to write change history would do the trick.

    But not for existing rows.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • patla4u (6/9/2016)


    I didn't get it.

    which change is presented by these 2 rows:

    23

    22

    3 --> 2 or 2 --> 3?

    _____________
    Code for TallyGenerator

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply