By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,944 Members | 1,611 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,944 IT Pros & Developers. It's quick & easy.

How to add characters exactly 25

ddtpmyra
100+
P: 333
Here's my case...
I need to allocate exact 25 characters on a field. For instance the name is Lucy this means I have to add 21 extra spaces at the end.

How can I do that on my select statement?

Expand|Select|Wrap|Line Numbers
  1.  select name,25-LEN(name) as difference,
  2.  case when 
  3.  25-LEN(name)<25 
  4.  then 
  5.  ??????????
  6.  else 
  7.  ???????? end len
  8.  from person
Nov 1 '12 #1

✓ answered by ddtpmyra

OR....

Expand|Select|Wrap|Line Numbers
  1. Select UPPER(LEFT(name+space(25),25))

Share this Question
Share on Google+
4 Replies


ddtpmyra
100+
P: 333
I thought of this…

Adding 25 blank space at the end of the last_name and only select the 25 char from the left.

Expand|Select|Wrap|Line Numbers
  1. Select UPPER(LEFT(name+'                         ',25))
  2.  
Nov 1 '12 #2

ddtpmyra
100+
P: 333
OR....

Expand|Select|Wrap|Line Numbers
  1. Select UPPER(LEFT(name+space(25),25))
Nov 2 '12 #3

Rabbit
Expert Mod 10K+
P: 12,430
Or
Expand|Select|Wrap|Line Numbers
  1. [name] + SPACE(25-LEN([name]))
Nov 2 '12 #4

ck9663
Expert 2.5K+
P: 2,878
If the field "name" is a character and not a varchar, you might want to trim it first before adding any space.

Happy Coding!!!


~~ CK
Nov 2 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.