With SQL Server 2012, I have two columns that I would like to compare. Both are on the same table, so no joins are needed.
Basically I need to compare two columns, for example scan1
and scan2
and if their value's match, then I need a 1
, else 0
. The results of the match would output to AS Results.
诸如SELECT .... , CASE WHEN scan1 = scan2 THEN 1 ELSE 0 END AS is_equal FROM table1
应该SELECT .... , CASE WHEN scan1 = scan2 THEN 1 ELSE 0 END AS is_equal FROM table1
。
You can go like:
SELECT CASE WHEN Scan1 = Scan2 THEN 1
ELSE 0 END AS ColumnAlias
FROM YourTable
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.