demo for UPDATE query 8108798

0

Please login or register to vote for this query.

(click on this box to dismiss)

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

CREATE TABLE #TableX(
 ord INT PRIMARY KEY
,name NVARCHAR(255));


INSERT INTO #TableX VALUES
 (3    ,'John')
,(5    ,'Mary')
,(8    ,'Michael')
,(10   ,'Steve')
,(13   ,'Jack')
,(20   ,'Peter')



UPDATE #TableX
SET ord = ( SELECT MIN(ord)+MAX(ord) 
            FROM #TableX 
            WHERE name IN ('Peter', 'Steve')
          ) - ord
WHERE name IN ('Peter', 'Steve')


SELECT * FROM #TableX

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results