This topic is locked

Simple SQL where query issues

12/5/2006 8:07:35 PM
PHPRunner General questions
M
matt.cohen author

I am running PHPRunner 3.1 and publishing the built pages on XP profession using PHP5 and Apache server.
I can not seem to figure the correct syntax for the following statement.
From [Service Records]

Where ((AccountingOptions<>'INVOICED' or AccountingOptions<>'N/A') and Progress='COMP')
I can successfully get a single condition as in " Where AccountingOptions<>'INVOICED' " but more than one condition seems to not work as expected.
Any clues would be greatly appreciated.

Alexey admin 12/6/2006

Matt,
just explain which records you want to display and which not.

I'll help you to construct a proper WHERE clause.

M
matt.cohen author 12/6/2006

Hi,
I am trying to display the records that have "COMP' in the "Progress" column and that do have "N/A" or "INVOICED" in the "AccountingOptions" column.
So all the services records that are complete and have not been already invoiced or are not deemed applicable.
Thanks in advance
Matt

L
larsonsc 12/7/2006

I am running PHPRunner 3.1 and publishing the built pages on XP profession using PHP5 and Apache server.

I can not seem to figure the correct syntax for the following statement.
From [Service Records]

Where ((AccountingOptions<>'INVOICED' or AccountingOptions<>'N/A') and Progress='COMP')
I can successfully get a single condition as in " Where AccountingOptions<>'INVOICED' " but more than one condition seems to not work as expected.
Any clues would be greatly appreciated.


I don't think you need to have the second AccountingOptions in your WHERE clause. Maybe you do though since I'm not sure what DBMS you are using (I don't recognize the syntax), but in MySQL I have not had to add the column name in the second time if I am making two comparisons to the same column.
Try it like this and see if you have any luck with it:

From [Service Records]

Where ((AccountingOptions<>'INVOICED' or 'N/A') and Progress='COMP')
J
Jane 12/7/2006

Matt,
here is the correct where clause:

From [Service Records]

Where ((AccountingOptions<>'INVOICED' and AccountingOptions<>'N/A') and Progress='COMP')

M
matt.cohen author 12/7/2006

Hi Jane,
Still no good with your solution.
The sample database has 80 records in it.

If I use "Where (Progress ='COMP' and AccountingOptions<> 'N/A') i get 30 records returned.

If I use "Where (Progress ='COMP' and AccountingOptions<> 'INVOICED') I get 38 records returned.

If I use "Where ((AccountingOptions<> 'COMP' and AccountingOptions<> 'INVOICED') and Progress='COMP') I get 0 Records returned ????
Any other ideas
Thanks in Advance
Cheers

J
Jane 12/7/2006

Matt,
sorry for my fault.

Here is a correct query:

Where (Progress ='COMP' and AccountingOptions<> 'N/A') or (Progress ='COMP' and AccountingOptions<> 'INVOICED')
M
matt.cohen author 12/8/2006

Matt,

sorry for my fault.

Here is a correct query:

Where (Progress ='COMP' and AccountingOptions<> 'N/A') or (Progress ='COMP' and AccountingOptions<> 'INVOICED')


Jane,
This seems to be a little tricky as it's still doesn't work. This sould be a little easier than this.
The new update is the where query that you supplied me, which I had already tried gives me exact the opposite of what I need.

It is as if it is mistaking the <> as an =.

The new query gives me 68 records. The the sum of the two queries I posted earlier.
Bugger

J
jim9 12/8/2006

If you develop on a local machine, with mysql, you could download and install sqlyog, there's a free version. Then using sqlyog you could pratice til the query is correct. Sqlyog doesn't work with parameters, but you could input the real data for testing, I.E., 5 instead of a variable.

This has helped me with my queries.

Also, try a space before <>.

Alexey admin 12/11/2006

Matt,

I am trying to display the records that have "COMP' in the "Progress" column and that do have "N/A" or "INVOICED" in the "AccountingOptions" column.

Here is the WHERE clause that satisfies your requirements.

where Progress='COMP' and (AccountingOptions='N/A' or AccountingOptions='INVOICED')