Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculated Field
Message
 
 
To
14/07/2011 14:39:45
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01518145
Message ID:
01518164
Views:
43
>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.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform