473,516 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

right padding equivalent

Hi everyone,

Please excuse me if this has been asked before or sounds a bit dim.
This is a question asked on another forum but the solutions being
offered are focussing on programming rather than letting the DB server
do the work, which I'm not sure is the most efficient solution.
However, my confession is I dont use SQL server so can't help them
directly with the syntax. Hopefully you can help me help them and learn
a little about SQL Server in the process.

Trying to right pad a first name field so the padded string is a total
of 30 chars. It will be output concatenated with the last name field,
and each field separated with a "|". So that when output it reads
something like:

fname | mylastname
Syntax given was:

select id,
substring((last_name+','+rtrim(' '+isnull(level,'))+'
'+rtrim(isnull(first_name,'))+space(30)),1,30)+ ' | ' as student_name
from student

Issue: It appears this is padding correctly but the spaces are not
rendering in the browser. (I have no way to check this as I don't use
sqlserver. However, I can understand that multiple spaces are not going
to render in the client browser, if indeed the query is padding with
spaces.

Question: Instead of using space(), can replicate() be used and a
unicode space representation rather than an actual space be used? Or,
is there a better way that will ensure
the padding shows in browser?
I guess a fixed width font would also need to be used otherwise the
30-char blocks could wind up being different widths, which would defeat
the purpose.

If there is something I've missed, or you have any suggestions, I'm
keen to learn.

TYhanks in advance,

Lossed

Jun 27 '06 #1
13 8550
lossed wrote:
Issue: It appears this is padding correctly but the spaces are not
rendering in the browser. (I have no way to check this as I don't use
sqlserver. However, I can understand that multiple spaces are not going
to render in the client browser, if indeed the query is padding with
spaces.


You can view source with the browser. Then highlight the text to see
whether the spaces are there or not.

Jun 28 '06 #2
Yes but view what?
I do not use sql server so can't build the query to output to the
browser.
Sorry if I did not make that clear enough.
Bucky wrote:
lossed wrote:
Issue: It appears this is padding correctly but the spaces are not
rendering in the browser. (I have no way to check this as I don't use
sqlserver. However, I can understand that multiple spaces are not going
to render in the client browser, if indeed the query is padding with
spaces.


You can view source with the browser. Then highlight the text to see
whether the spaces are there or not.


Jun 28 '06 #3
HTML strips extra whitespace out when rendering. Maybe appending a bunch of
" " non-breaking spaces to the end would resolve your display issue?

"lossed" <hu*********@gmail.com> wrote in message
news:11**********************@x69g2000cwx.googlegr oups.com...
Hi everyone,

Please excuse me if this has been asked before or sounds a bit dim.
This is a question asked on another forum but the solutions being
offered are focussing on programming rather than letting the DB server
do the work, which I'm not sure is the most efficient solution.
However, my confession is I dont use SQL server so can't help them
directly with the syntax. Hopefully you can help me help them and learn
a little about SQL Server in the process.

Trying to right pad a first name field so the padded string is a total
of 30 chars. It will be output concatenated with the last name field,
and each field separated with a "|". So that when output it reads
something like:

fname | mylastname
Syntax given was:

select id,
substring((last_name+','+rtrim(' '+isnull(level,'))+'
'+rtrim(isnull(first_name,'))+space(30)),1,30)+ ' | ' as student_name
from student

Issue: It appears this is padding correctly but the spaces are not
rendering in the browser. (I have no way to check this as I don't use
sqlserver. However, I can understand that multiple spaces are not going
to render in the client browser, if indeed the query is padding with
spaces.

Question: Instead of using space(), can replicate() be used and a
unicode space representation rather than an actual space be used? Or,
is there a better way that will ensure
the padding shows in browser?
I guess a fixed width font would also need to be used otherwise the
30-char blocks could wind up being different widths, which would defeat
the purpose.

If there is something I've missed, or you have any suggestions, I'm
keen to learn.

TYhanks in advance,

Lossed

Jun 28 '06 #4
Tks Mike,

Do you know what would be the query syntax that will concatenate the
first_name field with the required number of no breaking spaces?

Mike C# wrote:
HTML strips extra whitespace out when rendering. Maybe appending a bunch of
"&nbsp;" non-breaking spaces to the end would resolve your display issue?

"lossed" <hu*********@gmail.com> wrote in message
news:11**********************@x69g2000cwx.googlegr oups.com...
Hi everyone,

Please excuse me if this has been asked before or sounds a bit dim.
This is a question asked on another forum but the solutions being
offered are focussing on programming rather than letting the DB server
do the work, which I'm not sure is the most efficient solution.
However, my confession is I dont use SQL server so can't help them
directly with the syntax. Hopefully you can help me help them and learn
a little about SQL Server in the process.

Trying to right pad a first name field so the padded string is a total
of 30 chars. It will be output concatenated with the last name field,
and each field separated with a "|". So that when output it reads
something like:

fname | mylastname
Syntax given was:

select id,
substring((last_name+','+rtrim(' '+isnull(level,'))+'
'+rtrim(isnull(first_name,'))+space(30)),1,30)+ ' | ' as student_name
from student

Issue: It appears this is padding correctly but the spaces are not
rendering in the browser. (I have no way to check this as I don't use
sqlserver. However, I can understand that multiple spaces are not going
to render in the client browser, if indeed the query is padding with
spaces.

Question: Instead of using space(), can replicate() be used and a
unicode space representation rather than an actual space be used? Or,
is there a better way that will ensure
the padding shows in browser?
I guess a fixed width font would also need to be used otherwise the
30-char blocks could wind up being different widths, which would defeat
the purpose.

If there is something I've missed, or you have any suggestions, I'm
keen to learn.

TYhanks in advance,

Lossed


Jun 28 '06 #5
you can also surround it with <pre> tags

save this in a file and open it up in a browser, you will see that the
spaces are preserved
<pre> b b </pre>

Denis the SQL Menace
http://sqlservercode.blogspot.com/

lossed wrote:
Tks Mike,

Do you know what would be the query syntax that will concatenate the
first_name field with the required number of no breaking spaces?

Mike C# wrote:
HTML strips extra whitespace out when rendering. Maybe appending a bunch of
"&nbsp;" non-breaking spaces to the end would resolve your display issue?

"lossed" <hu*********@gmail.com> wrote in message
news:11**********************@x69g2000cwx.googlegr oups.com...
Hi everyone,

Please excuse me if this has been asked before or sounds a bit dim.
This is a question asked on another forum but the solutions being
offered are focussing on programming rather than letting the DB server
do the work, which I'm not sure is the most efficient solution.
However, my confession is I dont use SQL server so can't help them
directly with the syntax. Hopefully you can help me help them and learn
a little about SQL Server in the process.

Trying to right pad a first name field so the padded string is a total
of 30 chars. It will be output concatenated with the last name field,
and each field separated with a "|". So that when output it reads
something like:

fname | mylastname
Syntax given was:

select id,
substring((last_name+','+rtrim(' '+isnull(level,'))+'
'+rtrim(isnull(first_name,'))+space(30)),1,30)+ ' | ' as student_name
from student

Issue: It appears this is padding correctly but the spaces are not
rendering in the browser. (I have no way to check this as I don't use
sqlserver. However, I can understand that multiple spaces are not going
to render in the client browser, if indeed the query is padding with
spaces.

Question: Instead of using space(), can replicate() be used and a
unicode space representation rather than an actual space be used? Or,
is there a better way that will ensure
the padding shows in browser?
I guess a fixed width font would also need to be used otherwise the
30-char blocks could wind up being different widths, which would defeat
the purpose.

If there is something I've missed, or you have any suggestions, I'm
keen to learn.

TYhanks in advance,

Lossed


Jun 28 '06 #6
Tks Denis,

Do you know what would be the query syntax that will concatenate the
first_name field with the required number of no breaking spaces?

SQL Menace wrote:
you can also surround it with <pre> tags

save this in a file and open it up in a browser, you will see that the
spaces are preserved
<pre> b b </pre>

Denis the SQL Menace
http://sqlservercode.blogspot.com/

lossed wrote:
Tks Mike,

Do you know what would be the query syntax that will concatenate the
first_name field with the required number of no breaking spaces?

Mike C# wrote:
HTML strips extra whitespace out when rendering. Maybe appending a bunch of
"&nbsp;" non-breaking spaces to the end would resolve your display issue?

"lossed" <hu*********@gmail.com> wrote in message
news:11**********************@x69g2000cwx.googlegr oups.com...
> Hi everyone,
>
> Please excuse me if this has been asked before or sounds a bit dim.
> This is a question asked on another forum but the solutions being
> offered are focussing on programming rather than letting the DB server
> do the work, which I'm not sure is the most efficient solution.
> However, my confession is I dont use SQL server so can't help them
> directly with the syntax. Hopefully you can help me help them and learn
> a little about SQL Server in the process.
>
> Trying to right pad a first name field so the padded string is a total
> of 30 chars. It will be output concatenated with the last name field,
> and each field separated with a "|". So that when output it reads
> something like:
>
> fname | mylastname
>
>
> Syntax given was:
>
> select id,
> substring((last_name+','+rtrim(' '+isnull(level,'))+'
> '+rtrim(isnull(first_name,'))+space(30)),1,30)+ ' | ' as student_name
> from student
>
> Issue: It appears this is padding correctly but the spaces are not
> rendering in the browser. (I have no way to check this as I don't use
> sqlserver. However, I can understand that multiple spaces are not going
> to render in the client browser, if indeed the query is padding with
> spaces.
>
> Question: Instead of using space(), can replicate() be used and a
> unicode space representation rather than an actual space be used? Or,
> is there a better way that will ensure
> the padding shows in browser?
> I guess a fixed width font would also need to be used otherwise the
> 30-char blocks could wind up being different widths, which would defeat
> the purpose.
>
> If there is something I've missed, or you have any suggestions, I'm
> keen to learn.
>
> TYhanks in advance,
>
> Lossed
>


Jun 28 '06 #7
lossed (hu*********@gmail.com) writes:
Please excuse me if this has been asked before or sounds a bit dim.
This is a question asked on another forum but the solutions being
offered are focussing on programming rather than letting the DB server
do the work, which I'm not sure is the most efficient solution.
However, my confession is I dont use SQL server so can't help them
directly with the syntax. Hopefully you can help me help them and learn
a little about SQL Server in the process.

Trying to right pad a first name field so the padded string is a total
of 30 chars. It will be output concatenated with the last name field,
and each field separated with a "|". So that when output it reads
something like:

fname | mylastname
...
Issue: It appears this is padding correctly but the spaces are not
rendering in the browser. (I have no way to check this as I don't use
sqlserver. However, I can understand that multiple spaces are not going
to render in the client browser, if indeed the query is padding with
spaces.


This sounds like an HTML design issue to me. Use a table with an invisible
border, rather than putting &nbsp; and all that stuff in SQL Server.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 28 '06 #8
Tks Erland,

Do you know what would be the query syntax that will concatenate the
first_name field with the required number of no breaking spaces?
Erland Sommarskog wrote:
lossed (hu*********@gmail.com) writes:
Please excuse me if this has been asked before or sounds a bit dim.
This is a question asked on another forum but the solutions being
offered are focussing on programming rather than letting the DB server
do the work, which I'm not sure is the most efficient solution.
However, my confession is I dont use SQL server so can't help them
directly with the syntax. Hopefully you can help me help them and learn
a little about SQL Server in the process.

Trying to right pad a first name field so the padded string is a total
of 30 chars. It will be output concatenated with the last name field,
and each field separated with a "|". So that when output it reads
something like:

fname | mylastname
...
Issue: It appears this is padding correctly but the spaces are not
rendering in the browser. (I have no way to check this as I don't use
sqlserver. However, I can understand that multiple spaces are not going
to render in the client browser, if indeed the query is padding with
spaces.


This sounds like an HTML design issue to me. Use a table with an invisible
border, rather than putting &nbsp; and all that stuff in SQL Server.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Jun 28 '06 #9
You could create a UDF like this to do it:

CREATE FUNCTION dbo.fn_HtmlHardPad(@string VARCHAR(200), @length INT)
RETURNS VARCHAR(500)
AS
BEGIN
RETURN RTRIM(@string) + REPLICATE('&nbsp;', @length - LEN(@string))
END
GO

DECLARE @test CHAR(30)
DECLARE @padded VARCHAR(300)
SELECT @test = 'Hello there'
SELECT @padded = dbo.fn_HtmlHardPad(@test, 20)
SELECT @padded

"lossed" <lo********@hotmail.com> wrote in message
news:11**********************@d56g2000cwd.googlegr oups.com...
Tks Denis,

Do you know what would be the query syntax that will concatenate the
first_name field with the required number of no breaking spaces?

SQL Menace wrote:
you can also surround it with <pre> tags

save this in a file and open it up in a browser, you will see that the
spaces are preserved
<pre> b b </pre>

Denis the SQL Menace
http://sqlservercode.blogspot.com/

lossed wrote:
> Tks Mike,
>
> Do you know what would be the query syntax that will concatenate the
> first_name field with the required number of no breaking spaces?
>
> Mike C# wrote:
> > HTML strips extra whitespace out when rendering. Maybe appending a
> > bunch of
> > "&nbsp;" non-breaking spaces to the end would resolve your display
> > issue?
> >
> > "lossed" <hu*********@gmail.com> wrote in message
> > news:11**********************@x69g2000cwx.googlegr oups.com...
> > > Hi everyone,
> > >
> > > Please excuse me if this has been asked before or sounds a bit dim.
> > > This is a question asked on another forum but the solutions being
> > > offered are focussing on programming rather than letting the DB
> > > server
> > > do the work, which I'm not sure is the most efficient solution.
> > > However, my confession is I dont use SQL server so can't help them
> > > directly with the syntax. Hopefully you can help me help them and
> > > learn
> > > a little about SQL Server in the process.
> > >
> > > Trying to right pad a first name field so the padded string is a
> > > total
> > > of 30 chars. It will be output concatenated with the last name
> > > field,
> > > and each field separated with a "|". So that when output it reads
> > > something like:
> > >
> > > fname | mylastname
> > >
> > >
> > > Syntax given was:
> > >
> > > select id,
> > > substring((last_name+','+rtrim(' '+isnull(level,'))+'
> > > '+rtrim(isnull(first_name,'))+space(30)),1,30)+ ' | ' as
> > > student_name
> > > from student
> > >
> > > Issue: It appears this is padding correctly but the spaces are not
> > > rendering in the browser. (I have no way to check this as I don't
> > > use
> > > sqlserver. However, I can understand that multiple spaces are not
> > > going
> > > to render in the client browser, if indeed the query is padding
> > > with
> > > spaces.
> > >
> > > Question: Instead of using space(), can replicate() be used and a
> > > unicode space representation rather than an actual space be used?
> > > Or,
> > > is there a better way that will ensure
> > > the padding shows in browser?
> > > I guess a fixed width font would also need to be used otherwise the
> > > 30-char blocks could wind up being different widths, which would
> > > defeat
> > > the purpose.
> > >
> > > If there is something I've missed, or you have any suggestions, I'm
> > > keen to learn.
> > >
> > > TYhanks in advance,
> > >
> > > Lossed
> > >

Jun 29 '06 #10
Thanks very much Mike,

That's getting more along the lines I had hoped for.
Is there a way to simplify it into just the one select statement rather
than a udf?
I'm thinking along these lines:

SELECT RTRIM(last_name) + REPLICATE('&nbsp;', 30 - LEN(last_name)) + '
| ' + first_name AS student_name
FROM student

Would that work?

Thanks for your time and help thus far.

Mike C# wrote:
You could create a UDF like this to do it:

CREATE FUNCTION dbo.fn_HtmlHardPad(@string VARCHAR(200), @length INT)
RETURNS VARCHAR(500)
AS
BEGIN
RETURN RTRIM(@string) + REPLICATE('&nbsp;', @length - LEN(@string))
END
GO

DECLARE @test CHAR(30)
DECLARE @padded VARCHAR(300)
SELECT @test = 'Hello there'
SELECT @padded = dbo.fn_HtmlHardPad(@test, 20)
SELECT @padded

"lossed" <lo********@hotmail.com> wrote in message
news:11**********************@d56g2000cwd.googlegr oups.com...
Tks Denis,

Do you know what would be the query syntax that will concatenate the
first_name field with the required number of no breaking spaces?

SQL Menace wrote:
you can also surround it with <pre> tags

save this in a file and open it up in a browser, you will see that the
spaces are preserved
<pre> b b </pre>

Denis the SQL Menace
http://sqlservercode.blogspot.com/

lossed wrote:
> Tks Mike,
>
> Do you know what would be the query syntax that will concatenate the
> first_name field with the required number of no breaking spaces?
>
> Mike C# wrote:
> > HTML strips extra whitespace out when rendering. Maybe appending a
> > bunch of
> > "&nbsp;" non-breaking spaces to the end would resolve your display
> > issue?
> >
> > "lossed" <hu*********@gmail.com> wrote in message
> > news:11**********************@x69g2000cwx.googlegr oups.com...
> > > Hi everyone,
> > >
> > > Please excuse me if this has been asked before or sounds a bit dim.
> > > This is a question asked on another forum but the solutions being
> > > offered are focussing on programming rather than letting the DB
> > > server
> > > do the work, which I'm not sure is the most efficient solution.
> > > However, my confession is I dont use SQL server so can't help them
> > > directly with the syntax. Hopefully you can help me help them and
> > > learn
> > > a little about SQL Server in the process.
> > >
> > > Trying to right pad a first name field so the padded string is a
> > > total
> > > of 30 chars. It will be output concatenated with the last name
> > > field,
> > > and each field separated with a "|". So that when output it reads
> > > something like:
> > >
> > > fname | mylastname
> > >
> > >
> > > Syntax given was:
> > >
> > > select id,
> > > substring((last_name+','+rtrim(' '+isnull(level,'))+'
> > > '+rtrim(isnull(first_name,'))+space(30)),1,30)+ ' | ' as
> > > student_name
> > > from student
> > >
> > > Issue: It appears this is padding correctly but the spaces are not
> > > rendering in the browser. (I have no way to check this as I don't
> > > use
> > > sqlserver. However, I can understand that multiple spaces are not
> > > going
> > > to render in the client browser, if indeed the query is padding
> > > with
> > > spaces.
> > >
> > > Question: Instead of using space(), can replicate() be used and a
> > > unicode space representation rather than an actual space be used?
> > > Or,
> > > is there a better way that will ensure
> > > the padding shows in browser?
> > > I guess a fixed width font would also need to be used otherwise the
> > > 30-char blocks could wind up being different widths, which would
> > > defeat
> > > the purpose.
> > >
> > > If there is something I've missed, or you have any suggestions, I'm
> > > keen to learn.
> > >
> > > TYhanks in advance,
> > >
> > > Lossed
> > >


Jun 29 '06 #11
That should do the trick. Just make sure that LEN(last_name) can't be
greater than 30 characters or you might get an error message from the
replicate() function.

"lossed" <lo********@hotmail.com> wrote in message
news:11**********************@b68g2000cwa.googlegr oups.com...
Thanks very much Mike,

That's getting more along the lines I had hoped for.
Is there a way to simplify it into just the one select statement rather
than a udf?
I'm thinking along these lines:

SELECT RTRIM(last_name) + REPLICATE('&nbsp;', 30 - LEN(last_name)) + '
| ' + first_name AS student_name
FROM student

Would that work?

Thanks for your time and help thus far.

Mike C# wrote:
You could create a UDF like this to do it:

CREATE FUNCTION dbo.fn_HtmlHardPad(@string VARCHAR(200), @length INT)
RETURNS VARCHAR(500)
AS
BEGIN
RETURN RTRIM(@string) + REPLICATE('&nbsp;', @length - LEN(@string))
END
GO

DECLARE @test CHAR(30)
DECLARE @padded VARCHAR(300)
SELECT @test = 'Hello there'
SELECT @padded = dbo.fn_HtmlHardPad(@test, 20)
SELECT @padded

"lossed" <lo********@hotmail.com> wrote in message
news:11**********************@d56g2000cwd.googlegr oups.com...
> Tks Denis,
>
> Do you know what would be the query syntax that will concatenate the
> first_name field with the required number of no breaking spaces?
>
> SQL Menace wrote:
>> you can also surround it with <pre> tags
>>
>> save this in a file and open it up in a browser, you will see that the
>> spaces are preserved
>> <pre> b b </pre>
>>
>> Denis the SQL Menace
>> http://sqlservercode.blogspot.com/
>>
>> lossed wrote:
>> > Tks Mike,
>> >
>> > Do you know what would be the query syntax that will concatenate the
>> > first_name field with the required number of no breaking spaces?
>> >
>> > Mike C# wrote:
>> > > HTML strips extra whitespace out when rendering. Maybe appending
>> > > a
>> > > bunch of
>> > > "&nbsp;" non-breaking spaces to the end would resolve your display
>> > > issue?
>> > >
>> > > "lossed" <hu*********@gmail.com> wrote in message
>> > > news:11**********************@x69g2000cwx.googlegr oups.com...
>> > > > Hi everyone,
>> > > >
>> > > > Please excuse me if this has been asked before or sounds a bit
>> > > > dim.
>> > > > This is a question asked on another forum but the solutions
>> > > > being
>> > > > offered are focussing on programming rather than letting the DB
>> > > > server
>> > > > do the work, which I'm not sure is the most efficient solution.
>> > > > However, my confession is I dont use SQL server so can't help
>> > > > them
>> > > > directly with the syntax. Hopefully you can help me help them
>> > > > and
>> > > > learn
>> > > > a little about SQL Server in the process.
>> > > >
>> > > > Trying to right pad a first name field so the padded string is a
>> > > > total
>> > > > of 30 chars. It will be output concatenated with the last name
>> > > > field,
>> > > > and each field separated with a "|". So that when output it
>> > > > reads
>> > > > something like:
>> > > >
>> > > > fname | mylastname
>> > > >
>> > > >
>> > > > Syntax given was:
>> > > >
>> > > > select id,
>> > > > substring((last_name+','+rtrim(' '+isnull(level,'))+'
>> > > > '+rtrim(isnull(first_name,'))+space(30)),1,30)+ ' | ' as
>> > > > student_name
>> > > > from student
>> > > >
>> > > > Issue: It appears this is padding correctly but the spaces are
>> > > > not
>> > > > rendering in the browser. (I have no way to check this as I
>> > > > don't
>> > > > use
>> > > > sqlserver. However, I can understand that multiple spaces are
>> > > > not
>> > > > going
>> > > > to render in the client browser, if indeed the query is padding
>> > > > with
>> > > > spaces.
>> > > >
>> > > > Question: Instead of using space(), can replicate() be used and
>> > > > a
>> > > > unicode space representation rather than an actual space be
>> > > > used?
>> > > > Or,
>> > > > is there a better way that will ensure
>> > > > the padding shows in browser?
>> > > > I guess a fixed width font would also need to be used otherwise
>> > > > the
>> > > > 30-char blocks could wind up being different widths, which would
>> > > > defeat
>> > > > the purpose.
>> > > >
>> > > > If there is something I've missed, or you have any suggestions,
>> > > > I'm
>> > > > keen to learn.
>> > > >
>> > > > TYhanks in advance,
>> > > >
>> > > > Lossed
>> > > >
>

Jun 29 '06 #12
Thank you so much Mike.
Very much appreciated.

Mike C# wrote:
That should do the trick. Just make sure that LEN(last_name) can't be
greater than 30 characters or you might get an error message from the
replicate() function.

"lossed" <lo********@hotmail.com> wrote in message
news:11**********************@b68g2000cwa.googlegr oups.com...
Thanks very much Mike,

That's getting more along the lines I had hoped for.
Is there a way to simplify it into just the one select statement rather
than a udf?
I'm thinking along these lines:

SELECT RTRIM(last_name) + REPLICATE('&nbsp;', 30 - LEN(last_name)) + '
| ' + first_name AS student_name
FROM student

Would that work?

Thanks for your time and help thus far.

Mike C# wrote:
You could create a UDF like this to do it:

CREATE FUNCTION dbo.fn_HtmlHardPad(@string VARCHAR(200), @length INT)
RETURNS VARCHAR(500)
AS
BEGIN
RETURN RTRIM(@string) + REPLICATE('&nbsp;', @length - LEN(@string))
END
GO

DECLARE @test CHAR(30)
DECLARE @padded VARCHAR(300)
SELECT @test = 'Hello there'
SELECT @padded = dbo.fn_HtmlHardPad(@test, 20)
SELECT @padded

"lossed" <lo********@hotmail.com> wrote in message
news:11**********************@d56g2000cwd.googlegr oups.com...
> Tks Denis,
>
> Do you know what would be the query syntax that will concatenate the
> first_name field with the required number of no breaking spaces?
>
> SQL Menace wrote:
>> you can also surround it with <pre> tags
>>
>> save this in a file and open it up in a browser, you will see that the
>> spaces are preserved
>> <pre> b b </pre>
>>
>> Denis the SQL Menace
>> http://sqlservercode.blogspot.com/
>>
>> lossed wrote:
>> > Tks Mike,
>> >
>> > Do you know what would be the query syntax that will concatenate the
>> > first_name field with the required number of no breaking spaces?
>> >
>> > Mike C# wrote:
>> > > HTML strips extra whitespace out when rendering. Maybe appending
>> > > a
>> > > bunch of
>> > > "&nbsp;" non-breaking spaces to the end would resolve your display
>> > > issue?
>> > >
>> > > "lossed" <hu*********@gmail.com> wrote in message
>> > > news:11**********************@x69g2000cwx.googlegr oups.com...
>> > > > Hi everyone,
>> > > >
>> > > > Please excuse me if this has been asked before or sounds a bit
>> > > > dim.
>> > > > This is a question asked on another forum but the solutions
>> > > > being
>> > > > offered are focussing on programming rather than letting the DB
>> > > > server
>> > > > do the work, which I'm not sure is the most efficient solution.
>> > > > However, my confession is I dont use SQL server so can't help
>> > > > them
>> > > > directly with the syntax. Hopefully you can help me help them
>> > > > and
>> > > > learn
>> > > > a little about SQL Server in the process.
>> > > >
>> > > > Trying to right pad a first name field so the padded string is a
>> > > > total
>> > > > of 30 chars. It will be output concatenated with the last name
>> > > > field,
>> > > > and each field separated with a "|". So that when output it
>> > > > reads
>> > > > something like:
>> > > >
>> > > > fname | mylastname
>> > > >
>> > > >
>> > > > Syntax given was:
>> > > >
>> > > > select id,
>> > > > substring((last_name+','+rtrim(' '+isnull(level,'))+'
>> > > > '+rtrim(isnull(first_name,'))+space(30)),1,30)+ ' | ' as
>> > > > student_name
>> > > > from student
>> > > >
>> > > > Issue: It appears this is padding correctly but the spaces are
>> > > > not
>> > > > rendering in the browser. (I have no way to check this as I
>> > > > don't
>> > > > use
>> > > > sqlserver. However, I can understand that multiple spaces are
>> > > > not
>> > > > going
>> > > > to render in the client browser, if indeed the query is padding
>> > > > with
>> > > > spaces.
>> > > >
>> > > > Question: Instead of using space(), can replicate() be used and
>> > > > a
>> > > > unicode space representation rather than an actual space be
>> > > > used?
>> > > > Or,
>> > > > is there a better way that will ensure
>> > > > the padding shows in browser?
>> > > > I guess a fixed width font would also need to be used otherwise
>> > > > the
>> > > > 30-char blocks could wind up being different widths, which would
>> > > > defeat
>> > > > the purpose.
>> > > >
>> > > > If there is something I've missed, or you have any suggestions,
>> > > > I'm
>> > > > keen to learn.
>> > > >
>> > > > TYhanks in advance,
>> > > >
>> > > > Lossed
>> > > >
>


Jun 29 '06 #13
lossed (lo********@hotmail.com) writes:
Do you know what would be the query syntax that will concatenate the
first_name field with the required number of no breaking spaces?


Apparently you did not read my post, but only reply to whatever come
in the way.

Not that I would ever get the idea to picture myself as a expert on
HTML authoring, but using &nbsp; to fill up text does not sound like
a good idea. Least of all with a proportional font...

So I maintain that a <TABLE> tag is the way to go.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 29 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
11059
by: Marek Mand | last post by:
How to create a functional *flexible* UL-menu list <div> <ul> <li><a href=""></li> <li><a href=""></li> <li><a href=""></li> </ul> </div> (working in IE, Mozilla1.6, Opera7 (or maybe even in Opera6))
12
6707
by: Stanimir Stamenkov | last post by:
Here are two cases regarding inline-level elements' line-height, padding and background, which I doesn't understand: <div style="background: black; color: white; line-height: 1.5"> <span>Abc</span> <span style="background: white; color: black; line-height: 3">Abc</span> <span>Abc</span> </div>
3
2158
by: stan | last post by:
I have code that produces 5 boxes across the screen width. So far I have only tested it in IE 6 and NS 8. It works in IE, but in NS I am not able to fit in the 5th box. I am using two different style sheets, one for IE and on e for NS. The box widths are set to 20%. I would appreciate suggestions on how to get the 5 boxes to fit the...
1
1437
by: Edward | last post by:
Why is it that in this two-column example that (only) in explorer, the text in the right-column moves a couple pixels over to the right whereever there is text across from it in the left hand column? I pasted the code below. View screenshot: http://www.tanguay.info/web/examples/headerLeftMainFooterAskWhyNotCompatible.png Download...
19
11415
by: ashkaan57 | last post by:
Hi, I have a page in a right-to-left language and I am trying to make some bulleted lists using <ul>, but it puts the bullets to the left. Is there any way I can set the bullets to be on the right: ..lists { margin:2em 0 0 2em; } ..lists ul {
11
2432
by: john_aspinall | last post by:
I want to put a simple padding on the right hand side of my text container to stop the text from overflowing out of the box. Ive added a padding-right rule and it refusing to recognise it in either IE or Firefox. Ive done exactly the same with the left padding and thats worked fine. Whats the crack??? ...
5
2702
by: Timeri | last post by:
This is a bit confusing until you actually see what I'm talking about but the main content of my page is not growing with the right column. I want the main content (left/larger column) to take into account the right deck (right column) so that both end at the same place. *********************************************************** Here's the...
6
4702
by: maya | last post by:
hi, I recently discovered the hard way that when you had padding-right or padding-left to a div it increases the with of the div... how do you add left-padding or right-padding to a div w/o changing the width of it? (for example: I have a div that's 320px wide, content inside is 300px and I added padding-left:10px but it increased with...
3
5503
by: Noorain | last post by:
I designed a site. i want to header,footer,left & right column fixed but body information only scrolling. this site screen to be 800/600 px. i designed this way but when i used position fixed all information to show as displace. please help me. my coding are as below: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.