Unix Technical Forum

right padding equivalent

This is a discussion on right padding equivalent within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi everyone, Please excuse me if this has been asked before or sounds a bit dim. This is a ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 07:47 PM
lossed
 
Posts: n/a
Default 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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 07:47 PM
Bucky
 
Posts: n/a
Default Re: right padding equivalent

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 07:47 PM
lossed
 
Posts: n/a
Default Re: right padding equivalent

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.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 07:47 PM
Mike C#
 
Posts: n/a
Default Re: right padding equivalent

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

"lossed" <hundyhunter@gmail.com> wrote in message
news:1151445410.988182.165360@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
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 07:47 PM
lossed
 
Posts: n/a
Default Re: right padding equivalent

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" <hundyhunter@gmail.com> wrote in message
> news:1151445410.988182.165360@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
> >


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-29-2008, 07:47 PM
SQL Menace
 
Posts: n/a
Default Re: right padding equivalent

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" <hundyhunter@gmail.com> wrote in message
> > news:1151445410.988182.165360@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
> > >


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-29-2008, 07:48 PM
lossed
 
Posts: n/a
Default Re: right padding equivalent

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" <hundyhunter@gmail.com> wrote in message
> > > news:1151445410.988182.165360@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
> > > >


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-29-2008, 07:48 PM
Erland Sommarskog
 
Posts: n/a
Default Re: right padding equivalent

lossed (hundyhunter@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, esquel@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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-29-2008, 07:48 PM
lossed
 
Posts: n/a
Default Re: right padding equivalent

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 (hundyhunter@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, esquel@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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-29-2008, 07:48 PM
Mike C#
 
Posts: n/a
Default Re: right padding equivalent

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" <lossedspam@hotmail.com> wrote in message
news:1151528687.660240.231810@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" <hundyhunter@gmail.com> wrote in message
>> > > news:1151445410.988182.165360@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
>> > > >

>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:54 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com