Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Parameters to Dynamic SQL

Status
Not open for further replies.

krotha

Programmer
Nov 5, 2000
116
0
0
US
I am trying to pass the values from the parameters to a dynamic sql and I get syntax error.I have many parameters like this and need to build a query depends on parameters passed, any help is appreciated.

CREATE PROCEDURE Test.Search ( IN P_number varchar (50))
DYNAMIC RESULT SETS 1

P1: BEGIN


DECLARE stmt VARCHAR(4000);
declare v_stmt varchar(4000);


DECLARE cursor1 CURSOR WITH RETURN FOR v_stmt;

set stmt =
'SELECT ID,NUMBER FROM Temp WHERE 1=1' ;

if P_number is not null then
set stmt = stmt || ' AND number = P_number';
END if;

prepare v_stmt from stmt;
OPEN cursor1;

END P1
 
It worked. Thanks a lot for you help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top