views:

767

answers:

1

I have slimmed down the query to remove potential complications, in addition I have verified that the fields are correct. DB2 UDB zSeries V7 is my db2 version.

   SELECT 
 STDINSTRCD, 
 count(*) over(partition by STDINSTRCD),
 CAST(STDINSTRDESC AS VARCHAR(1000)) AS INSTR,
 C.STDINSTRSEQ,
 1
FROM SYST.SCC004 C
WHERE  C.STDINSTRCD = '098'

I have tried a subqeury as well.

select 
 H2.FRSTSTDINSTRCD,
 (select count(*) from SYST.scC004 Ci where '098'=Ci.STDINSTRCD) as cnt, 
 cast(STDINSTRDESC as varchar(1000)),
 C.STDINSTRSEQ,
 1
from SYST.scE4A00 H2
 LEFT OUTER JOIN SYST.scC004 C
 ON C.STDINSTRCD = H2.FRSTSTDINSTRCD
 WHERE
  H2.CTLENTYID='MCS'
  AND H2.VCKVAL='12654'
  AND H2.POKVAL='0198617S12 000  000'

The error is receive is om.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: (;, FROM INTO sqlcode sqlstate -104 Illegal Symbol token. 42601 A character, token, or clause is invalid or missing.

Any advice? I have been unable to determine what syntax error I might me making.

A: 

are there any weird special characters in there that might not be printing? http://www-01.ibm.com/support/docview.wss?uid=swg1IY43009 basically sounds like a weird cr/lf or special char? Any copy pasting from *nix to windows ?

Also, I'm not sure why you need partition by anyway? would a group by not accomplish your goal. (looks like your just counting number of rows that met your criteria)... something like this for your first query?

SELECT 
 STDINSTRCD, 
 count(1) ,
 CAST(STDINSTRDESC AS VARCHAR(1000)) AS INSTR,
 C.STDINSTRSEQ,
 1
FROM SYST.SCC004 C
WHERE  C.STDINSTRCD = '098'
group by 
STDINSTRCD, 
CAST(STDINSTRDESC AS VARCHAR(1000)) AS INSTR,
C.STDINSTRSEQ,
1
tim
I am not transitioning from unix to windows. I have stayed entirely in windows and removing the lines lets the query run. I will look into the special character issue but as far as I can tell there shouldn't be anything strange going on there.
Jeremy
which lines did you remove to get it to run? "and removing the lines lets the query run"..
tim
I am able to recreate the error too on my version of db2 (9.something)and it seems to be the "count(*) over ( partition by" that is giving me grief, if I change that to use row_number() over() as rownum it will work... would the rownumber function give you similar information as count(*), seems like it would?
tim
count(*) over(partition by STDINSTRCD), is the line I mentioned. I'll try row_number
Jeremy
Row_number had the same issue. Note that I need to avoid grouping by the various fields as I need to use the windowing functions for what I am attempting to do.
Jeremy
If you just want counts w/out group by try this .. I wonder if the error is a UDB driver thing? We have a similar set up here and I get the same error but not on all aggregate functions.. weird. This article even uses syntax just like yours.http://www.ibm.com/developerworks/data/library/techarticle/lyle/0110lyle.html SELECT STDINSTRCD, ( SELECT COUNT(1) FROM SYST.SCC004 C2 WHERE C2.STDINSTRCD = C.STDINSTRCD ) AS COUNT, CAST (STDINSTRDESC AS VARCHAR(1000)) AS INSTR, C.STDINSTRSEQ, 1FROM SYST.SCC004 CWHERE C.STDINSTRCD = '098'
tim