none
USP For 4 weeks

    Question

  • Using a Last Seen Date for an example
    I want to create a Procedure that calculates the last 4 weeks seen by getdate and if not seen in those weeks than false.

    Thank You in Advance



    • Edited by ODIAZ0305 Monday, August 26, 2013 2:37 PM
    Monday, August 26, 2013 2:36 PM

Answers

  • Hi ODIAZ0305,

    I think Sebastian gave us a great method, since we need to find the data values which older than 4 weeks, we just need to change ">=" as "<", for you convenience, I listed the codes here again.

    CREATE PROCEDURE FourWeeks @Flag BIT OUTPUT  
    AS  
    BEGIN  
    DECLARE @Count AS INT  
    SELECT @Count = COUNT(*) FROM YourTable WHERE YourDateField < DATEADD(d, -28, GETDATE())  
    IF @Count = 0 OR @Count IS NULL   
    SET @Flag = 0  
    ELSE  SET @Flag = 1 
    END  


    Allen Li
    TechNet Community Support

    Wednesday, August 28, 2013 1:47 AM

All replies

  • CREATE PROCEDURE FourWeeks @Flag BIT OUTPUT

    AS

    BEGIN

    DECLARE @Count AS INT

    SELECT @Count = COUNT(*) FROM YourTable WHERE YourDateField >= DATEADD(d, -28, GETDATE())

    IF @Count = 0 OR @Count IS NULL

    SET @Bit = 0

    ELSE

    SET @Bit = 1

    END


    Sebastian Sajaroff Senior DBA Pharmacies Jean Coutu

    Monday, August 26, 2013 2:42 PM
  • Thank you for the reply,

    Let me clarify it better

    Example:

    If a patient have not been seen in the last 4 weeks according to todays date.

    And if Todays date equals 4 weeks from the time seen or more

    Then False

    Thank you, 

    Monday, August 26, 2013 3:04 PM
  • Hi ODIAZ0305,

    I think Sebastian gave us a great method, since we need to find the data values which older than 4 weeks, we just need to change ">=" as "<", for you convenience, I listed the codes here again.

    CREATE PROCEDURE FourWeeks @Flag BIT OUTPUT  
    AS  
    BEGIN  
    DECLARE @Count AS INT  
    SELECT @Count = COUNT(*) FROM YourTable WHERE YourDateField < DATEADD(d, -28, GETDATE())  
    IF @Count = 0 OR @Count IS NULL   
    SET @Flag = 0  
    ELSE  SET @Flag = 1 
    END  


    Allen Li
    TechNet Community Support

    Wednesday, August 28, 2013 1:47 AM