• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Execute SQL queries within views conditionally

 
Ranch Hand
Posts: 154
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We had a couple of huge SQL statements (executed within an embedded sqlrpgle program) for which we created separate views - one for each SQL.

The SQL statements were being executed within the programs conditionally. That is, the program had some conditional logic in it (written in RPG) which would determine whether we would execute one query or the other.

Now what we are trying to do is to create a single view which would be an equivalent of the RPG program.

That is somehow include the conditional logic in the view code.

Below is the simplest pseudocode of the view that I could imagine of what I am trying to achieve



The if condition logic needs to be part of the view that I am trying to create. Is something like this possible in DB2?

Please note that the condition 1 used above is a very high level representation. The logic is actually comprised of several program calls etc.

Any advise would be appreciated.
 
Saloon Keeper
Posts: 23409
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're trying to do things in places you shouldn't be.

What I would recommend is that you define your two views unconditionally and let the application logic determine which view to use.

Now when I say "view" I'm referring to what is basically a named SQL fixed query that presents itself as a virtual table. If your idea of a view is parameterized, that would make it more like a stored procedure. You can, of course, use Views the same way you do regular tables in SQL queries, if that helps.
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic