If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > SELECT AS clause errors

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-01-04, 08:35
83urq 83urq is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
SELECT AS clause errors

Hello. I am trying to use a search table in this AS400. It basically contains keywords, and corresponding filenumbers that the rest of the information can be pulled from other tables with. There are multiple keywords for single files, hence the GROUPing.

But my problem is using the AS clause, i get this error:

Warning: odbc_exec(): SQL error: [IBM][Client Access Express ODBC Driver (32-bit)][DB2/400 SQL]SQL0206 - Column COUNT not in specified tables., SQL state S0022

Here is the SQL:

SELECT SRCHWORD, SRCHFILNBR, COUNT(SRCHFILNBR) AS COUNT
FROM CISDTA.RSRCH
WHERE (SRCHWORD >= '$keywd1' AND SRCHWORD <= 'keywd12')
OR (SRCHWORD >= '$keywd2' AND SRCHWORD <= '$keywd22')
AND COUNT = $keywords
GROUP BY SRCHFILNBR, SRCHWORD, COUNT ORDER BY SRCHFILNBR

In this case, $keywords would be 2, because the AS400 will return all filenumbers where only one keyword matches, and this will filter them out.
Reply With Quote
  #2 (permalink)  
Old 06-01-04, 08:45
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
i would try using something other than a reserved word like COUNT as the alias

also, any tests on an aggregate function must be done in the HAVING clause, not the WHERE clause
Code:
select SRCHWORD
     , SRCHFILNBR
     , count(SRCHFILNBR) as flooble
  from CISDTA.RSRCH
 where SRCHWORD between '$keywd1' and 'keywd12'
    or SRCHWORD between '$keywd2' and '$keywd22'
group 
    by SRCHWORD
     , SRCHFILNBR
having count(SRCHFILNBR) = $keywords      
order 
    by SRCHFILNBR
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Last edited by r937; 06-01-04 at 08:49.
Reply With Quote
  #3 (permalink)  
Old 06-01-04, 08:47
83urq 83urq is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
Quote:
Originally Posted by r937
i would try using something other than a reserved word like COUNT as the alias
Ive tried many words
Reply With Quote
  #4 (permalink)  
Old 06-01-04, 08:51
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
try query i put into previous post

i guess i was editing it while you answered
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 06-01-04, 09:03
83urq 83urq is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
Quote:
Originally Posted by r937
try query i put into previous post

i guess i was editing it while you answered
This:

SELECT SRCHWORD, SRCHFILNBR, COUNT(SRCHFILNBR) AS HITS
FROM CISDTA.RSRCH
WHERE (SRCHWORD >= 'keyword1' AND SRCHWORD <= 'keyword12')
OR (SRCHWORD >= 'keyword2' AND SRCHWORD <= 'keyword22')
GROUP BY SRCHFILNBR, SRCHWORD, HAVING COUNT(SRCHFILNBR) = 2
ORDER BY SRCHFILNBR

gives me this:

Warning: odbc_exec(): SQL error: [IBM][Client Access Express ODBC Driver (32-bit)][DB2/400 SQL]SQL0199 - Keyword COUNT not expected. Valid tokens: FOR WITH FETCH ORDER UNION OPTIMIZE., SQL state 37000 in SQLExecDirect
Reply With Quote
  #6 (permalink)  
Old 06-01-04, 09:28
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
comma in front of HAVING
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On