Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calculated Field
Message
 
 
À
14/07/2011 15:30:54
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01518145
Message ID:
01518179
Vues:
39
>>>>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform