SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select where length of field = 5
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Stumbler
Starting Member

Belgium
23 Posts

Posted - 09/21/2007 :  06:26:03  Show Profile  Reply with Quote
I'm sure it is possible to select all records where the length of a given field equals a certain value, but I don't know how to do it?

Can somebody tell me how?

Hans

harsh_athalye
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 09/21/2007 :  06:32:10  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
Select * from table where datalength(field1) = 5


If it is CHAR field, trimming the field may be necessary.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 09/21/2007 :  06:44:44  Show Profile  Reply with Quote
You may also want select * frim where LEN(field1) = 5
Look up BOL for the difference between DATALENGTH AND LEN

select datalength(12356789) = 4
select len('123456789') = 9

Jim
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 09/21/2007 :  06:53:29  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Also note that any use of function over indexed column will force SCAN than SEEK

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Stumbler
Starting Member

Belgium
23 Posts

Posted - 09/21/2007 :  07:06:55  Show Profile  Reply with Quote
Thanks to you all for taking the time to answer my question

Hans
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000