Solved

Excel 2007 - Oracle query with parameters

Posted on 2010-11-17
9
1,367 Views
Last Modified: 2012-05-10
I have a spreadsheet that uses an odbc connection to an oracle database and returns a set of data for a report.  What I would like to do is parameterize the where clause.  I have researched on microsoft's office web site and found a couple of articles that show you how to do it if using an access database but not oracle.  The parameters button is never enabled since my query does not allow you to edit it in design view only sql view.  Is there a way to parameterize an oracle sql statement by storing the values on another sheet?

Would like to have:
1) Setting sheet that contains the release value in the cell(2,1).
2) StatusReport sheet contains the data retrieved from the paramaterize query

WHERE CLAUSE:
r.release = @releaseid

not sure how to reference the parameter

Thanks in advance!

SQL Statement:
SELECT * FROM
(
SELECT c.PROJ_NAME as "Project",
       coalesce(sum(decode(tc.tc_status,'No Run',1,'Failed',1,'Passed',1,'Not Completed',1)),0) as "# of Scenarios",
       coalesce(sum(decode(tc.tc_status,'Failed',1,'Passed',1,'Not Completed',1)),0) as "# Executed",
       coalesce(sum(decode(tc.tc_status,'Passed',1)),0) as "# Pass",
       coalesce(sum(decode(tc.tc_status,'Failed',1)),0) as "# Fail"
FROM
tables
WHERE
r.release = '1.0'
GROUP BY p.PROJ_NAME
)
ORDER BY 1

Open in new window

0
Comment
Question by:j420exe1
[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
  • 3
  • 3
  • 3
9 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34159099
Did you build the query in code or in the query wizard?
0
 
LVL 9

Accepted Solution

by:
Philippe Damerval earned 250 total points
ID: 34159130
Hi,
Here's how I am making this work in my environment:

1) Under "data" select "from other sources" then "From Microsoft query"
2) Select "new datasource"
3) In "create new datasource" dialog type in new name, select oracle driver and click "connect"
4) Input login details, pick server
5) under "options" pick the default database
6) click OK and return to choose data source dialog
7) click ok - query wizard opens. CANCEL out of it
8) dialog "do you want to continue?" say YES
9) Add tables dialog - add the table you want
10) press "SQL" button in the toolbar
11) Add where clause with "?" as parameter
12) when asked supply a parameter - don't worry this is temporary
13) Choose "return data to Excel ) button on toolbar
14) In import data dialog press "properties"
15) under "definition" tab click "parameters" button
16) I use "getthe value from the following cell" option but you can opt to prompt for a value too

Now every time you refresh the query gets rerun using the parameter supplied, either through a prompt or using a cell in the sheet.

HTH

Philippe
0
 

Author Comment

by:j420exe1
ID: 34159378
I built the query using toad.  I tried manually adding the tables and kept getting errors with MS Query Wizard when trying to join them.  So, I couldn't get your example to work with multiple joined tabled since my query can't be edited by the Query Wizard.  
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 9

Expert Comment

by:Philippe Damerval
ID: 34159417
have you tried rewriting the query in such a way that it might be editable in MS query? You don't need the subquery to get the results you want.
0
 
LVL 37

Assisted Solution

by:TommySzalapski
TommySzalapski earned 250 total points
ID: 34159467
If the query is in VBA code it's easy to add parameters. You just do
query = "SELECT blah FROM table WHERE table.field = " & Range("A1").Value & " AND otherconditions"
I don't know what you meant by toad.
0
 

Author Comment

by:j420exe1
ID: 34159565

Toad is an oracle query tool.

Yes, I can get it to work using VBA code.  I was trying not to write code.

I could look at rewriting the query.  When I remove the first query select * from...ms query still chokes.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34159625
damerval, if you do the parameters in that way how does it affect the query when you view it? Does it show some useful code or does it hard code the values?
0
 
LVL 9

Expert Comment

by:Philippe Damerval
ID: 34159905
To the best of my ability to determine, the parameters are passed using ODBC logic, so the query is not changed, simply run with different parameters. Using the "?" and sequential values seems to be handled automatically.
0
 

Author Closing Comment

by:j420exe1
ID: 34163884
Since I can't seem to get it to work...I am going to attempt to code the solution for now.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

734 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