Link to home
Start Free TrialLog in
Avatar of Andrew
AndrewFlag for United States of America

asked on

UPDATE JOIN multiple tables

Hello,

I am trying to update [SeedTracker].[dbo].[DBLogNonResInt].Cassava (bit datatype) from a bit value from another table [SeedTracker].[dbo].[Location].Cassava joined by DBLogNonResint.Location = Location.Description.  If the value in Location.Cassava is True then update the DBLogNonResInt.Cassava to True otherwise update to FALSE.

My latest failed attempt:

UPDATE
[SeedTracker].[dbo].[DBLogNonResInt]
SET
Cassava = 0.0160
FROM
[SeedTracker].[dbo].[DBLogNonResInt] nr
INNER JOIN
[SeedTracker].[dbo].[Location] l
ON
nr.Location = l.[Description]
WHERE
l.Cassava = 1

Open in new window

User generated imageUser generated image
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andrew

ASKER

Excellent!  Thank you!  I was making it much tougher than what it really was like usual.
sorry, forgot the "false" part. try this:

UPDATE [SeedTracker].[dbo].[DBLogNonResInt]
SET [SeedTracker].[dbo].[DBLogNonResInt].Cassava=
        (
            CASE
                WHEN
                    (t2.Cassava=True)
                THEN
                    t2.Cassave
                ELSE
                    False
            END
        )
FROM [SeedTracker].[dbo].[Location] as t2
WHERE [SeedTracker].[dbo].DBLogNonResint.Location = t2.Description

Open in new window

Avatar of Andrew

ASKER

It's ok, I got it. Thanks!
or

UPDATE [SeedTracker].[dbo].[DBLogNonResInt]
SET [SeedTracker].[dbo].[DBLogNonResInt].Cassava=
        (
            CASE (t2.Cassava)
                    WHEN TRUE THEN t2.Cassava
                ELSE
                    False
            END
        )
FROM [SeedTracker].[dbo].[Location] as t2
WHERE [SeedTracker].[dbo].DBLogNonResint.Location = t2.Description

Open in new window