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

Errorr execute immediate

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 GetSearchedRecords (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(SqlSplitDelim(pKeyWords)) ur;


IF (pLimit = 0) THEN

SET vTopLimit = ' ';

ELSE

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

END IF;


SET
vsqlQuery = 'Select ' || vTopLimit || ' rec.RecordID, rec.Subject, fol.FolderName, rec.ReportDate, us.FirstName ||''|| us.LastName as Source,
field1.Field1TypeName, field2.Field2TypeName, field3.Field3TypeName, substr(rec.Comments, 1, 50) as Comments,
(Select Count(FileName) From Attachments Where DocumentID = rec.RecordID) As AttachmentCount
From ((((Records rec Left Join Field1Types field1 On rec.Field1TypeID = field1.Field1TypeID)
Left Join Field2Types field2 On rec.Field2TypeID = field2.Field2TypeID)
Left Join Field3Types field3 On rec.Field3TypeID = field3.Field3TypeID)
Inner Join Names_Users us On rec.CreatorUserID = 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_GetFolderAccessTypeID(fol.FolderID,''' || CAST (pUserID AS VARCHAR(100)) || ''') > 1 ';

SET vkeywordCount = (SELECT COUNT(ur.value)
FROM table(SqlSplitDelim(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.field1typename like ''%' || vkey || '%'' or field2.field2typename like ''%' || vkey || '%''or field3.field3typename 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.field1typename like ''%' || vkey || '%'' or field2.field2typename like ''%'|| vkey || '%'' or field3.field3typename 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.ModifiedDate ';

ELSE

SET vDateTypeColumn = ' ';

END IF;

END IF;

END IF;

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


IF (vDateTypeColumn <> ' ') 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 (pFolderCategory = 1
OR pFolderCategory = 2) THEN

SET vsqlQuery = vsqlQuery || ' and ';


IF (pFolderCategory = 1) THEN


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

ELSE

IF (pFolderCategory = 2) THEN


SET vsqlQuery = vsqlQuery || ' rec.FolderID In
(Select Value From F_GetDescendantsFolderID(''' || 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 2307
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
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
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...
3
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. ...
5
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...
2
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...
5
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
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...
3
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...
6
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...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.