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!

SQL Field - check for specific count of characters 1

Status
Not open for further replies.

JD5241

Technical User
Jan 17, 2005
154
US
I have a field in a SQL table that allows a max of 3 characters (string). For business reasons we only use up two characters. Every once in a while a user will make a typing error that puts 1 or 3 characters in that field. I'd like to be able to see when that condition exists with a query.
I don't have a mechanism to flag it on the front side so the user can correct it immediately.

My SQL is very rusty and I haven't been able to find anything through web searches or going through this site that does what I'm looking for.

Basic logic: if field_1 contains 2 characters, don't include in the results. If field_1 contains other than 2 characters, include in the results.

Just a simple select statement that will show that data. If anyone could help me with this, I'd greatly appreciate it. Thank you!
 
Look at LEN function

Pretty much:[tt]
Select field_1, LEN(field_1) As LEN_of_field_1
From MyTable
Where LEN(field_1) <> 2[/tt]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
I tried that initially, but I had the syntax incorrect, that works now. Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top