Syntax in statement please Help !

  • Hallo everybody,

    i have an syntax error in this Statement.

    Server: Msg 156, Level 15, State 1, Line 40

    Incorrect syntax near the keyword 'else'.

    Plaese Help.

    SELECT distinct t1.personalnummer,t1.agentname,t1.eintrittsdatum,

    t1.datum,t1.code,

    case t1.start_moment

    when ((SELECT min(t3.stop_moment)

    FROM svtemp T3

    WHERE (t3.personalnummer=t1.personalnummer)

    AND t3.start_moment =t1.start_moment) )

    then (SELECT min(t3.stop_moment)

    FROM svtemp T3

    WHERE (t3.personalnummer=t1.personalnummer)

    AND t3.start_moment =t1.start_moment)

    when ((SELECT min(t3.start_moment)

    FROM svtemp T3

    WHERE (t3.personalnummer=t1.personalnummer)

    AND t3.start_moment =t1.stop_moment) )

    then (SELECT min(t3.start_moment)

    FROM svtemp T3

    WHERE (t3.personalnummer=t1.personalnummer)

    AND t3.start_moment =t1.stop_moment)

    else t1.start_moment

    end as start_moment,

    case t1.stop_moment

    when ((SELECT min(t3.start_moment)

    FROM svtemp T3

    WHERE (t3.personalnummer=t1.personalnummer)

    AND t3.stop_moment =t1.stop_moment) )

    then (SELECT min(t3.start_moment)

    FROM svtemp T3

    WHERE (t3.personalnummer=t1.personalnummer)

    AND t3.stop_moment =t1.stop_moment)

    when ((SELECT max(t3.stop_moment)

    FROM svtemp T3

    WHERE (t3.personalnummer=t1.personalnummer)

    AND t3.start_moment =t1.stop_moment) )

    then ((SELECT max(t3.stop_moment)

    FROM svtemp T3

    WHERE (t3.personalnummer=t1.personalnummer)

    AND t3.start_moment =t1.stop_moment)

    else t1.stop_moment

    end as stop_moment,

    t1.groupid

    FROM svtemp T1 JOIN svtemp T2 ON (t1.personalnummer=t2.personalnummer)

    group by t1.personalnummer,t1.agentname,t1.eintrittsdatum,

    t1.datum,t1.code,t1.groupid,T1.START_MOMENT,T1.STop_MOMENT

    regards

    Thomas

  • Thanks,

    i ve found it 🙂

    It was an (( in the last then

    Thomas

  • Cool... thanks for posting back to save us time.

    --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)

Viewing 3 posts - 1 through 2 (of 2 total)

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