Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedure slower than SQL in Query Analyzer???

Status
Not open for further replies.

synapsevampire

Programmer
Mar 23, 2002
20,180
0
0
US
If I take the following and make an SP out of it (pass a SSNo parm and add it to the where clause), it takes several minutes to run, if I run it in the query analyzer (with the SQL provided below), it returns immediately, any thoughts?

I can even remove the where clause and it takes forever, but if I hardcode a SSNo in the where, it returns immediately.

declare @SSNo char(12)

set @ssno = '550512771'

SELECT dbo.AtsPerss.chrSSNo, SUM(dbo.AtsPersAcctTransacts.mnyPersonalPreTax) AS PersonalPretax, SUM(dbo.AtsPersAcctTransacts.mnyPersonalPostTax)
AS PersonalPosttax, SUM(dbo.AtsPersAcctTransacts.mnyYmcaPreTax) AS Expr3, SUM(dbo.AtsPersAcctTransacts.mnyYmcaPostTax) AS Expr4,
SUM(dbo.AtsPersAcctTransacts.mnyMonthlyComp) AS Expr5
FROM dbo.AtsPersAcctTransacts LEFT OUTER JOIN
dbo.AtsParticipants ON dbo.AtsPersAcctTransacts.guiPersID = dbo.AtsParticipants.guiPersID LEFT OUTER JOIN
dbo.AtsPersAcctTransactFunding ON
dbo.AtsPersAcctTransacts.guiUniqueID = dbo.AtsPersAcctTransactFunding.guiPersAcctTransactID LEFT OUTER JOIN
dbo.AtsPerss ON dbo.AtsPersAcctTransacts.guiPersID = dbo.AtsPerss.guiUniqueID
WHERE (dbo.AtsPersAcctTransactFunding.guiUniqueID IS NULL) AND (dbo.AtsPerss.chrSSNo = @SSNo) AND
(dbo.AtsParticipants.dtsEligibilityDate IS NULL)
GROUP BY dbo.AtsPerss.chrSSNo kai@informeddatadecisions.com
 
Interesting ...
Have you tried declaring SSNo as Varchar instead of Char?
 
I rewrote the joins and it runs quickly now.

I was more curious if others had experienced SQL which runs faster in Query Analyzer than a SP, especially by such a dramatic margin.

-k kai@informeddatadecisions.com
 
Hi,

It is not exactly the same but we are having performance issues running stored procedures in scheduled jobs. Run in Query Analyser it takes seconds, run overnight as part of a schedule and it takes 50 time longer. We tried it in SQL 2000 and this seemed to be OK, we have now found that there is a fix in SP4 for SQL Server 7.0 that may correct this type of problem.
Hope this is useful.

Sue
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top