Solved

inline view - table reference with union all

Posted on 2006-06-13
2
3,322 Views
Last Modified: 2008-01-09
ive got a larger query, but to cut it down its like this:

select count(col1) as reccount from table1
where col2 > 0 and col3 / col2 > 21
union all
select count(col1) as reccount from table1
where col2 = 0


in the first query i have to exclude records that are zero because as you can see i would end up dividing by zero.  i also need to include those records in the results though.  the query works alright when im getting the details, but not when using the count function.  im a sql guy and i would have done something like this to get a sum of the counts:

select sum(reccount) as sumcount from (
select count(col1) as reccount from table1
where col2 > 0 and col3 / col2 > 21
union all
select count(col1) as reccount from table1
where col2 = 0)



when i try to do that with the db2, it gives me:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[IBM][Client Access Express ODBC Driver (32-bit)][DB2/400 SQL]SQL0104 - Token <END-OF-STATEMENT> was not valid. Valid tokens: AS <IDENTIFIER>.



i have searched "db2 inline view" and "db2 table reference" and i keep finding articles that say its possible, but i cant get it to work.
0
Comment
Question by:WMIF
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 250 total points
ID: 16896628

Welcome to the world of IBM error messages.  :)   "General Failure to Do Right....."


Derived tables must be named.  Simply put a "as table3" after the closing ")".


Good Luck!
Kent
0
 
LVL 22

Author Comment

by:WMIF
ID: 16896742
awesome.  that worked perfectly.  



>>Welcome to the world of IBM error messages.  :)   "General Failure to Do Right....."

i am fairly familiar with the error messages because ive been accessing the db2 through asp for many years now.  its a pain to do sometimes, but its more of a pain to create copies of data into a sql server, besides being pointless as well.

thanks so much.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question