user image

AKY King of Life
Published in : 2022-03-02

Convert Stored Procedure of Oracle to SQL Server

General

I have a stored procedure which is compiled and stored in an Oracle database. I want to convert and then run this stored procedure in SQL Server.

Here is the stored procedure in Oracle - how to convert this code to SQL Server to run on this ?

create or replace PROCEDURE "SP_ora" (
IN_CD IN NUMBER,
IN_LOCAL IN NUMBER,
IN_INI IN  VARCHAR2,
IN_FIN IN   VARCHAR2,
cv_1 OUT SYS_REFCURSOR)
AS
V_INI1 VARCHAR2(30);
V_FIN1 VARCHAR2(30);
V_INI2 TIMESTAMP;
V_FIN2 TIMESTAMP;
V_LOCAL NUMBER(5);
BEGIN
 IF IN_LOCAL=0 THEN
  V_LOCAL := null;
 ELSE
  V_LOCAL:=IN_LOCAL;
 END IF;

 IF IN_INI IS NOT NULL THEN
  V_INICIO2 := TO_TIMESTAMP(CONCAT(IN_INI, ' 00:00:00'), 'dd/MM/yy 
  HH24:MI:SS');
 END IF;

 IF IN_FIN IS NOT NULL THEN
  V_FIN2 := TO_TIMESTAMP(CONCAT(IN_FIN, ' 23:59:59'), 'dd/MM/yy HH24:M 
  I:SS');
 END IF;

OPEN cv_1 FOR
SELECT TB_LOG_E.FE_FLAG2 AS fecha,
TB_HEAD_PPL.GLS_STORE
|| '-'
|| TB_STORE_INFO.STORE_NAME               AS CD,
TB_HEAD_PPL.FOLIO_PPL_SII                 AS guia,
TB_FOLIO_PPL_COD_VISACION.CODIGO_VISACION AS cod_visacion
FROM TB_HEAD_PPL
INNER JOIN TB_LOG_EJECUCION ON TB_HEAD_PPL.ID_HEAD_PPL =  
TB_LOG_EJECUCION.ID_HEAD_PPL AND TB_HEAD_PPL.ID_CD_NBR  = 
TB_LOG_EJECUCION.ID_CD_NBR
LEFT JOIN TB_FOLIO_PPL_COD_VISACION ON TB_HEAD_PPL.FOLIO_PPL_SII = 
TB_FOLIO_PPL_COD_VISACION.FOLIO_SII
INNER JOIN TB_STORE_INFO ON TB_HEAD_PPL.GLS_STORE = TB_STORE_INFO.STORE_NBR
LEFT JOIN TB_DETAIL_PPL D ON TB_HEAD_PPL.ID_HEAD_PPL = D.ID_HEAD_PPL
LEFT JOIN tb_item i ON D.GLS_ITEM_NBR = i.ITEM_NBR
where TB_LOG_EJECUCION.FECHORA_FLAG02 BETWEEN NVL(V_INICIO2, 
TB_LOG_EJECUCION.FECHORA_FLAG02) AND NVL(V_FIN2, 
TB_LOG_EJECUCION.FECHORA_FLAG02)
AND TB_HEAD_PPL.ID_CD_NBR = IN_CD AND TB_HEAD_PPL.GLS_STORE = NVL(V_LOCAL, 
TB_HEAD_PPL.GLS_STORE)
AND i.ITEM_DEPT_NBR = 83 and D.GLS_PRODUCTION_LOT_NUMBER is not null
GROUP BY TB_LOG_EJECUCION.FECHORA_FLAG02,
TB_HEAD_PPL.GLS_STORE
|| '-'
||  TB_STORE_INFO.STORE_NAME,
TB_HEAD_PPL.FOLIO_PPL_SII,
TB_FOLIO_PPL_COD_VISACION.CODIGO_VISACION
ORDER BY fecha;
END;

Comments

Shilpa Date : 2022-03-02

Best answers

10

Best answers

10

[Possible Duplicate]

You can find whole converted stored procedure according to your question IN THIS THREAD.

 

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

Choose default editor from filezilla on Ubuntu
Publish date: 2022-02-28 | Comments: 4

Tag: General

Select from a query with peewee
Publish date: 2022-03-05 | Comments: 0

Tag: General

Unable to Connect AWS EC2 Instance with my subdirectory through domain registrar.
Publish date: 2022-02-25 | Comments: 2

Tag: General

[solved] Unable to pull updates from git "sudo git pull"
Publish date: 2021-12-20 | Comments: 1

Tag: General

Password authentication is temporarily disabled as part of a brownout.
Publish date: 2021-07-28 | Comments: 2

Tag: General

Keycloak db query in source codes [closed]
Publish date: 2022-03-05 | Comments: 0

Tag: General

Help with sliding an image from the top of a stack
Publish date: 2022-02-12 | Comments: 1

Tag: General