Results 1 to 4 of 4

Thread: SELECT CASE with MS Access ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    369

    SELECT CASE with MS Access ?

    Hi,

    Is is possible to use the Select case in MS Access ?

    If yes, what is wrong with this query.

    Code:
    SELECT NOPLAINTE, NOPOCKET, 
    CASE PLAIDOYER 
    WHEN 'Coupable' THEN '1'
    WHEN 'Non coupable' THEN '2'
    WHEN 'Bénéfice du doute' THEN '3'
    END
    FROM PLAINTES 
    ORDER BY NOPLAINTE

    Thanks.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: SELECT CASE with MS Access ?

    Jet Engine does not support Case When...

    Use the IIF statement.

  3. #3
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: SELECT CASE with MS Access ?

    dbelly office:

    The syntax of the Select Case statement is:

    Select Case Expression
    Case Expression1
    Statement1
    Case Expression2
    Statement2
    Case Expression_n
    Statement_n
    End Select


    Private Sub cboMembership_AfterUpdate()
    Dim strMembership As String

    strMembership = [cboMembership]

    Select Case strMembership
    Case "Teen"
    txtPrice = "$25"
    Case "Adult"
    txtPrice = "$50"
    Case "Senior"
    txtPrice = "$35"
    End Select
    End Sub


    If you anticipate that there could be no match between the Expression and one of the Expressionn, you can use a Case Else statement at the end of the list. The statement would then look like this:

    Select Case Expression
    Case Expression1
    Statement1
    Case Expression2
    Statement2
    Case Expression3
    Statement3
    Case Else
    Statement_n
    End Select

  4. #4
    Hyperactive Member
    Join Date
    May 2005
    Posts
    324

    Re: SELECT CASE with MS Access ?

    To expand on #2, use
    SELECT NOPLAINTE, NOPOCKET,
    iif(PLAIDOYER = 'COUPABLE', 1 , IIF(PLAIDOYER = 'Non coupable' ,2 ,3)) AS PLAIDOYER
    FROM PLAINTES
    ORDER BY NOPLAINTE

Posting Permissions

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



Click Here to Expand Forum to Full Width