• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • 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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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