0
我想下面的函數從PLSQL轉換成tsql.But我不擅長在TSQL也想不出swisssql將其轉換correctly.Canü看看嗎?謝謝轉換PLSQL函數成爲TSQL
CREATE OR REPLACE function yonetici_kontrol_musteri (p_ID_MUSTERI_SIRKET in number, p_ID_YONETICI in number)
return number
is
v_unvan number;
v_yonetici number;
v_tmp_unvan number;
v_tmp_yonetici number;
v_result number;
begin
v_result:=-1;
SELECT id_unvan INTO v_unvan FROM lu_yonetici WHERE id_yonetici=p_ID_YONETICI;
for c in ( SELECT NVL (b.id_mufettis, 0) id_mufettis, b.id_sef
FROM cr_rut_musteri c, lu_bayi_temsilci b
WHERE c.id_musteri_sirket = p_id_musteri_sirket
AND c.id_temsilci = b.id_temsilci
AND c.valid = 1
AND b.valid = 1
AND c.aktif = 1
AND b.aktif = 1
)
loop
CASE v_unvan
WHEN 1 THEN
if c.id_mufettis = p_ID_YONETICI then
v_result:=1;
else
v_result:=0;
end if;
WHEN 2 THEN -- satis sefi
if c.id_sef = p_ID_YONETICI then
v_result:=1;
else
v_result:=0;
end if;
ELSE
v_yonetici:=c.id_sef;
loop
SELECT uy.id_unvan, uy.id_yonetici INTO v_tmp_unvan, v_tmp_yonetici
FROM lu_yonetici y, lu_yonetici uy
WHERE y.id_ust_yonetici=uy.id_yonetici
AND y.id_yonetici=v_yonetici;
if v_tmp_unvan=v_unvan then
if v_tmp_yonetici=p_ID_YONETICI then
v_result:=1;
else
v_result:=0;
end if;
else
v_yonetici:=v_tmp_yonetici;
end if;
exit when v_result=1 or v_tmp_unvan>=v_unvan;
end loop;
END CASE;
exit when v_result=1;
end loop;
return v_result;
exception
when others then
return 0;
end;