Unique Constraint on a SUBSTRING?

  • Anyone have any idea how to put a constraint on a table that requires a UNIQUE First Char in the column AND that it only has to be UNIQUE if another column is equal to 1?

    Well, that doesn't say it quite right. How about the following Data Set:

    Row1, Col1: Jane Smith

    Row1, Col2: 1

    Row2, Col1: Harry Belafonte

    Row2, Col2: 1

    Row3, Col1: Jesse Goodberry

    Row3, Col2: 2

    I don't want another 'J' or 'H' Name in the Column if the Col2 = 1

    I don't want another 'J' Name in the Column if the Col2 = 2,

    But Since I don't have an 'H' Name where Col2 = 2, then it would be okay until I did have one.

    That make sense?

    Phew...

  • If you're using SQL Server 2000, you could use a UDF in a check constraint. Otherwise you could use a trigger.

    --Jonathan



    --Jonathan

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply