Unix Technical Forum

How to find records with length greater than 17

This is a discussion on How to find records with length greater than 17 within the SQL Server forums, part of the Microsoft SQL Server category; --> how do i write sql statment to find records with name greater than 17 characters....


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-24-2008, 07:07 PM
ciojr@yahoo.com
 
Posts: n/a
Default How to find records with length greater than 17

how do i write sql statment to find records with name greater than 17
characters.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-24-2008, 07:07 PM
Plamen Ratchev
 
Posts: n/a
Default Re: How to find records with length greater than 17

The LEN function returns the number of characters excluding trailing blanks:

SELECT namecol
FROM Foo
WHERE LEN(namecol) > 17;

The DATALENGTH function returns the number of bytes.

HTH,

Plamen Ratchev
http://www.SQLStudio.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-24-2008, 07:07 PM
John Sheppard
 
Posts: n/a
Default Re: How to find records with length greater than 17


"Plamen Ratchev" <Plamen@SQLStudio.com> wrote in message
news:t9ednRsfVu9McZHVnZ2dnUVZ_jSdnZ2d@speakeasy.ne t...
> The LEN function returns the number of characters excluding trailing
> blanks:
>
> SELECT namecol
> FROM Foo
> WHERE LEN(namecol) > 17;
>
> The DATALENGTH function returns the number of bytes.
>
> HTH,
>
> Plamen Ratchev
> http://www.SQLStudio.com


Wouldnt it matter if the field was in unicode then? What do you do if you
want to include the spaces?

I dont really want to know I just thought it weird that len would behave
like that...(Im an SQL server noob)

John Sheppard


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-24-2008, 07:07 PM
Plamen Ratchev
 
Posts: n/a
Default Re: How to find records with length greater than 17

There is no difference when you use LEN with Unicode column. If you need to
include the spaces you can use DATALENGTH. The only considerations is that
it returns number of bytes, so for NVARCHAR/NCHAR/NTEXT will return double
the length.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-24-2008, 07:07 PM
ciojr@yahoo.com
 
Posts: n/a
Default Re: How to find records with length greater than 17

On Apr 21, 3:36*pm, "Plamen Ratchev" <Pla...@SQLStudio.com> wrote:
> The LEN function returns the number of characters excluding trailing blanks:
>
> SELECT namecol
> FROM Foo
> WHERE LEN(namecol) >17;
>
> The DATALENGTH function returns the number of bytes.
>
> HTH,
>
> Plamen Ratchevhttp://www.SQLStudio.com


Right - i dont want to include spaces.
I want to check where the first word is greater than 17
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-24-2008, 07:07 PM
Gert-Jan Strik
 
Posts: n/a
Default Re: How to find records with length greater than 17

ciojr@yahoo.com wrote:
>
> On Apr 21, 3:36 pm, "Plamen Ratchev" <Pla...@SQLStudio.com> wrote:
> > The LEN function returns the number of characters excluding trailing blanks:
> >
> > SELECT namecol
> > FROM Foo
> > WHERE LEN(namecol) >17;
> >
> > The DATALENGTH function returns the number of bytes.
> >
> > HTH,
> >
> > Plamen Ratchevhttp://www.SQLStudio.com

>
> Right - i dont want to include spaces.
> I want to check where the first word is greater than 17


It won't do that. For example, the query above will also select the row
where namecol has a value of 'John Smithersonson'

So if Plamen's solution does not do what you want, then please some
example data and desired output.

--
Gert-Jan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:43 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com