SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


space issue in display


space issue in display

Author
Message
coool_sweet
coool_sweet
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1495 Visits: 458

hi ,

I I have 2 column, column1 and column2.

I need to concat this 2 column with column1 should have 40 white space after table.

example ,

123234 10

23 12

1234 12

I am using space function but values are not showing right in table.

when I place this column in '' its showing right. but in the table its like below.

cast

(LEFT(column1+space(45),45) aschar(45))+cast(column2aschar(1))

please help


george_at_sql
george_at_sql
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1457 Visits: 1919
If i got your question right, you wish to have a total of 40 spaces in your output after concatenating column1 and column2?

If so this should help you.

create table t(x int,y int);

insert into t values (123234,10);
insert into t values(23,12);
insert into t values(1234,12);

select concat(concat(x,y),replicate(' ',40-datalength(concat(x,y))))
from t;

drew.allen
drew.allen
SSC Guru
SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)

Group: General Forum Members
Points: 65834 Visits: 17453
coool_sweet - Thursday, February 8, 2018 6:14 PM

hi ,

I I have 2 column, column1 and column2.

I need to concat this 2 column with column1 should have 40 white space after table.

example ,

123234 10

23 12

1234 12

I am using space function but values are not showing right in table.

when I place this column in '' its showing right. but in the table its like below.

cast

(LEFT(column1+space(45),45) aschar(45))+cast(column2aschar(1))

please help


The SSMS results panel uses a variable width font as the default. Since spaces are narrower than numbers, they will not line up using the default font. If you want to see how they line up, try outputting to text instead of grid.

Drew


J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
How to post data/code on a forum to get the best help.
How to Post Performance Problems
Make sure that you include code in the appropriate IFCode tags, e.g. [code=sql]<your code here>[/code]. You can find the IFCode tags under the INSERT options when you are writing a post.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search