Solved

inline view - table reference with union all

Posted on 2006-06-13
2
3,297 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
2 Comments
 
LVL 45

Accepted Solution

by:
Kdo 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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