2015年3月10日 星期二

msSQL2008 update .. select ..

  MERGE INTO 二廠物料請購單 T
   USING 二廠物料請購單2 S
      ON T.[訂單編號] = S.[訂購單號]
WHEN MATCHED THEN
   UPDATE
      SET [需求根據]=s.[備註];

MERGE INTO YourTable T
   USING other_table S 
      ON T.id = S.id
         AND S.tsql = 'cool'
WHEN MATCHED THEN
   UPDATE 
      SET col1 = S.col1, 
          col2 = S.col2;
 MERGE INTO YourTable T
   USING (
          SELECT id, col1, col2 
            FROM other_table 
           WHERE tsql = 'cool'
         ) S
      ON T.id = S.id
WHEN MATCHED THEN
   UPDATE 
      SET col1 = S.col1, 
          col2 = S.col2;

沒有留言:

張貼留言