Whitespace problem in Check Constraint

  • I have a table called IntNotes that including column Key,Notes,Keytable and few others.

    Key is Primary Key.

    Notes - Nvarchar(max),not null)

    I have a check constraint on Notes column.

    ALTER TABLE [dbo].[IntNotes] WITH NOCHECK ADD CHECK ((NOT [Notes] like '' AND NOT [Notes] like ' %' AND NOT [Notes] like '% ')).

    But when i am adding following values getting error

    "Error occured storing IntNotes data, the Violated constraints follows.[Notes] like '' AND NOT [Notes] like ' %' AND NOT [Notes] like '% "

    Value

    KeyTable = 881

    Key =2250

    Notes = 'Received signed 3yr contract priced at $12500/13500/14250. please send invoice for $12,500'.

    Can anyone suggest me what steps should i have to follow?

    Thanks you

  • i think you want something more like this: the field cannot be trimmed to equal whitespace, and must have at least a letter or number in it

    ALTER TABLE [dbo].[IntNotes] WITH NOCHECK

    ADD CHECK (NOT LTRIM(RTRIM([Notes])) = ''

    AND [Notes] like '%[^a-z,A-Z,0-9]%')

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

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

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