473,387 Members | 1,520 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,387 software developers and data experts.

UDF RETURNS DIFFERENT TABLE

I would like to write an UDF function that returns table A or table B
based on a value passed as argument.

Something like:

CREATE FUNCTION my_func(my_value INTEGER)
....
RETURNS TABLE (C1 INTEGER, C2 INTEGER)
....
BEGIN ATOMIC
RETURN
if my_value = 1 then
SELECT C1,C2 FROM TABLEA
else
SELECT C1,C2 FROM TABLEB
Is it possible to include an IF inside a RETURN ?

Jul 6 '08 #1
2 1783
On Jul 6, 4:50 pm, Massimiliano Campagnoli <m...@paoloastori.com>
wrote:
I would like to write an UDF function that returns table A or table B
based on a value passed as argument.

Something like:

CREATE FUNCTION my_func(my_value INTEGER)
...
RETURNS TABLE (C1 INTEGER, C2 INTEGER)
...
BEGIN ATOMIC
RETURN
if my_value = 1 then
SELECT C1,C2 FROM TABLEA
else
SELECT C1,C2 FROM TABLEB

Is it possible to include an IF inside a RETURN ?
You can achieve the same thing without if then else:

create function X (my_value INTEGER)
returns table (c1 int, c2 int)
return
select * from A where my_value = 1
union
select * from B where my_value <1

/Lennart

Jul 6 '08 #2
Lennart wrote:
On Jul 6, 4:50 pm, Massimiliano Campagnoli <m...@paoloastori.com>
wrote:
>I would like to write an UDF function that returns table A or table B
based on a value passed as argument.

Something like:

CREATE FUNCTION my_func(my_value INTEGER)
...
RETURNS TABLE (C1 INTEGER, C2 INTEGER)
...
BEGIN ATOMIC
RETURN
if my_value = 1 then
SELECT C1,C2 FROM TABLEA
else
SELECT C1,C2 FROM TABLEB

Is it possible to include an IF inside a RETURN ?

You can achieve the same thing without if then else:

create function X (my_value INTEGER)
returns table (c1 int, c2 int)
return
select * from A where my_value = 1
union
select * from B where my_value <1
Make that a UNION ALL.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jul 6 '08 #3

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

Similar topics

7
by: robert | last post by:
running 8.1.7 server, 8.1.6 client. i *thought* inner join should not return nulls, but not only that, but i get way more rows than i'm expecting. assume: order table: order_number
2
by: Edward | last post by:
SQL Server 7.0 If I run the following in Query Analyzer I get no records returned: exec GetLeadsOutcome_Dealer '1/1/2003','12/2/2003',10, '176, 183' If, however, I run either : exec...
1
by: Sreeneet | last post by:
HI all, In SQL Server, i have a function which will return a table. like create function fn_test (@t int) returns table as return (select * from table) now i want the function to retun the...
5
by: Susan Geller | last post by:
Character returns stored in a table do not display in a textbox or on a datagrid on my .net form. The text displays without the returns making the text difficult to read. When I "view source" on...
0
by: Solution Seeker | last post by:
Hi, We are using vb.net for creating a Windows Application. We are using layered approach, with a UI layer, Logic, Db Access layer etc. we are encountering a peculiar problem when we try to...
9
by: serge | last post by:
/* Subject: How to build a procedure that returns different numbers of columns as a result based on a parameter. You can copy/paste this whole post in SQL Query Analyzer or Management Studio...
2
by: wajih.boukaram | last post by:
Hi I've been using asp.net for a couple of days now and i think I've gotten the hang of things I do have a problem when using HttpWebRequest: i request a page from a remote server and this...
0
by: h2reyes | last post by:
I have the following query: select sq.*, p.numero, p.nombre from paf p right outer join dbo.GetListOfSquaresForShippingLot(@lot) sq on sq.number = p.numero and sq.version = p.numero The @lot...
1
by: canugi | last post by:
I need to store the contents of an SQL "in clause" in an MS Access 2000 table. I use MS Access version 9.0.8960 (SP3) This is my statement (and it works fine with the explicit "in clause"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.