select
ID_CLIENTE,
ID_FACTURA,
IIF( DATEDIFF( month, current_date, date FECHAFIN_CRE ) <0 AND (FECHAFIN_CRE <> '0000-00-00' ), M_VENTACREDITO,0) AS POR_VENCER,
IIF( DATEDIFF( month, current_date, date FECHAFIN_CRE )>=0 AND DATEDIFF( month, current_date, date FECHAFIN_CRE ) <=15 OR FECHAFIN_CRE = '00-00-0000', M_VENTACREDITO,0) AS VENCIDOS115,
IIF( DATEDIFF( month, current_date, date FECHAFIN_CRE )>=16 AND DATEDIFF( month, current_date, date FECHAFIN_CRE ) <=30, M_VENTACREDITO,0) AS VENCIDOS1630,
IIF( DATEDIFF( month, current_date, date FECHAFIN_CRE )>=31 AND DATEDIFF( month, current_date, date FECHAFIN_CRE ) <=45, M_VENTACREDITO,0) AS VENCIDOS3145,
IIF( DATEDIFF( month, current_date, date FECHAFIN_CRE )>=46 AND DATEDIFF( month, current_date, date FECHAFIN_CRE ) <=60, M_VENTACREDITO,0) AS VENCIDOS4660,
IIF( DATEDIFF( month, current_date, date FECHAFIN_CRE )>=61 AND DATEDIFF( month, current_date, date FECHAFIN_CRE ) <=90, M_VENTACREDITO,0) AS VENCIDOS6190,
IIF( DATEDIFF( month, current_date, date FECHAFIN_CRE )>=91 AND DATEDIFF( month, current_date, date FECHAFIN_CRE ) <=120, M_VENTACREDITO,0) AS VENCIDOS91120,
IIF( DATEDIFF( month, current_date, date FECHAFIN_CRE )>=121 ,M_VENTACREDITO,0) AS VENCIDOSMAS120
from FAC_CREDITO
ORDER BY ID_CLIENTE