on 09-29-2014 8:59 PM
HOLA
NECESITO COLOCAR COMO COLUMNA DE ENCABEZADO LOS RESULTADOS DE LAS CONSULTAS,
POR DEFECTO EN CR LOS MUESTRA EN HORIZONTAL, PERO YO DESEO COLOCARLO COMO COLUMNAS
GRACIAS
Buenas tardes
Trata haciendo un pivot para usar columnas
Te dejo una guía: http://www.qualityinfosolutions.com/el-poder-del-pivot-2/
Saludos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
GRACIAS FELIPE YA LO PROBE Y ES EXACTAMENTE LO QUE BUSCO.
Una consulta tengo el siguiente codigo para obtener por meses del año todo las CxC Cuentas por Cobrar, lo ajuste a la tabla pivote pero no me la arroja ya me cicle y aun no encuentro el error podrías darle un vistazo por favor (ojo me falta la parte de factura de anticipos, solo es factura de deudores)
Gracias
SELECT
P.[# Mes],
[1] as [Ene],
[2] as [Feb],
[3] as [Mar],
[4] as [Abr],
[5] as [May],
[6] as [Jun],
[7] as [Jul],
[8] as [Ago],
[9] as [Sep],
[10] as [Oct],
[11] as [Nov],
[12] as [Dic]
FROM (
SELECT datepart(month, t0.U_fechavenccontra)[# Mes]
,CASE T0.DocCur WHEN 'MXP' THEN sum(t0.doctotal -
t0.PaidToDate) ELSE sum(t0.doctotalFC - T0.PaidFC) END as
'TotalxCobrar',t0.doccur AS 'Moneda', 'MHO' as 'Sociedad'
FROM [MHO_Produccion].[dbo].oinv t0
WHERE docstatus = 'O' and t0.CardCode != '0663-000-P'And
t0.CardCode != '0663-001-D' and t0.U_fechavenccontra is not null
and t0.U_fechavenccontra between '20140101' and '20141231'
GROUP BY datepart(month, t0.U_fechavenccontra), T0.DocCur
) P
PIVOT (
SUM(TotalxCobrar)
FOR [datepart(month, t0.U_fechavenccontra)[# Mes]] IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])
) P
ORDER BY P.[# Mes]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
12 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.