How do I compare two columns for equality in SQL Server?

后端 未结 7 1036
忘掉有多难
忘掉有多难 2020-12-06 04:15

I have two columns that are joined together on certain criteria, but I would also like to check if two other columns are identical and then return a bit field if they are.

7条回答
  •  日久生厌
    2020-12-06 04:24

    What's wrong with CASE for this? In order to see the result, you'll need at least a byte, and that's what you get with a single character.

    CASE WHEN COLUMN1 = COLUMN2 THEN '1' ELSE '0' END AS MyDesiredResult
    

    should work fine, and for all intents and purposes accomplishes the same thing as using a bit field.

提交回复
热议问题