Computed Column with bit data type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coder1234
    New Member
    • Sep 2007
    • 1

    #1

    Computed Column with bit data type

    I'm trying to create a computed column in a table in SQL Server 2005 and can't get the syntax right for the Formula.

    I want the computed column to be a bit data type which resolves to 1/0 (true/false) depending on the equality of 2 other fields which are of decimal type.

    I've tried put in ColA = ColB and [ColA] = [ColB] but no luck so far.

    Any ideas?
  • azimmer
    Recognized Expert New Member
    • Jul 2007
    • 200

    #2
    Originally posted by coder1234
    I'm trying to create a computed column in a table in SQL Server 2005 and can't get the syntax right for the Formula.

    I want the computed column to be a bit data type which resolves to 1/0 (true/false) depending on the equality of 2 other fields which are of decimal type.

    I've tried put in ColA = ColB and [ColA] = [ColB] but no luck so far.

    Any ideas?
    Try:
    Code:
    SELECT CASE WHEN ColA = ColB THEN 1 ELSE 0 END as myBit
    FROM ...

    Comment

    Working...