Converting a complex select query to an update query

I could use some assistance in converting the query below to an update query. It is too complex for Query Designer to help me convert it.

I am looking to update Itemsite table records.

Specifically the field  itemsite.User8 for every specific Invtid

With the value being returned by the query below as oa.InvcDate

Your assistance is greatly appreciated.

Select Query:

SELECT
      i.invtid
    , i.SiteID
    , oa.InvcDate
    , oa.ShipperID
FROM ItemSite i
OUTER APPLY (
            SELECT TOP (1)
                  b.InvcDate
                , a.ShipperID
            FROM SOShipLine a
               INNER JOIN SOShipHeader b ON a.shipperid = b.shipperid
                                        AND b.SOTypeID IN ('CS', 'SO')and b.Cancelled<>'1'
            WHERE a.InvtID = i.invtid
            ORDER BY a.ShipperID DESC
            ) OA
where i.SiteID='WEST' and OA.InvcDate<>''
ORDER BY i.invtid
armgonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
You didn't specify which column(s) you want to update, so replace ColumnName with the desired column name:
UPDATE ItemSite
SET ItemSite.ColumnName = R.ColumnName
FROM 
	(SELECT
       i.invtid
     , i.SiteID
     , oa.InvcDate
     , oa.ShipperID
	FROM ItemSite i
	OUTER APPLY (
		SELECT TOP (1)
			b.InvcDate
			, a.ShipperID
		 FROM SOShipLine a
			INNER JOIN SOShipHeader b ON a.shipperid = b.shipperid
				AND b.SOTypeID IN ('CS', 'SO')and b.Cancelled<>'1'
		 WHERE a.InvtID = i.invtid 
		 ORDER BY a.ShipperID DESC) OA 
	 where i.SiteID='WEST' and OA.InvcDate<>'') R
 WHERE ItemSite.invtid = R.invtid

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
armgonAuthor Commented:
Thanks for your prompt assistance. Very kind of you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.