Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for Invalid Values in a Column

Status
Not open for further replies.

drallabs

Technical User
Mar 2, 2006
28
US
I would like to find the following occurences of invalid values in a field.

The first occurence is I have a field that limits the number of characters to 7. However users sometimes enter values in this field that are 6 characters or less. Is there a way to query these out?

The second occurence is users may enter lower case characters, in the field mentioned above, when they should in fact be capitalized. Is there a query to find these lower case characters?

Thanks.
 
Code:
declare @Temp Table(Data varchar(7))

Insert Into @Temp Values('ABCDEFG')
Insert Into @Temp Values('ABCDeFG')
Insert Into @Temp Values('ABCDEF')

Select * 
From   [!]@Temp [/!]
Where  Len([!]Data[/!]) <> 7
       Or Convert(VarBinary(100), Upper([!]Data[/!])) <> Convert(VarBinary(100), [!]Data[/!])

If you are satisfied with this functionality, you will need to change the table name and the column name (highlighted in red)

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top