CASE in a Select Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tena
    New Member
    • Jul 2006
    • 2

    CASE in a Select Problem

    Hi,
    I am getting a syntax error when I run the following, can anyone take a look and provide feedback?

    TIA~

    Tena

    SELECT View_ACTIVE_IQ_ USERS.fo_studen t_id, View_ACTIVE_IQ_ USERS.user_pk1 AS ETUserID, 'Y' AS Active,
    View_ACTIVE_IQ_ USERS.first_nam e,View_ACTIVE_I Q_USERS.address 2,View_ACTIVE_I Q_USERS.address 1,
    Address = CASE View_ACTIVE_IQ_ USERS.address2
    WHEN View_ACTIVE_IQ_ USERS.address2 is not null THEN (View_ACTIVE_IQ _USERS.address1 + ' ' + View_ACTIVE_IQ_ USERS.address2)
    WHEN View_ACTIVE_IQ_ USERS.address2 null THEN View_ACTIVE_IQ_ USERS.address1

    END,
    FROM View_IQ_Guardia n INNER JOIN
    View_ACTIVE_IQ_ USERS ON View_IQ_Guardia n.ETUserID = View_ACTIVE_IQ_ USERS.user_pk1
  • scripto
    New Member
    • Oct 2006
    • 143

    #2
    for starts, remove the comma after END and let's see what happens...

    Comment

    • tena
      New Member
      • Jul 2006
      • 2

      #3
      OK-tried that and still get:


      Msg 156, Level 15, State 1, Line 4
      Incorrect syntax near the keyword 'is'.


      TIA~

      Tena

      Comment

      • sukeshchand
        New Member
        • Jan 2007
        • 88

        #4
        Try this code

        Code:
        SELECT View_ACTIVE_IQ_USERS.fo_student_id, View_ACTIVE_IQ_USERS.user_pk1 AS ETUserID, 'Y' AS Active, 
        View_ACTIVE_IQ_USERS.first_name,View_ACTIVE_IQ_USE RS.address2,View_ACTIVE_IQ_USERS.address1,
        Address = CASE WHEN View_ACTIVE_IQ_USERS.address2 is not null THEN (View_ACTIVE_IQ_USERS.address1 + ' ' + View_ACTIVE_IQ_USERS.address2)
        WHEN View_ACTIVE_IQ_USERS.address2 null THEN View_ACTIVE_IQ_USERS.address1
        END
        FROM View_IQ_Guardian INNER JOIN
        View_ACTIVE_IQ_USERS ON View_IQ_Guardian.ETUserID = View_ACTIVE_IQ_USERS.user_pk1

        Comment

        Working...