Receiving Syntax Error using "OR" command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adigga1
    New Member
    • Feb 2008
    • 29

    Receiving Syntax Error using "OR" command

    Hello,

    I am attempting to call a particular table if the OR statement is used. When I try it gives me a Syntax error. Please assist?

    Here is the code:
    [code=sql]
    SELECT T_Physicians.Ta xID, T_ECCcpt.CPTcod e, T_ECCcpt.Charge , *
    FROM T_Physicians, T_ECCcpt
    WHERE (((T_Physicians .TaxID)="58-229xxxx"))
    OR
    SELECT T_Physicians.Ta xID, T_SibleyCpt.CPT code, T_SibleyCpt.Cha rge, *
    FROM T_Physicians, T_SibleyCpt
    WHERE
    T_Physicians.Ta xID = 58-187xxxx;
    [/code]

    Adigga1
    Last edited by Atli; Oct 4 '08, 01:00 AM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Adigga1.

    Please use [code&#9 3; tags when posting your code examples.

    Like:
    [code&#9 3; ...Code goes here... [/code]

    Or better yet:
    [code=sql&# 93; ...SQL goes here... [/code]

    Thank you.
    MODERATOR

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      That is not how the OR statement is mean to be used.

      It is supposed to be used in a boolean statement, for example:
      [code=mysql]
      SELECT * FROM tbl
      WHERE id = 1 OR id = 2
      [/code]

      What you are attempting might require a stored procedure or some external API code.
      It might be accomplished by a well designed JOIN, but I would need to know more about your data to be able to help figure that out.

      Comment

      • adigga1
        New Member
        • Feb 2008
        • 29

        #4
        Originally posted by Atli
        That is not how the OR statement is mean to be used.

        It is supposed to be used in a boolean statement, for example:
        [code=mysql]
        SELECT * FROM tbl
        WHERE id = 1 OR id = 2
        [/code]

        What you are attempting might require a stored procedure or some external API code.
        It might be accomplished by a well designed JOIN, but I would need to know more about your data to be able to help figure that out.

        thank you and I apologize for the incorrect formatting;

        What I'm attempting to establish is a condition i suppose whereby, when a particular TaxID is selected that represents ECC the corresponding ECC CPT table is referenced where i have to option to select the CPT code and price from that table.

        I have all of the Physicians and TaxID; CPT and Prices loaded in their respective tables and fields.

        I am seeking the correct coding to use in order to accomplish this. I am pretty new to coding so please be patient with me?

        Thank you.

        Comment

        • coolsti
          Contributor
          • Mar 2008
          • 310

          #5
          I do not know what your * in your select query is referring to, so I cannot give you a complete answer to this. I do not know if the way I am about to suggest is the most efficient way to handle this.

          But assuming you do not have the * in the select query (you do not want any more fields) then the following may be a start of what you are looking for (but will not work as it is):

          [CODE=sql]
          SELECT T1.TaxID,
          IF (T1.ECC='yes',T 2.CPTcode,T3.CP Tcode) as CPTcode,
          IF (T1.ECC='yes',T 2.Charge,T3.Cha rge) as Charge
          FROM T_Physicians T1, T_ECCcpt T2, T_SibleyCpt T3
          WHERE (missing join conditions here)
          AND (((T1.TaxID)="5 8-229xxxx"))
          [/CODE]

          Here I do not know what the actual name of the attribute is in your main table for this ECC flag, nor do I know what values it can have. In the above example, I call it ECC, and I assume it has the value of 'yes' or 'no'. You can make changes to the above to fit your situation.

          Also notice that I introduce here the aliases T1, T2 and T3 to make life simpler.

          What is obviously missing here are missing join conditions for the three tables, and whether this strategy will work or not will depend on what the relationship is between the three tables involved (one to one, one to many, etc.).

          What I do want to point out here in case it helps, is the use of an IF clause. Maybe a CASE clause would be more appropriate (in all my MySQL usage I have not ever used a CASE clause yet :) )

          Comment

          • adigga1
            New Member
            • Feb 2008
            • 29

            #6
            Thank you very much coolsti ,

            As a novice to this art, I appreciate the level of descriptive detail and time allocated to my challenge.

            I will utilize and test this technique and post the results.

            Again, thank you for your patience.

            Adigga1

            Comment

            • coolsti
              Contributor
              • Mar 2008
              • 310

              #7
              Glad to help where I can. I am not expert in all things and I assume (and welcome) others will jump in and correct me when I am wrong.

              I don't always have the time for it but I feel a good explanation helps more than a short response giving only a solution.

              Comment

              Working...