August 19, 2005 at 12:00 am
how to add spaces to a string?
August 19, 2005 at 12:37 am
U can add spaces to string by enclosing the spaces in the two single quotes. For eg
declare @str1 varchar(10)
set @str1 = 'abcdef'
select @str1 +' '+ 'ghi'
the spaces in the qutoes will be added to the string.
August 19, 2005 at 1:08 am
Adding to the answer above, I am taking a wild guess that you are looking for a way to pad a string with spaces to make it a fixed length. If so, here is an example of that:
DECLARE @string VARCHAR(10)
SET @string = 'abc'
PRINT @string + REPLICATE(' ', 10 - LEN(@string))
August 19, 2005 at 1:36 am
Following on from Chris, don't forget SPACE() to add a fixed number of spaces in a string
August 19, 2005 at 5:56 am
example of combining chris's solution with shawn's alternative would be:
DECLARE @string VARCHAR(10)
SET @string = 'abc'
PRINT SPACE(10 - LEN(@string)) + @string
**ASCII stupid question, get a stupid ANSI !!!**
August 19, 2005 at 10:56 pm
All good altrnatives but the easy way is to not use varchar. If you use Char(10) you know your string will always be 10 characters long.
Mike
August 20, 2005 at 6:32 am
Hard to answer that whern he doesn't tell where he wants the spaces.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply