Results 1 to 7 of 7
  1. #1
    masond is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    12

    writing a basic case statement for DoCmd.RunSQL

    HI All



    I need some help writing a DoCmd.RunSQL

    Aim > Create a column Called “Channel” by using the following logic below. The data is coming from a file called “test”
    If [sub-Source] Is Null Then [how did you hear of us] Else [sub-Source]

    Looking forward to your help

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Have you tried Google or Bing
    Ms Access docmd.runsql sample

  3. #3
    masond is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    12
    Hi Orange
    i been browsing all weekend and i am super confused
    I can do a basic, case statement but thats all

  4. #4
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    As this is an Access forum, and you post yourself as a novice - then I think the best advice is to develop your code using the Query Design View - rather than attempting building with a manual sql statement. You can then change the design view to sql view in order to get the syntax.

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I agree with NTC -- if you use query designer, then review the sql you will see code that works.

    What exactly do you mean by a case statement?

    See Select Case

  6. #6
    masond is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    12
    HI guys

    Thanks for the tip

    So far this is my if formula

    IIf([Sub-Source] Is Null,[Sub-Source],[How did you hear of us]) AS Channel,


    iIf([Channel] in ('Internet PPC','Offer-1for3month-Jan13', 'Offer-1for3month-Jan13', 'Offer-Switch-Jan13','Phone-Offer-1for3month-Jan13','Phone-PPC-Brand','Phone-PPC-Machines', 'Phone-PPC-Merchant','Phone-PPC-ProcPayments','Phone-PPC-Terminals','Post visit BingYahoo PPC', 'Post visit Google PPC','Post visit Referrer Referred', 'PPC-Brand','PPC-CreditCard','PPC-DCC','PPC-Ecommerce', 'PPC-Machines', 'PPC-Merchant','PPC-ProcPayments', 'PPC-Terminals', 'Switcher Cashback', 'PPC-remarketing'), "PPC",

    IIf([Channel] in('At Work','ClientLine - Freefor3months','£1MonthFor3','ConnectX-Online','Connectx-Print','Email','Google/Yahoo','HDC','Internet FDMS Website (SE0)','Internet Search Engine','Live Chat','New Customer','Partner Referral','Phone-Direct', 'Phone-Offer-RetraFd', 'Recommendation/Referral','Refer a Friend','RetraFd','SEO-1Monthsfor3','SEO-Switcher-Cashback', 'Phone-SEO'), "SE0", "Check")) AS [testing],


    In the final if statement i need to say

    If Callid>1 then update column Testing with “PPC” other wise stick with the value in “Testing”

    Any ideas, how i can add the last if condition on ?

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Can you tell us in plain English -- no vba , no SQL --WHAT exactly are you trying to do?

    You might find syntax and samples of functions at:
    http://www.techonthenet.com/access/f...vanced/iif.php
    http://www.techonthenet.com/access/f...ced/isnull.php

    http://www.w3schools.com/sql/sql_in.asp

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

Similar Threads

  1. DoCmd.RunSQL
    By Access_Blaster in forum Programming
    Replies: 6
    Last Post: 07-23-2013, 09:27 PM
  2. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  3. Replies: 2
    Last Post: 10-13-2011, 09:14 AM
  4. problem with my DoCmd.RunSQL statement
    By cgclower in forum Access
    Replies: 1
    Last Post: 07-24-2011, 06:12 PM
  5. my first DoCmd.RunSQL
    By broecher in forum Programming
    Replies: 4
    Last Post: 11-05-2010, 09:35 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