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>
>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 >thanks, that should get me going again