Home > database >  Without the while how to do??
Without the while how to do??

Time:04-10

 
/*
Compared to the number of records in two tables are consistent, not while, how to do? Horse to the update list of is_ok field is' y '
*/

IF OBJECT_ID (' tempdb for. Dbo. # out ') IS NOT NULL
DROP TABLE # out
The CREATE TABLE # out (code VARCHAR (10), price, NUMERIC (18, 2), the amount INT, is_ok VARCHAR (1) the DEFAULT 'n')
INSERT INTO # out (code, price, amount)
SELECT the 'A', 10, 20 UNION ALL
SELECT the 'A', 10, 20 UNION ALL
SELECT the 'A', 11, 20 UNION ALL
SELECT the 'A', 11, 30 UNION ALL
SELECT the 'A', 12, 40 UNION ALL
SELECT the 'A', 12, 20

IF OBJECT_ID (' tempdb for. Dbo. # in ') IS NOT NULL
DROP TABLE # in
The CREATE TABLE # (in code VARCHAR (10), price, NUMERIC (18, 2), the amount INT, is_ok VARCHAR (1) the DEFAULT 'n')
INSERT INTO # (in code, price, amount)
SELECT the 'A', 10, 10 UNION ALL
SELECT the 'A', 10, 10 UNION ALL
SELECT the 'A', 10, 20 UNION ALL
SELECT the 'A', 11, 10 UNION ALL
SELECT the 'A', 11, 10 UNION ALL
SELECT the 'A', 11, 15 UNION ALL
SELECT the 'A', 12, 40 UNION ALL
SELECT the 'A', 12, 20

CodePudding user response:

 


The update table to modify the set data from field=change
Need to modify the inner table of the join on the source data,,,,,,,,,,
The where condition,,,,,,,,,

  • Related