Align concatenated column in a query in SQL Server

0

I have this query:

SELECT A.CODIGO_MINSA, A.DESCRIPCION,  B.DESCRIPCION AS COLEGIO, 
A.CODIGO_MINSA + ' - ' + A.DESCRIPCION + SPACE(60 - LEN(A.DESCRIPCION)) + '- 
' +  B.DESCRIPCION  AS PRESENTACION
FROM [HEVES_RRHH].[dbo].[T_TIPO_ESPECIALIDAD] A LEFT JOIN  [HEVES_RRHH]. 
[dbo].[T_COLEGIOS_PROFESIONALES] B ON A.CODIGO_COLEGIO = B.CODIGO_MINSA

Concatenate 3 columns and in PRESENTACION , throws the following:

1-ADMINISTRACION DE HOSPITALES          - COLEGIO MEDICO DEL PERU
2-CIRUGÍA BUCAL MÁXILO FACIAL      - COLEGIO ODONTOLOGICO DEL PERU
3-PSICOLOGÍA CLÍNICA Y DE LA SALUD    - COLEGIO DE PSICOLOGOS DEL PERU

My goal is for the result to be aligned, like this:

1-ADMINISTRACION DE HOSPITALES     - COLEGIO MEDICO DEL PERU
2-CIRUGÍA BUCAL MÁXILO FACIAL      - COLEGIO ODONTOLOGICO DEL PERU
3-PSICOLOGÍA CLÍNICA Y DE LA SALUD - COLEGIO DE PSICOLOGOS DEL PERU

I used the SPACE command, with the total of characters to 60, I assumed that by subtracting from the description length and adding it with spaces, it should be aligned.

What am I doing wrong?

    
asked by Jose Obeso 06.11.2018 в 16:19
source

1 answer

0

I have not tried your code, but I think it works well.

The problem is that sql server shows the results with a source that is not monospaced, that is, the letter 'W' occupies more space than the letter 'I'. The solution would be to leave the query as it is and to show it in your application use a monospaced font.

I leave this image to explain my point:

Each record has 10 letters at the beginning

The following information may interest you: link link

    
answered by 07.11.2018 в 10:37