Results 1 to 11 of 11
  1. #1
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76

    Query Sql IIf Statement return value

    Hi all, I have a query with 5 field, [Country],[Province],[GroupingInfo],[City],[Area]
    I want to write or build a new query to have something on the [City] critiria like:

    IIf [City]="NoInfo" And [GroupingInfo]<=1 Then [City]=[Province], else [City] = [City]

    This is on the Query Sql, not on the VBA Code



    Thanks So Much!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What have you got that isn't working? You practically have it written already.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    I worte this:
    IIf("NoInfo" AND [GroupingInfo]<=1, [City]=[Province]) Or IIf(Not Like "NoInfo", [City]=[City])

    It returns nothing on my query...


  4. #4
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    Never Mind, somehow it worked.....I changed it to IIf("NoInfo" AND [GroupingInfo]<=1, [Province]) Or IIf(Not Like "NoInfo", [City])

    But I do have another question:

    I need the following expression
    IIf "NoInfo" AND [GroupingInfo]>1, I want it return all [city] = [Province] where they share the same [Province] value

    I have trouble to do the Where clause in Sql, Can you tell me how to do that

    Quote Originally Posted by pbaldy View Post
    What have you got that isn't working? You practically have it written already.

  5. #5
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    Oh no! I meet a huge problem here, my query won't change its [city] value to [Province] when it is "Noinfo", I think I maybe need to do the update query, but I do not want to change my original table, Can anyone tell me how to write sql to let [City]change value to [Province] in the query only?


  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, I didn't realize you were trying to use this as a criteria. I've never done that. Your IIf() to simply return values would be:

    IIf([City]="NoInfo" And [GroupingInfo]<=1, [Province], [City])
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    Thanks, but this piece of code will eat all the row that [city]="NoInfo" and return to me a query that only contain the value that [City] does not contain "NoInfo"

    Do you have any idea to solve it?

    Quote Originally Posted by pbaldy View Post
    Sorry, I didn't realize you were trying to use this as a criteria. I've never done that. Your IIf() to simply return values would be:

    IIf([City]="NoInfo" And [GroupingInfo]<=1, [Province], [City])

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, I'm not really clear on what the goal is.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    errr....maybe I'm not clear here, After the query run, I want it return to me the value to replace the value before my query runs.

    I want all the "NoInfo" value in [City] would show me the value in [Province],

    But the sql only return me the value that is not "NoInfo" in [City], won't show any row with "NoInfo" before and now should replace to province

    Ex:
    Before Sql
    [Country][Province] [GroupingInfo] [City] [Area]
    Country1 Province1 1 NoInfo NoInfo
    Country1 Province2 0 NoInfo NoInfo
    Country1 Province1 1 City1 Area3
    Country2 Province3 1 City2 Area4

    I want it give me
    [Country][Province] [GroupingInfo] [City] [Area]
    Country1 Province1 1 Province1 Province1
    Country1 Province2 0 Province2 Province2
    Country1 Province1 1 City1 Area3
    Country2 Province3 1 City2 Area4

    But it only give me the two rows with City1 and City2
    Country1 Province1 1 City1 Area3
    Country2 Province3 1 City2 Area4

    Do you get the problem? Please help me, Thanks

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The formula I gave you would do that. You want it as a field, not a criteria.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    Thank you!!!!
    I got this one right, Could you tell me how to write sql
    IIf "NoInfo" AND [GroupingInfo]>1, I want it return all [city] = [Province] where they share the same [Province] value

    The problem is on how can I write the expr to show the change is on all the [city] value that share same [Province] value, and how to write the where clause on the field expr?

    Again, thank you for your useful tip!

    Quote Originally Posted by pbaldy View Post
    The formula I gave you would do that. You want it as a field, not a criteria.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query to return values
    By narendrabr in forum Queries
    Replies: 3
    Last Post: 01-08-2013, 09:30 AM
  2. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  3. Quick Return Query
    By worldwidewall in forum Access
    Replies: 2
    Last Post: 03-07-2012, 07:04 PM
  4. Replies: 1
    Last Post: 04-15-2010, 02:07 AM
  5. Return all records from Query
    By ysrini in forum Queries
    Replies: 1
    Last Post: 01-15-2010, 09:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums