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 2005 Forums
 Transact-SQL (2005)
 length of string

Author  Topic 

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2008-01-15 : 04:30:04
Hi

I want to get i.e. 70% of the len of a string in a round amount.

i.e. select 'testing123',round((len('testing123')/100 * 70),0) as length_threshold

should return: testing123, 7

But with this code I only return 0.

I need the length_Threshold to be a whole number

Can anybody help?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-15 : 04:31:03
/100.0


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-15 : 04:38:06
select 'testing123', round((len('testing123') * 0.70), 0)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2008-01-15 : 05:09:21
Also remember that the len function ignores trailing spaces.

See what happens with this:

select 'How long is 70% of a piece of string', round((len('How long is 70% of a piece of string') * 0.70), 0)
select 'How long is 70% of a piece of string ', round((len('How long is 70% of a piece of string ') * 0.70), 0)



Duane.
Go to Top of Page

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2008-01-15 : 05:27:13
excellent, many thanks all!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-16 : 01:40:43
In case if you want to consider trailing sapces, use DATALENGTH instead on LEN

Madhivanan

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

- Advertisement -