Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2008, 03:21 AM
Authorized User
 
Join Date: May 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default Function used in procedure

Hi all,

I am using a function to reterive the Account no ( total account no count 30,000) and use the account for some other processing in the Stored proc - my doubt is will function gives performnace hit in the SP or instead of using the function what is the other option pls let me know...... here is my SP

CREATE PROCEDURE [dbo].uspGenerateAccount
SELECT
AccountId ,
dbo.fnFYear(AccountId,getdate()) as RYear,
INTO #TempTable
FROM
tblAccounts AP
WHERE NOT Exists ( SELECT
1
FROM
tblClist CL
WHERE
CL.AccountNumber = AP.AccountId
AND
CL.RYear = dbo.fnFYear(AP.AccountId,getdate())



INSERT INTO
CList
(
AccountNumber
,RYear
,AReminder
)
SELECT
AccountID
,RYear
,1
FROM
#TempTable
.
..
..
...
and the function is
ALTER FUNCTION dbo.fnFYear(@AccountID int, @CurrentDate datetime)
RETURNS INT

AS
BEGIN

DECLARE @FiscalYearEnds varchar(5)
DECLARE @FiscalYear INT


SET @FiscalYearEnds='12/31' --DEFAULT YEAR END


SELECT
@FiscalYearEnds = CASE WHEN FiscalYearEnds is NULL
THEN cast(month(max(Statementdate)) as varchar) + '/'
+ cast(day(max(Statementdate)) as varchar)


WHEN ltrim(rtrim(FiscalYearEnds))=''
THEN
cast(month(max(Statementdate)) as varchar) + '/'
+ cast(day(max(Statementdate)) as varchar)


ELSE
ltrim(rtrim(FiscalYearEnds))
END
FROM
Statement st
INNER JOIN
vwOrganization vw
ON
st.fkPartyID = vw.PartyID
WHERE
vw.AccountID = @AccountID
and fkStatusCodeID = 1 ---Fiscal
GROUP BY FiscalYearEnds

SELECT @FiscalYearEnds = dbo.fnValidFYE(@FiscalYearEnds)

IF @CurrentDate > DATEADD(DAY,1,CAST(YEAR(@CurrentDate) -1 as varchar(4)) + '/' + @FiscalYearEnds)
and
@CurrentDate < DATEADD(DAY,1,CAST(YEAR(@CurrentDate) as varchar(4)) + '/' + @FiscalYearEnds)

SET @FiscalYear= CAST(YEAR(@CurrentDate)-1 AS INT)
ELSE
SET @FiscalYear= CAST(YEAR(@CurrentDate) AS INT)

RETURN @FiscalYear

END


 
Old February 13th, 2008, 05:10 AM
Friend of Wrox
 
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

It is diffcult to understand output of your function, please specify what is an aim of your function and whether it queries database or not.

According to me if function is againg querying any huge table then this may ruin performance.

urt

Help yourself by helping someone.
 
Old February 13th, 2008, 05:21 AM
Authorized User
 
Join Date: May 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

urtrivedi,
U didnt understand my function ???? It queries the DB manipulate the with the Date and returns FiscalYear like '2007'. My question is because of the performance issue i asked is there anyother way strip out the function from the procedure, i you have anyother solution please provide.

 
Old February 13th, 2008, 05:23 AM
Friend of Wrox
 
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

According to me if function is again querying any huge table then this may ruin performance.



urt

Help yourself by helping someone.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Function Procedure reneemettrie Excel VBA 0 June 13th, 2008 11:06 AM
Procedure or function has too many arguments Raby VB Databases Basics 6 November 16th, 2007 11:38 AM
Function and Procedure code_lover Oracle 2 July 24th, 2007 07:05 AM
Procedure or function STOREDPROC has too man rit01 ASP.NET 2.0 Basics 4 January 25th, 2006 09:51 AM
Analytical function and stored procedure akmhasan Oracle 2 November 14th, 2003 01:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.