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.
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.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
my overalls have superpowers - they repel people who think fashion is important. Tiny ad: