Solved

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

Posted on 2012-12-31
6
1,255 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now