473,624 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Errorr execute immediate

4 New Member
Dear all,
I'll try to convert from SQL server Store Procedure to DB2 Store Procedure.
I've make SP under DB2 like this
CREATE PROCEDURE GetSearchedReco rds (pKeyWords VARCHAR(1000),
pIsAll INTEGER,
pIsExact INTEGER,
pDateCondition INTEGER,
pDateType INTEGER,
pDateOn TIMESTAMP,
pDateTo TIMESTAMP,
pLimit INTEGER,
pFolderCategory INTEGER,
pFolderID CHAR(32),
pSort INTEGER,
pUserID CHAR(32) )
LANGUAGE SQL

BEGIN


DECLARE vsqlQuery VARCHAR(8000);

DECLARE vTopLimit VARCHAR(30);

DECLARE voperator VARCHAR(5);

DECLARE vkey VARCHAR(300);

DECLARE vkeywordCount INTEGER;

DECLARE vloop INTEGER;

DECLARE l_sqlstatus INTEGER;

DECLARE vDateTypeColumn VARCHAR(20);

DECLARE vSortCondition VARCHAR(35);

DECLARE key_cursor CURSOR FOR SELECT ur.Value
FROM table(SqlSplitD elim(pKeyWords) ) ur;


IF (pLimit = 0) THEN

SET vTopLimit = ' ';

ELSE

SET vTopLimit = ' TOP ' || CAST (RTRIM(CHAR(pLi mit)) AS VARCHAR(30)) || ' ';

END IF;


SET
vsqlQuery = 'Select ' || vTopLimit || ' rec.RecordID, rec.Subject, fol.FolderName, rec.ReportDate, us.FirstName ||''|| us.LastName as Source,
field1.Field1Ty peName, field2.Field2Ty peName, field3.Field3Ty peName, substr(rec.Comm ents, 1, 50) as Comments,
(Select Count(FileName) From Attachments Where DocumentID = rec.RecordID) As AttachmentCount
From ((((Records rec Left Join Field1Types field1 On rec.Field1TypeI D = field1.Field1Ty peID)
Left Join Field2Types field2 On rec.Field2TypeI D = field2.Field2Ty peID)
Left Join Field3Types field3 On rec.Field3TypeI D = field3.Field3Ty peID)
Inner Join Names_Users us On rec.CreatorUser ID = us.UserID)
Inner Join Folders fol On fol.FolderID = rec.FolderID
';

IF (pIsAll = 0) THEN

SET voperator = ' or ';

ELSE

IF (pIsAll = 1) THEN

SET voperator = ' and ';

END IF;

END IF;

SET vsqlQuery = vsqlQuery || ' Where F_GetFolderAcce ssTypeID(fol.Fo lderID,''' || CAST (pUserID AS VARCHAR(100)) || ''') > 1 ';

SET vkeywordCount = (SELECT COUNT(ur.value)
FROM table(SqlSplitD elim(pKeywords) )ur) ;

IF (vkeywordCount <> 0) THEN

SET vsqlQuery = vsqlQuery || ' and (';

END IF;

SET vloop = 0;

OPEN key_cursor;

SET l_sqlstatus = 0;
FETCH FROM key_cursor INTO vkey;

WHILE l_sqlstatus = 0 DO

IF (vloop = vkeywordCount - 1) THEN

SET vsqlQuery = vsqlQuery || ' (rec.Subject like ''%' || vkey || '%'' or fol.foldername like ''%' || vkey || '%'' or us.FirstName like ''%' || vkey || '%'' or us.LastName like ''%' || vkey || '%'' or field1.field1ty pename like ''%' || vkey || '%'' or field2.field2ty pename like ''%' || vkey || '%''or field3.field3ty pename like ''%' || vkey || '%'' or rec.comments like ''%'|| vkey||'%'' ))';


ELSE


SET vsqlQuery = vsqlQuery || ' (rec.Subject like ''%' || vkey || '%'' or fol.foldername like ''%' || vkey || '%'' or us.FirstName like ''%' || vkey || '%'' or us.LastName like ''%' || vkey || '%'' or field1.field1ty pename like ''%' || vkey || '%'' or field2.field2ty pename like ''%'|| vkey || '%'' or field3.field3ty pename like ''%' || vkey || '%'' or rec.comments like ''%'|| vkey||'%'' )) ' || voperator ;



END IF;


SET vloop = vloop + 1;


SET l_sqlstatus = 0;
FETCH FROM key_cursor INTO vkey;

END WHILE ;


CLOSE key_cursor;




IF (pDateType = 0) THEN


IF (pDateCondition <> 0) THEN


SET vDateTypeColumn = ' rec.ReportDate ';

ELSE


SET vDateTypeColumn = ' ';

END IF;

ELSE

IF (pDateType = 1) THEN

SET vDateTypeColumn = ' rec.CreateDate ';

ELSE

IF (pDateType = 2) THEN


SET vDateTypeColumn = ' rec.ModifiedDat e ';

ELSE

SET vDateTypeColumn = ' ';

END IF;

END IF;

END IF;

IF (pDateCondition > 0
AND pDateCondition <= 4) THEN


IF (vDateTypeColum n <> ' ') THEN


SET vsqlQuery = vsqlQuery || ' and ';

IF (pDateCondition = 1) THEN


SET vsqlQuery = vsqlquery ||''|| vDateTypeColumn ||''|| '=' ||''|| Cast(pDateOn As varchar(11)) ;

ELSE

IF (pDateCondition = 2) THEN


SET vsqlQuery = vsqlquery ||''|| vDateTypeColumn ||''|| '>' ||''|| Cast(pDateOn As varchar(11)) ;


ELSE

IF (pDateCondition = 3) THEN


SET vsqlQuery = vsqlquery ||''|| vDateTypeColumn ||''|| '<' ||''|| Cast(pDateOn As varchar(11)) ;

ELSE


IF (pDateCondition = 4) THEN


SET vsqlQuery = vsqlquery ||''|| vDateTypeColumn ||''|| '>' ||''|| Cast(pDateOn As varchar(11)) ||''|| 'and'||''|| vDateTypeColumn ||''|| '<' ||''|| Cast(pDateOn As varchar(11)) ;


END IF;

END IF;

END IF;

END IF;

END IF;

END IF;

IF (pFolderCategor y = 1
OR pFolderCategory = 2) THEN

SET vsqlQuery = vsqlQuery || ' and ';


IF (pFolderCategor y = 1) THEN


SET vsqlQuery = vsqlQuery || ' rec.FolderID = ''' || CAST (pFolderID AS VARCHAR(100)) || '''';

ELSE

IF (pFolderCategor y = 2) THEN


SET vsqlQuery = vsqlQuery || ' rec.FolderID In
(Select Value From F_GetDescendant sFolderID(''' || CAST (pFolderID AS VARCHAR(100)) || ''')
Union Select ''' || CAST (pFolderID AS VARCHAR(100)) || ''')';

END IF;

END IF;

END IF;

IF (pSort = 0) THEN

SET vSortCondition = ' order by rec.FolderID ASC ';

ELSE

IF (pSort = 1) THEN


SET vSortCondition = ' order by rec.ReportDate DESC ';

ELSE

IF (pSort = 2) THEN

SET vSortCondition = ' order by rec.ReportDate ASC ';

ELSE

SET vSortCondition = ' ';

END IF;

END IF;

END IF;

SET vsqlQuery = vsqlQuery || vSortCondition;


EXECUTE IMMEDIATE vsqlQuery;

END

but when I try to execute this SP , giving error, An EXECUTE IMMEDIATE statement contains a SELECT or VALUES
statement. SQLSTATE=42612,
anyone help me please


Regards


Agus Wahyu
Jul 24 '07 #1
1 2326
Shashank1984
26 New Member
The implied function is not supported.
Prepare the SELECT or VALUES statement.
Then use OPEN, FETCH, and CLOSE.

Thanks and Regards,
Shashank K.
Jul 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
22380
by: michi | last post by:
Hello there... Can anybody tell me what is the difference when I excecute a sql statement within pl sql with/without "execute immediate" statement Thanks Michi :)
4
28419
by: finlma | last post by:
I'm trying to run an EXECUTE IMMEDIATE within a PL/SQL if loop but it doesn't work for me. I'm trying to create a column conditionally but it doesn't work. It fails because there are apostrophes within the statement. How do I override the apostrophe? DECLARE cCount NUMBER; BEGIN SELECT count(*) INTO cCount FROM all_tab_columns WHERE owner = 'Owner'
3
20386
by: Agoston Bejo | last post by:
I am looking for the PL/SQL equivalent of the VBScript Exec and/or Eval functions, i.e. I want to be able to dynamically create a statement, then execute it in the current PL/SQL context, e.g. declare x integer := 5; begin ExecuteStatement('x := 10'); dbms_output.put_line(x); -- should put "10" if EvaluateExpression('x*2 = 20') then
5
12408
by: Gustavo Randich | last post by:
Hello, I'm writing an automatic SQL parser and translator from Informix to DB2. Now I'm faced with one of the most difficult things to translate, the "foreach execute procedure" functionality provided by Informix. This is the problem: the execution of the translated SQL leaves the rows in the temp table correctly but raises error SQL0480N. It's very simple to try it: ------------
2
1154
by: Nancy | last post by:
I keep getting a syntax errorr with this code and having problems figuring out the problem. SELECT pageid, title, section.name, category.name, subcat.name, division.name, subdiv.name FROM page LEFT JOIN(section, category, subcat, division, subdiv) ON (section.section id = page.sectionid AND category.categoryid = page.categoryid AND subcat.subcatid = page.subcatid AND
5
7769
by: umesh049 | last post by:
Hello, I want to delete all the date of all the table in a scheman. but i got error at execute immediate statement. can any body help me. thanks
3
6969
by: nghivo | last post by:
My environment DB2 9.1.4 on Sun OS I write a C embedded SQL to load data. I declare host vars as: EXEC SQL BEGIN DECLARE SECTION; SQL TYPE IS CLOB(599999) sqlStr; EXEC SQL END DECLARE SECTION;
3
6953
by: Rahul Babbar | last post by:
Hi, I have the following doubt. Suppose I use the execute immediate statement and the statement to be executed is a Select statement from the sysibm.sysdummy1 table which will always return me one row. Further, i need to capture the result of the execute Immediate into a
6
4425
by: Oliver | last post by:
I'm fairly new to DB2. I have been assigned to build a delete trigger that finds the data type of each of the table's fields so that the trigger can then build a string consisting of OLD values pre-wrapped in quote marks as needed. The deleted record's field values, all strung together as a single string, would then be inserted into a single archiving table (an architecture I inherited and cannot change). I've got the trigger doing...
0
8233
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.