Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Simple question: the LEN function

Author  Topic 

jeroena
Yak Posting Veteran

76 Posts

Posted - 2002-10-18 : 08:20:02
Hi,

What is the best alternative for this:

SELECT @l_len = LEN(@p_param)

where @p_param equals 'HELLO WORLD '

The problem is that LEN trims the right spaces. I need the length of the string including the spaces.

I use this now:

LEN(REVERSE(@p_param)) because I know the 1st character never is a space. I can imagine this is not very efficient. It's ugly anyway...

Thnx! Spike.

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-10-18 : 08:27:03
Hi

Try the DATALENGTH() function. That will count whitespace as well.

Damian
Go to Top of Page

jasper_smith
SQL Server MVP & SQLTeam MVY

846 Posts

Posted - 2002-10-18 : 08:29:03
Use DATALENGTH


HTH
Jasper Smith
Go to Top of Page

jeroena
Yak Posting Veteran

76 Posts

Posted - 2002-10-18 : 08:34:41
Same answer twice! this must be correct! Thnx. Missed it in the docs, sorry.

Spike.

Go to Top of Page

jeroena
Yak Posting Veteran

76 Posts

Posted - 2002-10-18 : 08:50:50
btw. if some microsoft dude is reading this:

Would it be too much trouble to insert a bloody link to the DATALENGTH function in de the LEN function documentation?

gjeeez.

Spike.

Go to Top of Page
   

- Advertisement -