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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird stored procedure behaviour

Status
Not open for further replies.

AndrejSlo

Programmer
Jun 14, 2005
3
SI
Hi, it sound silly, but there it is. If I run this SQL from within DataManager (i'm using Pervasive V.8)

SELECT
klklas, klnasl FROM ktskld
WHERE ((klklas LIKE '2%'))
AND ((klnasl like '%'))
AND ((length(klklas) = 2))
ORDER BY klklas;

i get corect result, but when i try to get results from the stored procedure

CREATE PROCEDURE SP_KTSKLD(IN :klklas char (9), IN :klnasl CHAR(34), IN :tip CHAR(1), IN :pORDER CHAR(20))
RETURNS(
klklas char(9),
klnasl char(34)
) with default handler

as

declare :dol integer

set :dol = length:)klklas)

set :klklas = :klklas + '%';
set :klnasl = :klnasl + '%';

if :Dol < 2 then

SELECT
klklas, klnasl FROM ktskld
WHERE ((klklas LIKE :klklas) or :)klklas = ''))
AND ((klnasl like :klnasl) or :)klnasl = ''))
AND ((length(klklas) = 2) or :)tip = '0'))
ORDER BY klklas;

else if :Dol < 3 then

SELECT
klklas, klnasl FROM ktskld
WHERE ((klklas LIKE :klklas) or :)klklas = ''))
AND ((klnasl like :klnasl) or :)klnasl = ''))
AND ((length(klklas) = 3) or :)tip = '0'))
ORDER BY klklas;

else if :Dol < 4 then

SELECT
klklas, klnasl FROM ktskld
WHERE ((klklas LIKE :klklas) or :)klklas = ''))
AND ((klnasl like :klnasl) or :)klnasl = ''))
AND ((length(klklas) = 6) or :)tip = '0'))
ORDER BY klklas;

else

SELECT
klklas, klnasl FROM ktskld
WHERE ((klklas LIKE :klklas) or :)klklas = ''))
AND ((klnasl like :klnasl) or :)klnasl = ''))
AND ((length(klklas) = 9) or :)tip = '0'))
ORDER BY klklas;

end if;
end if;
end if;

using call SP_KTSKLD('2', '', '1', '')

the first two (not allways, but there are allmost always duplicate key values) rows have IDENTICAL klklas values. Indexes are good, so i don't have a clue about what it might be the reason for such strange results.

My second question is : How can i use variables :)Var) from within DataManager since this is the only way to check whether sp will work the way it should? Any alternative editors ??

Thanks for your answers.
Andrej
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top