Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

CASE statement in a JOIN\UPDATE statement

$
0
0

I have two statements one for the "BatchNo = 110 case and another for the "not 110" case.  I'm trying to combine these into a single CASE statement but can't get the syntax right. Any help appreciated.

TIA,

edm2

UPDATE t1
  SET t1.CalculatedColumn = t2.[MyCalc]
  FROM dbo.Table1 AS t1
  INNER JOIN dbo.Table2 AS t2
  ON t1.CommonField = t2.[Common Field]
  WHERE t1.BatchNo = '110';

 

UPDATE t1
  SET t1.CalculatedColumn = t2.[MyCalc] + 1
  FROM dbo.Table1 AS t1
  INNER JOIN dbo.Table2 AS t2
  ON t1.CommonField = t2.[Common Field]
  WHERE t1.BatchNo != '110';


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>