kizziebutler
Programmer
I was wondering if the procedure below could be changed to improve the performance.
CREATE PROCEDURE spGetMailQueue (@CurrentDate datetime, @HOD varchar(3))
AS
CREATE TABLE #PrintQueue (QueueNo int primary key, PCDID int, Stationary varchar(50))
INSERT INTO #PrintQueue
SELECT tblCheque.ChqSerialNo as QueueNo, tblControl.PCDID, tblSystem.Stationary
FROM tblCheque, tblSystem, tblControl
WHERE tblCheque.PCDID = tblControl.PCDID
AND DatePart(d,SessionDate) = DatePart(d, @CurrentDate)
AND DatePart(m,SessionDate) = DatePart(m, @CurrentDate)
AND DatePart(yy,SessionDate) = DatePart(yy, @CurrentDate)
AND tblSystem.SystemID = tblControl.SystemID
AND tblSystem.HOD = @HOD
SELECT tblCheque.*, tblQueuePouch.PouchNo, tblControl.UserID,#PrintQueue.Stationary,tblControl.PCDID_Value
FROM tblCheque, tblQueuePouch, tblQueueMail, #PrintQueue, tblControl
WHERE tblQueuePouch.PCDID = #PrintQueue.PCDID
AND #PrintQueue.QueueNo >= tblQueueMail.RangeFrom
AND #PrintQueue.QueueNo <= tblQueueMail.RangeTo
AND tblQueueMail.QueuePouchID = tblQueuePouch.QueuePouchID
AND tblControl.PCDID = #PrintQueue.PCDID
AND tblCheque.ChqSerialNo = #PrintQueue.QueueNo
DROP TABLE #PrintQueue
GO
CREATE PROCEDURE spGetMailQueue (@CurrentDate datetime, @HOD varchar(3))
AS
CREATE TABLE #PrintQueue (QueueNo int primary key, PCDID int, Stationary varchar(50))
INSERT INTO #PrintQueue
SELECT tblCheque.ChqSerialNo as QueueNo, tblControl.PCDID, tblSystem.Stationary
FROM tblCheque, tblSystem, tblControl
WHERE tblCheque.PCDID = tblControl.PCDID
AND DatePart(d,SessionDate) = DatePart(d, @CurrentDate)
AND DatePart(m,SessionDate) = DatePart(m, @CurrentDate)
AND DatePart(yy,SessionDate) = DatePart(yy, @CurrentDate)
AND tblSystem.SystemID = tblControl.SystemID
AND tblSystem.HOD = @HOD
SELECT tblCheque.*, tblQueuePouch.PouchNo, tblControl.UserID,#PrintQueue.Stationary,tblControl.PCDID_Value
FROM tblCheque, tblQueuePouch, tblQueueMail, #PrintQueue, tblControl
WHERE tblQueuePouch.PCDID = #PrintQueue.PCDID
AND #PrintQueue.QueueNo >= tblQueueMail.RangeFrom
AND #PrintQueue.QueueNo <= tblQueueMail.RangeTo
AND tblQueueMail.QueuePouchID = tblQueuePouch.QueuePouchID
AND tblControl.PCDID = #PrintQueue.PCDID
AND tblCheque.ChqSerialNo = #PrintQueue.QueueNo
DROP TABLE #PrintQueue
GO