I want to convert following function from plsql into tsql.But i am not good at in tsql and also swisssql couldnt convert it correctly.Can u look at it?Thanks
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
开发者_JAVA百科 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;
You might want to try the SwisSQL Online migration tool
It gives the following result:
--SWISSQL DROP SCRIPTS
If Exists ( SELECT name
FROM sysobjects
WHERE name = 'yonetici_kontrol_musteri'
AND type = 'FN')
DROP FUNCTION yonetici_kontrol_musteri
GO
CREATE FUNCTION yonetici_kontrol_musteri
(
@p_ID_MUSTERI_SIRKET FLOAT ,
@p_ID_YONETICI FLOAT
)
RETURNS FLOAT
AS
BEGIN
DECLARE @adv_error INT
DECLARE @v_unvan FLOAT
DECLARE @v_yonetici FLOAT
DECLARE @v_tmp_unvan FLOAT
DECLARE @v_tmp_yonetici FLOAT
DECLARE @v_result FLOAT
SELECT @v_result = - 1
SELECT @v_unvan = id_unvan
FROM lu_yonetici
WHERE id_yonetici = @p_ID_YONETICI
SELECT @adv_error = @@ERROR
IF @adv_error != 0
BEGIN
GOTO Exception1
END
DECLARE cursor_for_inline_select1 CURSOR LOCAL FOR
SELECT
ISNULL(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
OPEN cursor_for_inline_select1
FETCH NEXT FROM cursor_for_inline_select1 INTO
/* SwisSQL (Oracle To SQL Server) : Table Information is not found in METADATA for the CURSOR used by the record-index */
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF @v_unvan = 1
BEGIN
IF /* SwisSQL (Oracle To SQL Server) : Manual Conversion Required */ c.id_mufettis = @p_ID_YONETICI
BEGIN
SELECT @v_result = 1
END
ELSE
BEGIN
SELECT @v_result = 0
END
END
ELSE
IF @v_unvan = 2
BEGIN
-- satis sefi
IF /* SwisSQL (Oracle To SQL Server) : Manual Conversion Required */ c.id_sef = @p_ID_YONETICI
BEGIN
SELECT @v_result = 1
END
ELSE
BEGIN
SELECT @v_result = 0
END
END
ELSE
BEGIN
SELECT @v_yonetici = /* SwisSQL (Oracle To SQL Server) : Manual Conversion Required */ c.id_sef
DECLARE @count INT
SELECT @count = 1
WHILE (0 = 0)
BEGIN --(
SELECT
@v_tmp_unvan = uy.id_unvan,
@v_tmp_yonetici = uy.id_yonetici
FROM lu_yonetici y,
lu_yonetici uy
WHERE y.id_ust_yonetici = uy.id_yonetici
AND y.id_yonetici = @v_yonetici
SELECT @adv_error = @@ERROR
IF @adv_error != 0
BEGIN
GOTO Exception1
END
IF @v_tmp_unvan = @v_unvan
BEGIN
IF @v_tmp_yonetici = @p_ID_YONETICI
BEGIN
SELECT @v_result = 1
END
ELSE
BEGIN
SELECT @v_result = 0
END
END
ELSE
BEGIN
SELECT @v_yonetici = @v_tmp_yonetici
END
IF @v_result = 1 or @v_tmp_unvan >= @v_unvan
BREAK
SELECT @count=@count +1
END --)
END
IF @v_result = 1
BREAK
FETCH NEXT FROM cursor_for_inline_select1 INTO
/* SwisSQL (Oracle To SQL Server) : Table Information is not found in METADATA for the CURSOR used by the record-index */
END
CLOSE cursor_for_inline_select1
DEALLOCATE cursor_for_inline_select1
DEALLOCATE cursor_for_inline_select1
return @v_result
GOTO ExitLabel1
Exception1:
BEGIN
DEALLOCATE cursor_for_inline_select1
return 0
/* SwisSQL (Oracle To SQL Server) : Manual Intervention to verify Exception is required */
END
ExitLabel1:
return @v_result
END
GO
########################################################################################################
edit:for further details look into this question
精彩评论