Hi I was wodering how to add an OR statment right in the Check Constraint expression.
This is what I am starting with in the database
([zip] like '[0-9][0-9][0-9][0-9][0-9]')
and what I want well not exact but this would answer my question
([zip] like '[0-9][0-9][0-9][0-9][0-9] || [A-Z][A-Z][A-Z][A-Z][A-Z]')
Thanks for any help
Maybe will be better if you will check if value is numeric instead of using very big LIKE for numeric part ?
where ISNUMERIC(zip)=1
or zip like '[A-Z][A-Z][A-Z][A-Z][A-Z]'
if should be all you need if size of your field is 5 char long.
|||Thanks for looking in on me but this
([zip] like '[0-9][0-9][0-9][0-9][0-9] || [A-Z][A-Z][A-Z][A-Z][A-Z]')
is just an example
What I really want to know is can I use an OR or an AND in
Check Constraint expression area
Thanks
|||so probably you can put something like this in constrain expression
[zip] like '[0-9][0-9][0-9][0-9][0-9]'
or zip like '[A-Z][A-Z][A-Z][A-Z][A-Z]'
you can also create function and check its result
it should return bool value
dbo.checkZIPFormat(zip)
or you have to test the result
dbo.checkZIPFormat(zip) = 1 (if function returns 1 when ZIP is valid)
|||Hi thanks again for checking. The problem lies in the database not in the code. It is in the Constraints part of the table. I can change this but no matter what I do with the code it will not let in any thing that does not match the expression right in the data base. I can even delete this out and write my own code but thats not whats required. I need to be able to have it check for [0-9][0-9][0-9][0-9][0-9] OR [A-Z][A-Z][A-Z][A-Z][A-Z]
Thank again
Mike
|||Hi JPazgier, I have figured it out you would do somthing like
([zip] like '[0-9][0-9][0-9][0-9][0-9]' OR [zip] like '[A-Z][A-Z][A-Z][A-Z][A-Z]')
Thanks Again
Mike