dbTalk Databases Forums  

In DB2 UDF , Can I insert Temp table ??(Original Source MSSQL)

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss In DB2 UDF , Can I insert Temp table ??(Original Source MSSQL) in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
scv1977
 
Posts: n/a

Default In DB2 UDF , Can I insert Temp table ??(Original Source MSSQL) - 04-29-2010 , 01:01 AM






Hi!
I have the following build problem with UDF creating the following.
The simplified text does the following:

1> MSSQL2005 UDF
CREATE FUNCTION dbo.FUNC1 (
@CompanySeq INT,
@FormatSeq INT
)
RETURNS @retFindReports TABLE (
FSItemTypeSeq INT,
FSItemSeq INT
)

AS
BEGIN
SET @FormatSeq = ISNULL(@FormatSeq, 0)
IF @FSItemSeq = 0 SET @FSItemSeq = 1;

WITH CTE_F1(FSItemTypeSeq, FSItemSeq)
AS
(
SELECT A.FSItemTypeSeq, A.FSItemSeq
FROM T1 A WITH (NOLOCK)
WHERE A.CompanySeq = @CompanySeq
AND A.FormatSeq = @FormatSeq


UNION ALL
SELECT A.FSItemTypeSeq, A.FSItemSeq
FROM T1 A WITH (NOLOCK)
INNER JOIN CTE_F1 CTE
ON A.UpperFSItemTypeSeq = CTE.FSItemTypeSeq
AND A.UpperFSItemSeq = CTE.FSItemSeq
WHERE A.CompanySeq = @CompanySeq
AND A.FormatSeq = @FormatSeq
)


INSERT @retFindReports ----> DB2 posssible @retFindReports(May
Be Temp Table)

SELECT FSItemTypeSeq, FSItemSeq
FROM CTE_F1
WHERE FSItemSeq NOT IN (SELECT UpperFSItemSeq FROM CTE_F1 )
OR UMCostType NOT IN (SELECT UpperUMCostType FROM CTE_F1 )
RETURN
END;


Also I Know(UDF can't use global temp table)
1) For Insert Into ,I must create "Procedure"
2) UDF Call Procedure
How Can I make the UDF the Another Method(Insert into
@retFindReports)?

Reply With Quote
  #2  
Old   
Serge Rielau
 
Posts: n/a

Default Re: In DB2 UDF , Can I insert Temp table ??(Original Source MSSQL) - 05-02-2010 , 10:37 AM






Try this:

CREATE FUNCTION dbo.FUNC1 (
CompanySeq INT,
FormatSeq INT
)
RETURNS TABLE (
FSItemTypeSeq INT,
FSItemSeq INT
)

BEGIN ATOMIC
SET FormatSeq = ISNULL(FormatSeq, 0);
// Below IF makes no sense....
IF FSItemSeq = 0 THEN SET FSItemSeq = 1; END IF;

RETURN
WITH CTE_F1(FSItemTypeSeq, FSItemSeq)
AS
(
SELECT A.FSItemTypeSeq, A.FSItemSeq
FROM T1 A WITH (NOLOCK)
WHERE A.CompanySeq = CompanySeq
AND A.FormatSeq = FormatSeq


UNION ALL
SELECT A.FSItemTypeSeq, A.FSItemSeq
FROM T1 A WITH (NOLOCK)
INNER JOIN CTE_F1 CTE
ON A.UpperFSItemTypeSeq = CTE.FSItemTypeSeq
AND A.UpperFSItemSeq = CTE.FSItemSeq
WHERE A.CompanySeq = CompanySeq
AND A.FormatSeq = FormatSeq
)
SELECT FSItemTypeSeq, FSItemSeq
FROM CTE_F1
WHERE FSItemSeq NOT IN (SELECT UpperFSItemSeq FROM CTE_F1 )
OR UMCostType NOT IN (SELECT UpperUMCostType FROM CTE_F1 );
END
@



--
Serge Rielau
SQL Architect DB2 for LUW
IBM Toronto Lab

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.