Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculated Field
Message
 
 
To
14/07/2011 15:30:54
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01518145
Message ID:
01518179
Views:
38
>>>>So, I recommend to lean towards stored procedures for complex logic and not try to abuse functions (although, of course, they do have their place).
>>>
>>>so are you saying the code I wrote would work in an SP?
>>
>>I haven't studied your code in details, but generally, yes.
>
>:)
>
>I hope that someone can look at my code, because I'm stuck
>
>
CREATE PROCEDURE GetClaimStatus 
>	-- Add the parameters for the stored procedure here
>	@Clm_PK UNIQUEIDENTIFIER,
>	@Status INT OUTPUT
>AS
>BEGIN
>	-- SET NOCOUNT ON added to prevent extra result sets from
>	-- interfering with SELECT statements.
>	SET NOCOUNT ON;
>
>    -- Insert statements for procedure here
>	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)
>
>/* I don't know how to implement the logic:						
>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 */
>			
>    RETURN @Status 
>END
>GO
Post your create table statements and insert statements.

But basically, it's something like
select @Status = case when exists (select 1 from ClaimItems where ClaimID = @Clm_PK 
and ClaimDate > dateadd(day, -1*@DayLimit, CURRENT_TIMESTAMP) 
                                        then 'Overdue' 
                          when exists (select 1 from ClaimItems where ClaimID = @Clm_PK and Status <> 'Settled') 
                                     then 'Pending' 
                          ELSE 'Settled' END
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