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
 Transact-SQL (2000)
 Len( ) Problem

Author  Topic 

MrEd
Starting Member

2 Posts

Posted - 2004-12-15 : 15:32:01
The below code returns a value of one. Can someone tell me why?


declare @sStg varchar
select @sStg = 'The length of this string is not one'

select len(@sStg)



X002548
Not Just a Number

15586 Posts

Posted - 2004-12-15 : 15:34:53
Did you try

SELECT @sStg

???????????

You need to supply a length



Brett

8-)
Go to Top of Page

MrEd
Starting Member

2 Posts

Posted - 2004-12-15 : 15:40:53
Okay so when I supply the length of the variable, the code returns 36, as it should. Hence, the below code returns 36.

declare @sStg varchar(500)
select @sStg = 'The length of this string is not one'
select len(@sStg)


Thanks for your quick reply and help.
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2004-12-15 : 15:59:19
If you don't supply a length in the variable definition, it defaults to a length of one.

e.g., declare @sStg varchar <==> declare @sStg varchar(1)



HTH

=================================================================

Happy Holidays!
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2004-12-15 : 16:13:44
And moved to the T-SQL forum...

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page
   

- Advertisement -