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
Solved

DB2 SQL - How can I provide for a variable substitution in my SQL where clause?

Posted on 2012-12-31
6
1,290 Views
Last Modified: 2013-01-09
Hi All,

I need to be able to substitute  two variables in this simple SQL code:

The JCL:
//SETVAR SET SSNODE=DBO1,DBOI=P1,DBOO=D2,
//           TRK=OG1,LOADIR=TEST,
//           PARMDIR=OGDBA,
//           PDBNAME='OG1DD%1',  <<-----Database name
//           PTSNAME='OG1SC%'       <<-----Tablespace Name

//SYSTSIN DD *
  DSN SYSTEM(DBO1) RETRY(3)
  RUN   PROGRAM(DSNTIAUL) PLAN(DSNTIB81) -
       LIB('SYS2.DB2.TEST.RUNLIB.LOAD') PARMS('SQL')
  END
/*
//SYSIN    DD *
  SELECT '-START DB('||DBNAME||') SPACENAM('||NAME||') ACCESS(UT)'  <<<------SQL
  FROM SYSIBM.SYSTABLESPACE
  WHERE DBNAME LIKE %PDBNAME
  AND NAME LIKE           %PTSNAME

//           PDBNAME='OG1DD%1',  <<-----Database name
//           PTSNAME='OG1SC%'       <<-----Tablespace Name


How can make this work?  I am getting errors every which way I try!

Your expert help will be highly appreciated
0
Comment
Question by:Enyinnaya
  • 4
  • 2
6 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 38733972
there is no simple way to do that
you can either write a program that gets those parameters and put them in the sql query and then execute the query or generate the input file for dsntiaul, or you can try to use iebgener to modify the input file for dsntiaiul
0
 

Author Comment

by:Enyinnaya
ID: 38737768
Ok, moni_sabag, could you kindly describe in more detail with example of what or how you will go about doing what you have in mind?



Thanks
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 38737795
could you explain what is the point of having those as parameters that are hard coded in the JCL?
0
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 

Author Comment

by:Enyinnaya
ID: 38740640
First, we are do not have many of the avaiable DBMS management toolset available to us so I am not privileged in that regard.
I have several application tracks and the associated databases. I do not want to have to update many many jobs every time a change is made/added/dropped, etc to tablespaces or tables if I want to QUIESCE, or put Tablespaces in utility mode during DB maintenance.

Also, I want to try to use only one Procedure for all my DB2 environments: 6 QA environment and 4 Test environment not to mention my production environments. Each environment has at least 7 applications/database tracks. My good news is that the database and tablespace are identical in almost everyway. By using symbolic substitution method, I can do this easily I believe.

The problem is, and as you so rightfully stated earlier, there is no easy way (or is there?) to get DNSTIAUL to accept parameter substitution the way I have it in the SQL that you saw before.

All I really trying to achieve here is be able to specify a database and/or tablespaces, select all tablespace that I specify and put them in utility mode or return them to read/write at will without doing any hardcoding!.

This SQL works just fine only if I hardcode a database or a tablespace name. I want to substitute to two parameters dynamically.

I hope this help to clarify what I am trying to achieve.

Thanks
0
 

Accepted Solution

by:
Enyinnaya earned 0 total points
ID: 38744337
Ok, I think this question is/was wrongly worded hence the lack of responses or answers. I am going to close it...rephrase the question to more accurately reflect what I need assistance with...no points awarded.

Thanks
0
 

Author Closing Comment

by:Enyinnaya
ID: 38758226
No valid answer, no example...rephrasing the question...
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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