Update a table based on a value from another table..

Posted on 2009-12-22
Last Modified: 2012-05-08
Could you suggest a way to do the following scenario:

DML TableA
only when these 2 conditions are false:
*Max(Updatedate) of TableB is before yesterday.(for example, if today is 5th of the month, Max(Updatedate) should be 3rd or before)
*Min(updatedate) of TableA should not be today or yesterday

There is no key between TableA and TableB.

Question by:anushahanna
    LVL 35

    Expert Comment

    write a stored procedure, simple query won't work
    LVL 5

    Expert Comment

    which table are you updating a 3rd table?
    can you explain a bit more?

    LVL 35

    Accepted Solution

    inside your stored procedure you could do something like that:

    DECLARE @dtMax as Datetime
    DECLARE @dtMin as Datetime

    SELECT @dtMax=MAX(Updatedate) FROM TableB

    SELECT @dtMin=MIN(Updatedate) FROM TableA

    IF @dtMax < DATEADD(day,-1,GETDATE())
          IF @dtMin <> GETDATE()
                IF @dtMin <> DATEADD(day,-1,GETDATE())
                      --update TableA here
                                                                    UPDATE TableA SET ......



    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
    Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now