CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    78

    SQL in ACCESS 97

    Hi,

    Does anyone know if the SQL version used in access supports IF or CASE statements? I have seen these in T-SQL.

    Examples in T-SQL:

    SELECT Category = CASE type
    WHEN 'popular_comp' THEN 'Popular Computing'
    WHEN 'mod_cook' THEN 'Modern Cooking'
    WHEN 'business' THEN 'Business'
    WHEN 'psychology' THEN 'Psychology'
    WHEN 'trad_cook' THEN 'Traditional Cooking'
    ELSE 'Not yet categorized'
    END
    FROM titles


    I have tried CASE and IF in ACCESS 97 but it can't figure out the right syntax or any info on the HELP pages.

    Many thanks,

    RF

    p.s. I know is not a VB question, but since VB is used in Access and many use Access... maybe one of you knows



  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: SQL in ACCESS 97

    I am not sure but try something like this

    select (iif([Category] = 'popular_comp','Popular Computing',(iif([Category] = 'mod_cook', 'Modern Cooking','Not yet categorized')))) from Titles

    Check the brackets. I might screw up


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    78

    Re: SQL in ACCESS 97

    I found something that works... ;-)
    Simply, put the criteria on a table and include that table.

    Here it is:

    SELECT C.Name
    FROM titles AS T, criteria AS C
    WHERE T.Category = C.Category

    Table: criteria
    -----------------
    Column: Category Column: Name
    ---------------- --------------------
    popular_comp Popular Computing
    mod_cook Modern Cooking
    business Business
    psychology Psychology
    trad_cook Traditional Cooking

    I think the IIF() is good for 2 options, but anything more than 2 I think this approach is more practical. However, if anyone does know if IF and CASE can be used in Access SQL... please post the syntax... thanks.


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

Featured