How to convert select statement to an update statement
I'm trying to create an Update statement that works or functions the same as this Select statement: SELECT * FROM table WHERE field1 = 1 AND field2 NOT IN (SELECT field2 FROM table WHERE field1 = 0)
The translation from select to update is very simple in this case as it doesn't require SQL Server's non standard proprietary update syntax. UPDATE table SET field3 = 'X' WHERE field1 = 1 AND field2 NOT IN (SELECT field2 FROM table WHERE field1 = 0) Another way of translating it would be to just put the whole select statement inside a cte and update that. WITH t AS (SELECT * FROM table WHERE field1 = 1 AND field2 NOT IN (SELECT field2 FROM table WHERE field1 = 0)) UPDATE t SET field3 = 'Y' If any of the columns involved are nullable not exists will likely have a better plan though.
UPDATE [Table1] SET [Column1] = ? ,[Column2] = ? --,... other columns and so on.... WHERE field1 = 1 AND NOT EXISTS (SELECT 1 FROM Table2 WHERE field1 = 0 AND Field2 = [Table1].Field2 )
Calculate diffrences between values from diffrent rows in SQL
Automate Data Feeds challenges
How to select rows as a column for View in TSQL?
How to deploy Asp.net MVC4 websit with MSSQL database?
Export Data to Flat File using SSIS Package
SQL Server stored procedure with/without linkserver to self give different result
Insert records to a table with loop from an other table data
SQL Server 2008 - How to fill blank rows with data in other rows (either before or after blank rows)
Cannot create an instance of OLE DB provider “Microsoft.ACE.OLEDB.12.0” for linked server “ATTENDANCERecord”
How to Convert DATETIME to CHAR in MS SQL
Group by using MAX()
How can I get the most recent unique record out of a table not in 1NF?
Want to calculate difference record count in SQL Server 2008
SQL Server 2008 : Where Clause with And Or
Stored Procedure to send different email content to different contacts when it is 30 days before the finish date
SQL Server where clause not working on nvarchar column after database recovery