Connecting Tech Pros Worldwide Forums | Help | Site Map

Receiving Syntax Error using "OR" command

Newbie
 
Join Date: Feb 2008
Posts: 29
#1: Oct 4 '08
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:
Expand|Select|Wrap|Line Numbers
  1. SELECT T_Physicians.TaxID, T_ECCcpt.CPTcode, T_ECCcpt.Charge, *
  2. FROM T_Physicians, T_ECCcpt
  3. WHERE (((T_Physicians.TaxID)="58-229xxxx"))
  4. OR
  5. SELECT T_Physicians.TaxID, T_SibleyCpt.CPTcode, T_SibleyCpt.Charge, *
  6. FROM T_Physicians, T_SibleyCpt
  7. WHERE
  8. T_Physicians.TaxID = 58-187xxxx;
  9.  
Adigga1

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#2: Oct 4 '08

re: Receiving Syntax Error using "OR" command


Adigga1.

Please use [code] tags when posting your code examples.

Like:
[code] ...Code goes here... [/code]

Or better yet:
[code=sql] ...SQL goes here... [/code]

Thank you.
MODERATOR
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#3: Oct 4 '08

re: Receiving Syntax Error using "OR" command


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

It is supposed to be used in a boolean statement, for example:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tbl
  2. WHERE id = 1 OR id = 2
  3.  
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.
Newbie
 
Join Date: Feb 2008
Posts: 29
#4: Oct 4 '08

re: Receiving Syntax Error using "OR" command


Quote:

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:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tbl
  2. WHERE id = 1 OR id = 2
  3.  
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.
Needs Regular Fix
 
Join Date: Mar 2008
Posts: 311
#5: Oct 4 '08

re: Receiving Syntax Error using "OR" command


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):

Expand|Select|Wrap|Line Numbers
  1. SELECT T1.TaxID, 
  2. IF (T1.ECC='yes',T2.CPTcode,T3.CPTcode) as CPTcode,
  3. IF (T1.ECC='yes',T2.Charge,T3.Charge) as Charge
  4. FROM T_Physicians T1, T_ECCcpt T2, T_SibleyCpt T3 
  5. WHERE (missing join conditions here)  
  6. AND (((T1.TaxID)="58-229xxxx")) 
  7.  
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 :) )
Newbie
 
Join Date: Feb 2008
Posts: 29
#6: Oct 4 '08

re: Receiving Syntax Error using "OR" command


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
Needs Regular Fix
 
Join Date: Mar 2008
Posts: 311
#7: Oct 5 '08

re: Receiving Syntax Error using "OR" command


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.
Reply