IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Generic DB2 statement


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
simha_it

New User


Joined: 05 May 2005
Posts: 30

PostPosted: Thu May 06, 2010 3:44 pm
Reply with quote

Hi All,

I want to write one generic Service (SQL query) in which I can retrieve the data from any table using primary key.

For example, during the run time my service will get the table name (it could be any table name) as an input. Based on that table name, I have to retrieve the data. But I have to retrieve the data based on the primary key of that particular table.

Can any one suggest how to achieve this?

I have one idea in my mind. I think, we can use dynamic SQL. By using dynamic SQL we can issue Select * from [table name] but difficult to give where clause here. Is it possible to give Index (primary key) dynamically for any table.

Thanks
Simha
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu May 06, 2010 4:08 pm
Reply with quote

So why have you posted this in the DFSORT forum ?
Back to top
View user's profile Send private message
simha_it

New User


Joined: 05 May 2005
Posts: 30

PostPosted: Thu May 06, 2010 5:12 pm
Reply with quote

I don't know about this. But I am looking for a help. Could you please help me out in this?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu May 06, 2010 5:22 pm
Reply with quote

what You ask for is not suitable for a forum reply ..
if You have the skills it' s reasonably easy to do it, NO amount of replies will provide You with the skills needed

Yes it can be done once the requirements are clear, how to do it is a different show

take one of the DSNTEP flavors and modify it according to Your needs
DSNTEP resides in a dataset name along "<some_qualifier>.SDSNSAMP"
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu May 06, 2010 9:28 pm
Reply with quote

Hello,

Why do you believe you need to provide a substitute for SPUFI?

Hopefully, you are aware that if "anyone" is permitted to do "whatever they want" on the fly, the system will eventually melt down. . .
Back to top
View user's profile Send private message
die7nadal

Active User


Joined: 23 Mar 2005
Posts: 156

PostPosted: Fri May 07, 2010 9:25 pm
Reply with quote

This can done by querying the SQLDA variables. This process has been explained under Varying list Select statements using dynamic query in the IBM manuals. I can't remember exactly which manual at the top of my head.

As far as the primary key is concerned you can get them from the catalogue tables using this query
Code:
SELECT * FROM SYSIBM.SYSCOLUMNS 
WHERE TBNAME = 'NAME'             
AND KEYSEQ   > 0                 
WITH UR;                         
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Sat May 08, 2010 11:11 am
Reply with quote

This is a very ambitious project, and, from your basic question, I don't believe you have the necessary skills.
I'm not even sure I have the skills for that!

simha_it wrote:
I have to retrieve the data based on the primary key of that particular table.
...
but difficult to give where clause here. Is it possible to give Index (primary key) dynamically for any table.
From the way you posted your question, I feel you mixed the WHERE and ORDER BY clauses.
If you want to force DB2 to use an index, then you should ORDER BY all the key columns.

And yes, handling the WHERE will be very difficult.
You will need to handle all possible row lengths too.
And you will need authorization to access all the tables.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat May 08, 2010 7:45 pm
Reply with quote

Hello,

Tonrepeat:
Quote:
Why do you believe you need to provide a substitute for SPUFI?
If youn explain what you really want to do, someone may have a suggestion.

What you have asked is about a solution. What is the actual requirement?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
No new posts Relate COBOL statements to EGL statement All Other Mainframe Topics 0
No new posts process statement for SUPREC, CMPCOLM... TSO/ISPF 4
No new posts SYNCSORT/ICETOOL JOINKEYS SORT Statem... DFSORT/ICETOOL 13
No new posts DFDSS COPY using Filter REFDT statement JCL & VSAM 2
Search our Forums:

Back to Top