How to add 'n' number of spaces between two column names in Query?

I am trying to write a basic query that gives me FullName from the columns FirstName and LastName

Query:

select StudentID,
    FirstName + ' ' + LastName as FullName
from Students

Now I am interested to see if there is a chance to add spaces between FirstNameand LastNamein the query when merging dynamic?

per say I need to have 50 spaces between FirstNameand LastName? Can i achieve this.

One solution would be to add spaces manually that are really looking for a way here.

+4
source share
2 answers

REPLICATE() allows you to duplicate the specified string n times.

SELECT StudentID,
    FirstName + REPLICATE(' ',50) + LastName as FullName
FROM Students
+3
source

I found this:

right(replicate('0',10)+cast(@num as varchar(15)),10) aS lpad_number

Just replace “0” with spaces, which I think.

:

left(field + replicate(' ',5),5)

, .

+1

All Articles