• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Execute SQL queries within views conditionally

Ranch Hand
Posts: 160
  • 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: 27885
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.
    Bookmark Topic Watch Topic
  • New Topic