Skip to main content
added 9 characters in body
Source Link
surya
  • 31
  • 2

I want a stored procedure that retrieves ID and PID from the invoice table with batchid as input parameter and based on the retrieved PID I want to retrieve sid from the log table.
In total I want to retrieve 3 parameters - ID, PID and SID

I have written SP below but I think this can be optimized.Is there a way I can write this SP in MSSQL so that I don't have to query the invoice table twice.

CREATE OR ALTER PROCEDURE INVOICE_IDS(@BATCHID INT)
AS
BEGIN

SELECT ID, PID 
FROM INVOICE where BATCHID =@BATCHID;

SELECT SID FROM LOG WHERE PID in ( SELECT  PID 
FROM INVOICE where BATCHID =@BATCHID  );

END

I want a stored procedure that retrieves ID and PID from the invoice table with batchid as input parameter and based on the retrieved PID I want to retrieve sid from the log table.
In total I want to retrieve 3 parameters - ID, PID and SID

I have written SP below but I think this can be optimized.Is there a way I can write this SP so that I don't have to query the invoice table twice.

CREATE OR ALTER PROCEDURE INVOICE_IDS(@BATCHID INT)
AS
BEGIN

SELECT ID, PID 
FROM INVOICE where BATCHID =@BATCHID;

SELECT SID FROM LOG WHERE PID in ( SELECT  PID 
FROM INVOICE where BATCHID =@BATCHID  );

END

I want a stored procedure that retrieves ID and PID from the invoice table with batchid as input parameter and based on the retrieved PID I want to retrieve sid from the log table.
In total I want to retrieve 3 parameters - ID, PID and SID

I have written SP below but I think this can be optimized.Is there a way I can write this SP in MSSQL so that I don't have to query the invoice table twice.

CREATE OR ALTER PROCEDURE INVOICE_IDS(@BATCHID INT)
AS
BEGIN

SELECT ID, PID 
FROM INVOICE where BATCHID =@BATCHID;

SELECT SID FROM LOG WHERE PID in ( SELECT  PID 
FROM INVOICE where BATCHID =@BATCHID  );

END
added 90 characters in body
Source Link
surya
  • 31
  • 2

I want a stored procedure that retrieves ID and PID from the invoice table with batchid as input parameter and based on the retrieved PID I want to retrieve sid from the log table.
In total I want to retrieve 3 parameters - ID, PID and SID

I have written SP below but I think this can be optimized.Is there a way I can write this SP so that I don't have to query the invoice table twice.

CREATE OR ALTER PROCEDURE INVOICE_IDS(@BATCHID INT)
AS
BEGIN

SELECT ID, PID 
FROM INVOICE where BATCHID =@BATCHID;

SELECT SID FROM LOG WHERE PID in ( SELECT  PID 
FROM INVOICE where BATCHID =@BATCHID  );

END

I want a stored procedure that retrieves ID and PID from the invoice table with batchid as input parameter and based on the retrieved PID I want to retrieve sid from the log table.
In total I want to retrieve 3 parameters - ID, PID and SID

I have written SP below but I think this can be optimized

CREATE OR ALTER PROCEDURE INVOICE_IDS(@BATCHID INT)
AS
BEGIN

SELECT ID, PID 
FROM INVOICE where BATCHID =@BATCHID;

SELECT SID FROM LOG WHERE PID in ( SELECT  PID 
FROM INVOICE where BATCHID =@BATCHID  );

END

I want a stored procedure that retrieves ID and PID from the invoice table with batchid as input parameter and based on the retrieved PID I want to retrieve sid from the log table.
In total I want to retrieve 3 parameters - ID, PID and SID

I have written SP below but I think this can be optimized.Is there a way I can write this SP so that I don't have to query the invoice table twice.

CREATE OR ALTER PROCEDURE INVOICE_IDS(@BATCHID INT)
AS
BEGIN

SELECT ID, PID 
FROM INVOICE where BATCHID =@BATCHID;

SELECT SID FROM LOG WHERE PID in ( SELECT  PID 
FROM INVOICE where BATCHID =@BATCHID  );

END
edited tags
Link
surya
  • 31
  • 2
deleted 17 characters in body
Source Link
surya
  • 31
  • 2
Loading
deleted 120 characters in body
Source Link
surya
  • 31
  • 2
Loading
Source Link
surya
  • 31
  • 2
Loading