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 > Subselect query not working only on DB2 V9.1

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-08-10, 03:59
ronakmaini ronakmaini is offline
Registered User
 
Join Date: Feb 2010
Posts: 6
Subselect query not working only on DB2 V9.1

Hi Guys,

The subselect query mentioned below works for DB2 V9.7 and 9.5 databases but FAILS on DB2 V9.1 -
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>
db2 "select SUM(FSFreeSizeKB) from (select distinct SUM(FS_TOTAL_SIZE_KB)-SUM(FS_USED_SIZE_KB) FSFreeSizeKB from SYSIBMADM.CONTAINER_UTILIZATION where TBSP_NAME = 'USERSPACE1' AND ACCESSIBLE = 1 group by FS_ID, CONTAINER_ID, DBPARTITIONNUM)"
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>

The following error message is displayed for V9.1 -

SQL0104N An unexpected token "" was found following ")". Expected tokens may include: "AS". SQLSTATE=42601

Please let me know what could be the reason of failure on V9.1

Thanks,
Ronak.
Reply With Quote
  #2 (permalink)  
Old 02-08-10, 05:36
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Add AS s, like this...
db2 "select ..... DBPARTITIONNUM) AS s"

It was suggested in the error message text.
Quote:
SQL0104N ... Expected tokens may include: "AS". ...
Reply With Quote
  #3 (permalink)  
Old 02-08-10, 05:50
ronakmaini ronakmaini is offline
Registered User
 
Join Date: Feb 2010
Posts: 6
Thanks!!! I had initially tried using AS .. after SUM(FSFreeSizeKB) and not at the end. But still dont know why this depedency for V9.1
Reply With Quote
  #4 (permalink)  
Old 02-08-10, 05:59
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
It is correlation-clause, and was mandatory until DB2 9.1 for LUW.
It is also mandatory on DB2 for z/OS and DB2 for iSeries.

You can see syntax in the manual "DB2 SQL Reference", like this...

nested-table-expression:
[LATERAL] ( fullselect ) correlation-clause

correlation-clause:
[AS] correlation-name [( column-name [, ...] )]
Reply With Quote
  #5 (permalink)  
Old 02-08-10, 06:27
ronakmaini ronakmaini is offline
Registered User
 
Join Date: Feb 2010
Posts: 6
Thanks for the explanation. Cheers!!!
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