November 7, 2006 at 3:47 am
In a stored procedure, when i use variable in the where condition of a query then the performance is very slow. But when i directly subtitute the values, the performance is really good
For eg:
declare @CompID varchar(16),@FinYr varchar(15),@JrlID varchar(10)
set @CompID='BM'
set @JrlID='CA_P'
set @FinYr='2006-2007'
Journal ON Trans_Header.CompanyID = Journal.CompanyID AND Trans_Header.Finyear = Journal.FinYear AND Trans_Header.JrlID = Journal.JrlID WHERE Trans_Header.CompanyID=@CompID and Trans_Header.Finyear=@FinYr and Journal.JrlID=@JrlID
WHen i substitute the variables as
Journal ON Trans_Header.CompanyID = Journal.CompanyID AND Trans_Header.Finyear = Journal.FinYear AND Trans_Header.JrlID = Journal.JrlID WHERE Trans_Header.CompanyID='BM' and Trans_Header.Finyear='2006-2007' and Journal.JrlID='ca_p'
November 7, 2006 at 3:56 am
What are the datatypes of the clumns:
"Varchar" is not an answer.
_____________
Code for TallyGenerator
November 7, 2006 at 4:29 am
The datatypes as
Trans_header.CompanyID -- varchar(16), Trans_header.Finyear -- varchar(15), Journal.JrlID -- varchar(10)
November 8, 2006 at 11:43 am
You may be running into a problem with Parameter Sniffing. Good details in this article:
As a workaround, you could try assigning some local variables with the values passed from the variables passed into the SP. I've seen it make a difference.
For example:
CREATE PROCEDURE sp_MyProc
@SPVAR VARCHAR(10)
AS
DECLARE @LOCALVAR VARCHAR(10)
SET @LOCALVAR = @SPVAR
SELECT... etc.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply