Prompt 1
create select statement with the columns commented out if they are null in this sample row output below
SELECT
pp.PP_Id
-- , pp.Actual_Bad_Items
etc
PP_Id Actual_Bad_Items Actual_Bad_Quantity Actual_Down_Time Actual_End_Time Actual_Good_Items Actual_Good_Quantity Actual_Repetitions Actual_Running_Time Actual_Start_Time Adjusted_Quantity Alarm_Count Block_Number BOM_Formulation_Id Comment_Id Control_Type Entry_On Extended_Info Forecast_End_Date Forecast_Quantity Forecast_Start_Date Implied_Sequence Implied_Sequence_Offset Late_Items Parent_PP_Id Path_Id PP_Status_Id PP_Type_Id Predicted_Remaining_Duration Predicted_Remaining_Quantity Predicted_Total_Duration Process_Order Prod_Id Production_Rate Source_PP_Id User_General_1 User_General_2 User_General_3 User_Id
7405 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2 2025-05-12 11:39:39.813 NULL 2025-05-12 05:43:11.673 100 2025-05-11 23:13:11.673 1115853191 0 NULL NULL 10 7 1 NULL NULL NULL PRF_250511_04 448 NULL NULL NULL NULL NULL 6
Answer 1
Certainly! Here’s a SELECT statement where each column is commented out if its value is NULL
in your sample row.
(Columns with non-NULL values are included as normal.)
SELECT
pp.PP_Id
-- , pp.Actual_Bad_Items
-- , pp.Actual_Bad_Quantity
-- , pp.Actual_Down_Time
-- , pp.Actual_End_Time
-- , pp.Actual_Good_Items
-- , pp.Actual_Good_Quantity
-- , pp.Actual_Repetitions
-- , pp.Actual_Running_Time
-- , pp.Actual_Start_Time
-- , pp.Adjusted_Quantity
-- , pp.Alarm_Count
-- , pp.Block_Number
-- , pp.BOM_Formulation_Id
-- , pp.Comment_Id
, pp.Control_Type
, pp.Entry_On
-- , pp.Extended_Info
, pp.Forecast_End_Date
, pp.Forecast_Quantity
, pp.Forecast_Start_Date
, pp.Implied_Sequence
, pp.Implied_Sequence_Offset
-- , pp.Late_Items
-- , pp.Parent_PP_Id
, pp.Path_Id
, pp.PP_Status_Id
, pp.PP_Type_Id
-- , pp.Predicted_Remaining_Duration
-- , pp.Predicted_Remaining_Quantity
-- , pp.Predicted_Total_Duration
, pp.Process_Order
, pp.Prod_Id
-- , pp.Production_Rate
-- , pp.Source_PP_Id
-- , pp.User_General_1
-- , pp.User_General_2
-- , pp.User_General_3
, pp.User_Id
FROM ProductionPlan AS pp;
How this was determined:
- If the value in your sample row is
NULL
, the column is commented out. - If the value is not
NULL
, the column is included.
Let me know if you want the output in a different format or for a different sample row!
Prompt 2
Now i want the sql condensed so that it uses less lines and as much as possible on the same line keeping minimal number of comment blocks but respecting the sequence of columns
Answer 2
Certainly! Here’s a condensed version of your SELECT statement, with columns that are NULL in your sample row grouped together in a single comment block, and all columns kept in their original order.
This minimizes lines and comment blocks while preserving column sequence:
SELECT
pp.PP_Id
/*, pp.Actual_Bad_Items, pp.Actual_Bad_Quantity, pp.Actual_Down_Time, pp.Actual_End_Time, pp.Actual_Good_Items, pp.Actual_Good_Quantity, pp.Actual_Repetitions, pp.Actual_Running_Time, pp.Actual_Start_Time, pp.Adjusted_Quantity, pp.Alarm_Count, pp.Block_Number, pp.BOM_Formulation_Id, pp.Comment_Id */
, pp.Control_Type
, pp.Entry_On
/*, pp.Extended_Info */
, pp.Forecast_End_Date
, pp.Forecast_Quantity
, pp.Forecast_Start_Date
, pp.Implied_Sequence
, pp.Implied_Sequence_Offset
/*, pp.Late_Items, pp.Parent_PP_Id */
, pp.Path_Id
, pp.PP_Status_Id
, pp.PP_Type_Id
/*, pp.Predicted_Remaining_Duration, pp.Predicted_Remaining_Quantity, pp.Predicted_Total_Duration */
, pp.Process_Order
, pp.Prod_Id
/*, pp.Production_Rate, pp.Source_PP_Id, pp.User_General_1, pp.User_General_2, pp.User_General_3 */
, pp.User_Id
FROM ProductionPlan AS pp;
Notes:
- All consecutive NULL columns are grouped into a single
/* ... */
comment block. - The sequence of columns is preserved.
- Only non-NULL columns are listed outside comments.
- The statement is as condensed as possible while remaining readable.
Let me know if you want it even more compact or in a different style!