我需要将空行添加到sql结果中,以便始终有3行。如果我的查询返回0行,我需要做一个空行的3个联合,如果查询返回1行,我需要UNION 2空行。如果查询返回2行,我需要UNION只有一个空行,并且如果查询返回3行,请添加空行。不同的select sql在case语句中
我新手SQL和我是想这样的:
SELECT CASE (COUNT(*) FROM public_getxo_alumbrado_puntos_luz_soportes_demo where id_punto_luz=CInt(Reports![TODO_horizontal]!id_punto_luz))
WHEN 0 THEN (SELECT * FROM public_getxo_alumbrado_puntos_luz_soportes_demo where id_punto_luz=CInt(Reports![TODO_horizontal]!id_punto_luz)
UNION ALL Select DISTINCT '' as tipo_soporte , '' as subtipo_soporte, '' as soporte_ppal_forma, '' as material, '' as soporte_ppal_altura, '' as longitud, '' as soporte_aux_angulo, '' as modelo, '' as marca, '' as estado, '' as fecha_instalacion, '' as fecha_intervencion, '' as fecha_baja, '' as observaciones, '' as tipo_intervencion , CInt(Reports![TODO_horizontal]!id_punto_luz) as id_punto_luz, '' as id_soporte, '' as id_modelo from public_getxo_alumbrado_puntos_luz_soportes_demo
UNION ALL Select DISTINCT '' as tipo_soporte , '' as subtipo_soporte, '' as soporte_ppal_forma, '' as material, '' as soporte_ppal_altura, '' as longitud, '' as soporte_aux_angulo, '' as modelo, '' as marca, '' as estado, '' as fecha_instalacion, '' as fecha_intervencion, '' as fecha_baja, '' as observaciones, '' as tipo_intervencion , CInt(Reports![TODO_horizontal]!id_punto_luz) as id_punto_luz, '' as id_soporte, '' as id_modelo from public_getxo_alumbrado_puntos_luz_soportes_demo
UNION ALL Select DISTINCT '' as tipo_soporte , '' as subtipo_soporte, '' as soporte_ppal_forma, '' as material, '' as soporte_ppal_altura, '' as longitud, '' as soporte_aux_angulo, '' as modelo, '' as marca, '' as estado, '' as fecha_instalacion, '' as fecha_intervencion, '' as fecha_baja, '' as observaciones, '' as tipo_intervencion , CInt(Reports![TODO_horizontal]!id_punto_luz) as id_punto_luz, '' as id_soporte, '' as id_modelo from public_getxo_alumbrado_puntos_luz_soportes_demo)
WHEN 1 THEN (SELECT * FROM public_getxo_alumbrado_puntos_luz_soportes_demo where id_punto_luz=CInt(Reports![TODO_horizontal]!id_punto_luz)
UNION ALL Select DISTINCT '' as tipo_soporte , '' as subtipo_soporte, '' as soporte_ppal_forma, '' as material, '' as soporte_ppal_altura, '' as longitud, '' as soporte_aux_angulo, '' as modelo, '' as marca, '' as estado, '' as fecha_instalacion, '' as fecha_intervencion, '' as fecha_baja, '' as observaciones, '' as tipo_intervencion , CInt(Reports![TODO_horizontal]!id_punto_luz) as id_punto_luz, '' as id_soporte, '' as id_modelo from public_getxo_alumbrado_puntos_luz_soportes_demo
UNION ALL Select DISTINCT '' as tipo_soporte , '' as subtipo_soporte, '' as soporte_ppal_forma, '' as material, '' as soporte_ppal_altura, '' as longitud, '' as soporte_aux_angulo, '' as modelo, '' as marca, '' as estado, '' as fecha_instalacion, '' as fecha_intervencion, '' as fecha_baja, '' as observaciones, '' as tipo_intervencion , CInt(Reports![TODO_horizontal]!id_punto_luz) as id_punto_luz, '' as id_soporte, '' as id_modelo from public_getxo_alumbrado_puntos_luz_soportes_demo)
WHEN 2 THEN (SELECT * FROM public_getxo_alumbrado_puntos_luz_soportes_demo where id_punto_luz=CInt(Reports![TODO_horizontal]!id_punto_luz)
UNION ALL Select DISTINCT '' as tipo_soporte , '' as subtipo_soporte, '' as soporte_ppal_forma, '' as material, '' as soporte_ppal_altura, '' as longitud, '' as soporte_aux_angulo, '' as modelo, '' as marca, '' as estado, '' as fecha_instalacion, '' as fecha_intervencion, '' as fecha_baja, '' as observaciones, '' as tipo_intervencion , CInt(Reports![TODO_horizontal]!id_punto_luz) as id_punto_luz, '' as id_soporte, '' as id_modelo from public_getxo_alumbrado_puntos_luz_soportes_demo)
WHEN 3 THEN (SELECT * FROM public_getxo_alumbrado_puntos_luz_soportes_demo where id_punto_luz=CInt(Reports![TODO_horizontal]!id_punto_luz))
END
FROM public_getxo_alumbrado_puntos_luz_soportes_demo;
非约束性建议:如果可能的话,做SQL外部这样的事情。 – Ashalynd