Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculated Field
Message
From
14/07/2011 14:58:13
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01518145
Message ID:
01518166
Views:
37
>>Hi Naomi,
>>
>>I've created the Numbers table and the Calendar table along with functions to GetWorkingDays and ClaimItemStatus. Now I'm stuck on the last function to get the ClaimStatus based on these rules:
>>
>>1. If any Claim Items are Overdue, then Claim is Overdue
>>2. Else If all Claim Items are Settled, then Claim is Settled
>>3. Otherwise Status is Pending
>>
>>Here is what I have attempted:
>>
>>
CREATE FUNCTION dbo.ClaimStatus
>>( 
>>    @Clm_PK UNIQUEIDENTIFIER
>>) 
>>RETURNS INT 
>>AS 
>>BEGIN
>>	DECLARE @Status INT
>>	DECLARE @DayLimit INT
>>	DECLARE @Cli_PK UNIQUEIDENTIFIER
>>	
>>	SET @Status = 1 /* Pending */
>>	SET @Cli_PK = (SELECT clm_clifk FROM Claims WHERE clm_pk = @Cli_PK)
>>	
>>	SET @DayLimit = (SELECT com_OverDueDays 
>>					FROM Companies 
>>						INNER JOIN Clients ON com_pk = cli_comfk
>>							WHERE cli_comfk = @Cli_PK)
>>							
>>	SELECT CIT_PK
>>			,dbo.GetClaimItemStatus(clm_Forwarded, cit_received, @DayLimit)
>>		FROM ClaimItems	
>>			INNER JOIN Claims ON cit_clmfk = clm_pk
>>			WHERE cit_clmfk = @Clm_PK
>>			
>>    RETURN @Status 
>>END 
>>GO
>>
>>The problem I have is that I get Error Msg 444: Select statements included within a function cannot return data to a client which is due to my SELECT CIT_PK...
>>
>>How do I return that into a temporary table/cursor so that I can check the status of the claim items?
>
>It looks like you're overcomplicating the problem. I suggest to create a stored procedure rather than a function and do all the calculations there.

What's the difference between the SP and the function? The logic I need to apply will be the same in both, won't it?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform