Ask a Question related to Microsoft SQL / MS SQL Server, Design and Development.
-
Aaron Bertrand - MVP #1
Re: Right Justified
Probably something you should do at the client application. However, let's
say you want 30 spaces...
SELECT col = CONVERT(VARCHAR(30), RIGHT(REPLICATE(SPACE(1), 30) + 'foo',
30))
UNION ALL
SELECT RIGHT(REPLICATE(SPACE(1), 30) + 'foobario', 30)
I used the convert on the first result set to make the column 30 characters
wide in Query Analyzer. If you leave that out, you can use a variable for
the length. In fact, you could create a UDF to handle this pretty easily;
CREATE FUNCTION dbo.RightJustify
(
@str VARCHAR(8000),
@len INT
)
RETURNS VARCHAR(8000)
AS
BEGIN
RETURN RIGHT(REPLICATE(SPACE(1), @len) + @str, @len)
END
GO
SELECT col = dbo.RightJustify('foo', 30)
UNION ALL
SELECT dbo.RightJustify('foobario', 30)
"Kevin Munro" <kevin_remove8839421@c3amulet.com> wrote in message
news:3f0c270f$0$45180$65c69314@mercury.nildram.net ...> Hi, how do you pad out a varchar with leading spaces so that the text is
> right-justified?
>
> Thanks, Kevin.
>
>
Aaron Bertrand - MVP Guest
-
Justified text flow - IDCS2
I had a good search but couldn't come up with any info. A couple of years ago I went to the Adobe roadshow (debut of CS1), and they talked about... -
IDCS Hyphenation for justified columns sucks
Sucks is a strong word I know. I have been using InDesign for 18 months or so — as a Quark refugee, I'm really enjoying it. I wouldn't go back —... -
Right justified tabs don't line up.
Aaaargh. this is driving me bananas . . . I have about 12 or 14 lines (think of a price list) with left justified type, then a leader and right-just... -
Fully justified text in Flash MX. How?
What's the best way to display fully justified text in a flash movie? The movie will periodically need to be updated and each "page" on the movie... -
Kevin Munro #2
Re: Right Justified
Thanks for this Aaron, you're right - I should be doing this at the front
end. What I'm really doing is padding out some numbers with leading zero's
which can be displayed in a hierarchy and I don't want to recompile my app
yet to do it. Don't know why I said spaces, but I just convert your
function as it's still a varchar.
Many thanks, Kevin.
"Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
news:%23e9dbeiRDHA.2332@TK2MSFTNGP10.phx.gbl...let's> Probably something you should do at the client application. However,characters> say you want 30 spaces...
>
>
> SELECT col = CONVERT(VARCHAR(30), RIGHT(REPLICATE(SPACE(1), 30) + 'foo',
> 30))
> UNION ALL
> SELECT RIGHT(REPLICATE(SPACE(1), 30) + 'foobario', 30)
>
>
> I used the convert on the first result set to make the column 30> wide in Query Analyzer. If you leave that out, you can use a variable for
> the length. In fact, you could create a UDF to handle this pretty easily;
>
>
> CREATE FUNCTION dbo.RightJustify
> (
> @str VARCHAR(8000),
> @len INT
> )
> RETURNS VARCHAR(8000)
> AS
> BEGIN
> RETURN RIGHT(REPLICATE(SPACE(1), @len) + @str, @len)
> END
> GO
>
> SELECT col = dbo.RightJustify('foo', 30)
> UNION ALL
> SELECT dbo.RightJustify('foobario', 30)
>
>
>
>
> "Kevin Munro" <kevin_remove8839421@c3amulet.com> wrote in message
> news:3f0c270f$0$45180$65c69314@mercury.nildram.net ...>> > Hi, how do you pad out a varchar with leading spaces so that the text is
> > right-justified?
> >
> > Thanks, Kevin.
> >
> >
>
Kevin Munro Guest
-
Delbert Glass #3
Re: Right Justified
SELECT REPLICATE(SPACE(1), 30)
vs
SELECT SPACE(30)
?
Bye,
Delbert Glass
Delbert Glass Guest
-
Aaron Bertrand [MVP] #4
Re: Right Justified
Yep, I always forget about that one, so sorry...
"Delbert Glass" <delbert@noincoming.com> wrote in message
news:uvzrojmRDHA.2676@TK2MSFTNGP10.phx.gbl...> SELECT REPLICATE(SPACE(1), 30)
> vs
> SELECT SPACE(30)
> ?
>
> Bye,
> Delbert Glass
>
>
Aaron Bertrand [MVP] Guest



Reply With Quote

