473,320 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do I take table name from user in UDF

Hi friends,

I have a serious problem
I want to write a UDF that takes cloumn list and table name from the
user and then displays records from that table with those fields
displayed. Can anyone tell me how do I do this in DB2 Version 8.2 on
Windows

Thanks and regards
mailar

Nov 12 '05 #1
3 1947
ma****@gmail.com wrote:
Hi friends,

I have a serious problem
I want to write a UDF that takes cloumn list and table name from the
user and then displays records from that table with those fields
displayed. Can anyone tell me how do I do this in DB2 Version 8.2 on
Windows

Thanks and regards
mailar

You can do dynamic SQL in SQL Procedures or external UDF.
Not in SQL Functions. If you don't like to code C use the CALL statement
in the SQL UDF to call out to a SQL Procedure which then glues together
the statement.

Cheers
Serge
Nov 12 '05 #2
Hi Serge,
Thanks for oyur reply.
In fact I want to return a value from that table to the user and I dont
know if SQL procedure can return some value to its calling function.

So, could you give me an example(SQL procedure) that takes a table name
from user and returns a value(to its calling function) by firing a
query on that table.

Thanks again
mailar
Serge Rielau wrote:
ma****@gmail.com wrote:
Hi friends,

I have a serious problem
I want to write a UDF that takes cloumn list and table name from the user and then displays records from that table with those fields
displayed. Can anyone tell me how do I do this in DB2 Version 8.2 on Windows

Thanks and regards
mailar
You can do dynamic SQL in SQL Procedures or external UDF.
Not in SQL Functions. If you don't like to code C use the CALL

statement in the SQL UDF to call out to a SQL Procedure which then glues together the statement.

Cheers
Serge


Nov 12 '05 #3
Untested, but should make the point:

db2 -td$

CONNECT TO SAMPLE
$

CREATE TABLE S.T(c INTEGER)
$
INSERT INTO S.T(c) VALUES 1
$
CREATE PROCEDURE p (IN tabschema VARCHAR(128),
IN tabname VARCHAR(128),
OUT value INTEGER)
READS SQL DATA NO EXTERNAL ACTION DETERMINISTIC
BEGIN
DECLARE stmttxt VARCHAR(4000);
DECLARE stmt STATEMENT;
DECLARE cur CURSOR FOR stmt;

SET stmttxt = 'SELECT c FROM "' || tabschema || '"."'
|| tabname || '"';
PREPARE stmt FROM stmttxt;
OPEN cur;
FETCH cur INTO value;
CLOSE cur;
END
$
CREATE FUNCTION foo(tabschema VARCHAR(128),
tabname VARCHAR(128))
RETURNS INTEGER
READS SQL DATA DETERMINISTIC NO EXTERNAL ACTION
BEGIN ATOMIC
DECLARE result INTEGER;
CALL p(tabschema, tabname, result);
RETURN result;
END
$

VALUES foo('S', 'T')
$

TERMINATE
$
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John | last post by:
Hi, I have a data driven application which has some generalized components. So, for reuse, I am building the components so they can be reused in other projects ... it takes almost no extra...
3
by: Paul | last post by:
I have some option boxes and combo boxes that looks up values on a separate table (i.e. campus table with campusID & campus name fields) When I choose a selection from the combo box, it puts the...
6
by: Lewis Veale | last post by:
I have an Access 2000 front-end pointing at a SQL Server backend, with around 80 linked tables and views. I frequently need to point the front-end at different versions of the back-end, and achieve...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
9
by: john | last post by:
I have imported an Excel spreadsheet in Access. This table has 150 fields. The first field is 'user name', and all the other fields represent application names of which the value can be True of...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
2
by: banderson | last post by:
Hello, I have a data entry form for a table with information about buildings and am having a problem making a combo box do what I want. I would like to make the combo box show a list of unique bldg...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
3
by: adiel_g | last post by:
Hello everyone, I am trying to move a field name to a variable in vb.net. For example, first I retrieve the record from the database and save its value: .... userGroup =...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.