• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

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

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.

Thanks
0
anushahanna
Asked:
anushahanna
  • 2
1 Solution
 
YZlatCommented:
write a stored procedure, simple query won't work
0
 
fhillyer1Commented:
which table are you updating a 3rd table?
can you explain a bit more?

please
0
 
YZlatCommented:
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())
BEGIN
      IF @dtMin <> GETDATE()
      BEGIN
            IF @dtMin <> DATEADD(day,-1,GETDATE())
            BEGIN
                  --update TableA here
                                                                UPDATE TableA SET ......
            END

      END

END
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now