Solved

inline view - table reference with union all

Posted on 2006-06-13
2
3,282 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now