2012-01-23 13 views
1
私は店の手順を実行し、「tbl_property.intId = 1」はプロシージャの実行が 1243失敗与えるパラメータ渡し
Below is my store procedure .please help........ 



BEGIN 



DECLARE selectQuery VARCHAR(2000); 
declare finalquery varchar(2000); 
declare stmt3 varchar(2000); 

SET selectQuery = 'SELECT tbl_property.intId, strAddressLine1,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountyTypeId) as strCountyName ,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountryTypeId) as strCountryName ,strpostCode,(tbl_pro_adver_matchcriteria.floatAskingPrice),tbl_pro_adver_matchcriteria.intBedrooms 
FROM tbl_property LEFT OUTER JOIN tbl_pro_adver_matchcriteria on tbl_property.intId = tbl_pro_adver_matchcriteria.intPro 
set finalquery =CONCAT(selectQuery,strSqlQuery,' AND tbl_property.intId=1 '); 

execute finalquery; 

END 

MySQLでのステートメントを実行使い方 - 不明プリペアドステートメントハンドラを(最後のクエリ)ダイナミック使用している間、where句

よく私はそれが正しいクエリを返し、結果を返すselect文でクエリ結果を確認します。私はExecuteステートメントを使用して助けてください。

+0

SQL構文プリペアドステートメントのための - のhttp://dev.mysql。 com/doc/refman/5.1/ja/sql-syntax-prepared-statements.html – Devart

答えて

0

このリンクhttp://docs.oracle.com/javase/tutorial/jdbc/basics/storedprocedures.htmlを試してみて、それが が

DECLARE selectQuery VARCHAR(2000); 
declare finalquery varchar(2000); 
declare stmt3 varchar(2000); 

SET selectQuery = 'SELECT tbl_property.intId, strAddressLine1,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountyTypeId) as strCountyName ,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountryTypeId) as strCountryName ,strpostCode,(tbl_pro_adver_matchcriteria.floatAskingPrice),tbl_pro_adver_matchcriteria.intBedrooms 
FROM tbl_property LEFT OUTER JOIN tbl_pro_adver_matchcriteria on tbl_property.intId = tbl_pro_adver_matchcriteria.intProId '; 

set finalquery =CONCAT(selectQuery,strSqlQuery); 


EXECUTE finalquery; 
0

動的ステートメントを調製し、使用後に割り当てを解除する必要があるBEGIN、あなたを助けるかもしれません。ここに例があります。

BEGIN 

SET @selectQuery = 'SELECT * from table1 where' 

SET @QUERY = CONCAT(@selectQuery, ' field = 1');    
SELECT @QUERY; 
PREPARE s FROM @QUERY; 

EXECUTE s; 
DEALLOCATE PREPARE s; 

END 
2

あなたの助けのためのThanxsは、私はそれを試してみましたが、それは少しmodifications..belowで動作します私の店の手順です:

BEGIN 
DECLARE selectQuery VARCHAR(2000); 
declare finalquery varchar(2000); 

SET selectQuery = 'SELECT tbl_property.intId, strAddressLine1,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountyTypeId) as strCountyName ,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountryTypeId) as strCountryName ,strpostCode,(tbl_pro_adver_matchcriteria.floatAskingPrice),tbl_pro_adver_matchcriteria.intBedrooms 
FROM tbl_property LEFT OUTER JOIN tbl_pro_adver_matchcriteria on tbl_property.intId = tbl_pro_adver_matchcriteria.intProId '; 

set @finalquery =CONCAT(selectQuery,strSqlQuery,' AND tbl_property.intId=1 '); 

PREPARE result from @finalquery; 
EXECUTE result; 
DEALLOCATE PREPARE result; 

END 
+0

これをシステムが許可したときに受け入れられた回答としてマークするか、これをあなたの質問に編集し、あなたを助けた回答を受け入れることを忘れないでください最も。 –

+0

と変更したものを示します。 – levi