No me sle estoy que lo pongo asi
Código SQL:
Ver originalSELECT 'D054790500001' +' ' + '001'+'0000' + A.ALUMNO +
CASE WHEN Len (rn)<=15 THEN (rtrim(rn) + replicate('0',7-len(rn)) + CONVERT(VARCHAR(15),rn))
ELSE SUBSTRING(rn,1,15)+ '' END+
'20499571144'+'0'+'0000'+
CASE WHEN Len (A.NOMBRE)<=20 THEN (rtrim(A.NOMBRE)+replicate(' ', 20 - Len(A.NOMBRE)))
ELSE SUBSTRING(A.NOMBRE,1,20)+ '' END+
CASE WHEN Len (CA.DESCRIPCION)<=13 THEN (rtrim(CA.DESCRIPCION)+replicate(' ', 13 - Len(CA.DESCRIPCION)))
ELSE SUBSTRING(CA.DESCRIPCION,1,13)+ '' END+
' '+'G'+
CASE WHEN Len ((CAST(ACP.GRUPO AS VARCHAR(10)))+(CAST(O.PERIODO AS VARCHAR(10))) + (CAST(O.NUMERO_CUOTA AS VARCHAR(10))) )<=15
THEN (rtrim((CAST(ACP.GRUPO AS VARCHAR(10)))+(CAST(O.PERIODO AS VARCHAR(10))) + (CAST(O.NUMERO_CUOTA AS VARCHAR(10))) ) )+
replicate(' ', 15 - Len((CAST(ACP.GRUPO AS VARCHAR(10)))+(CAST(O.PERIODO AS VARCHAR(10))) + (CAST(O.NUMERO_CUOTA AS VARCHAR(10))) ))
ELSE SUBSTRING((CAST(ACP.GRUPO AS VARCHAR(10)))+(CAST(O.PERIODO AS VARCHAR(10))) +(CAST(O.NUMERO_CUOTA AS VARCHAR(10))) ,1,15)+ '' END +
CO.TIPO_CONCEPTO + '0000' + CAST(O.MONTO AS VARCHAR(10))+'00'+' '+'000000000'+' '+'000000000'+' '+'000000000'+' '+'000000000'+' '+'000000000'+'0000000000'+CAST(O.MONTO AS VARCHAR(10))+'00'+'0000000000'+CAST(O.MONTO AS VARCHAR(10))+'00'+'00000000'+'0'+'20140514'+
CONVERT(VARCHAR,O.FECHA_VENCIMIENTO, 112)+'015'+' '+'*',O.INSTITUCION, O.CANTIDAD_TOTAL FROM
(
SELECT
'D054790500001' +' ' + '001'+'0000' + A.ALUMNO + ROW_NUMBER() OVER (ORDER BY A.NOMBRE) rn + '20499571144'+'0'+'0000'+
CASE WHEN Len (A.NOMBRE)<=20 THEN (rtrim(A.NOMBRE)+replicate(' ', 20 - Len(A.NOMBRE)))
ELSE SUBSTRING(A.NOMBRE,1,20)+ '' END+
CASE WHEN Len (CA.DESCRIPCION)<=13 THEN (rtrim(CA.DESCRIPCION)+replicate(' ', 13 - Len(CA.DESCRIPCION)))
ELSE SUBSTRING(CA.DESCRIPCION,1,13)+ '' END+
' '+'G'+
CASE WHEN Len ((CAST(ACP.GRUPO AS VARCHAR(10)))+(CAST(O.PERIODO AS VARCHAR(10))) + (CAST(O.NUMERO_CUOTA AS VARCHAR(10))) )<=15
THEN (rtrim((CAST(ACP.GRUPO AS VARCHAR(10)))+(CAST(O.PERIODO AS VARCHAR(10))) + (CAST(O.NUMERO_CUOTA AS VARCHAR(10))) ) )+
replicate(' ', 15 - Len((CAST(ACP.GRUPO AS VARCHAR(10)))+(CAST(O.PERIODO AS VARCHAR(10))) + (CAST(O.NUMERO_CUOTA AS VARCHAR(10))) ))
ELSE SUBSTRING((CAST(ACP.GRUPO AS VARCHAR(10)))+(CAST(O.PERIODO AS VARCHAR(10))) +(CAST(O.NUMERO_CUOTA AS VARCHAR(10))) ,1,15)+ '' END +
CO.TIPO_CONCEPTO + '0000' + CAST(O.MONTO AS VARCHAR(10))+'00'+' '+'000000000'+' '+'000000000'+' '+'000000000'+' '+'000000000'+' '+'000000000'+'0000000000'+CAST(O.MONTO AS VARCHAR(10))+'00'+'0000000000'+CAST(O.MONTO AS VARCHAR(10))+'00'+'00000000'+'0'+'20140514'+
CONVERT(VARCHAR,O.FECHA_VENCIMIENTO, 112)+'015'+' '+'*',O.INSTITUCION, O.CANTIDAD_TOTAL FROM ALUMNO
) AS t1
FROM OBLIGACIONES O INNER JOIN
PERSONA P ON O.PERSONA = P.PERSONA INNER JOIN
ALUMNO A ON A.ALUMNO = P.PERSONA INNER JOIN
INSTITUCION I ON I.INSTITUCION = O.INSTITUCION INNER JOIN
CARRERA CA ON CA.CARRERA = O.CARRERA INNER JOIN ALUMNO_CARRERA_PERIODO ACP
ON ACP.ALUMNO=A.ALUMNO INNER JOIN CONCEPTO CO ON CO.CONCEPTO=O.CONCEPTO
WHERE
(O.CANTIDAD_TOTAL IS NULL)
AND (O.FECHA_VENCIMIENTO > = '30/06/2014')
AND (O.CONCEPTO = '2621')
AND (O.INSTITUCION = '54') ) AS t1