How to create conditional uniqe constraint on SQL Server 2005
===

Having a table:`Table1` in which a column `Code` accepts nullables values how can we insure that values are unique for non nullable values except for codes that start with `'A'` which can be duplicated maximum twice?

**Table1**

    
    Id |  Code
    ---------- 
    1  |  NULL   [ok]
    2  |  A123   [ok]
    3  |  A123   [ok]
    4  |  B100   [ok] 
    5  |  C200   [ok]
    6  |  B100   [not ok alerady used]
    7  |  NULL   [ok]

What i have tried is creating an indexed view, the solution work fine for `NULL` values but not for the second case i mentioned (skipped actualy)

    Create view v_Table_unq with schemabinding as( 
    select code from dbo.Table1 where code is not null and code not like 'A%'
    )
    go
    create unique clustered index unq_code on v_Table_unq(code)
Thanks for help