PoorMansTSqlFormatter icon indicating copy to clipboard operation
PoorMansTSqlFormatter copied to clipboard

Option: Do not indent FROM clause

Open bsacheri opened this issue 5 years ago • 0 comments

Do not overly indent FROM clause hierarchy.

When I've got a lot of tables involved in a query it is distracting when it indents like a tree, with a lot of wasted white space at the beginning. I don't see any value in this style of formatting.

FROM (
	(
		(
			(
				(
					tbl_ref_Tag_Prefix RIGHT JOIN (
						(
							(
								(
									(
										tbl_Equipment_List AS EL LEFT JOIN tbl_ref_Building ON EL.Building_ID = tbl_ref_Building.Building_ID
										) LEFT JOIN tbl_ref_Discipline ON EL.Discipline_ID = tbl_ref_Discipline.Discipline_ID
									) LEFT JOIN tbl_ref_Equipment_Status ON EL.Equipment_Status_ID = tbl_ref_Equipment_Status.Equipment_Status_ID
								) LEFT JOIN tbl_ref_Package ON EL.Package_ID = tbl_ref_Package.Package_ID
							) LEFT JOIN tbl_ref_UPN ON EL.UPN_ID = tbl_ref_UPN.UPN_ID
						) ON tbl_ref_Tag_Prefix.Tag_Prefix_ID = EL.Equipment_Tag_Prefix_ID
					) LEFT JOIN tbl_ref_Package AS tbl_ref_Package_1 ON EL.Prepurchase_Package_ID = tbl_ref_Package_1.Package_ID
				) LEFT JOIN tbl_ref_IMCS ON EL.IMCS_ID = tbl_ref_IMCS.IMCS_ID
			) LEFT JOIN tbl_ref_Voltage_Phase ON EL.Voltage_Phase_ID = tbl_ref_Voltage_Phase.Voltage_Phase_ID
		) LEFT JOIN tbl_ref_Motor_Data ON EL.Motor_ID = tbl_ref_Motor_Data.Motor_ID
	)
LEFT JOIN tbl_Equipment_List AS EL_Parent ON EL.Parent_Eq_List_ID = EL_Parent.Equipment_List_ID

I would like to have an option to ignore the hierarchy when indenting the FROM clause. Maybe something more like this:

FROM (((((tbl_ref_Tag_Prefix RIGHT JOIN (((((tbl_Equipment_List AS EL LEFT JOIN tbl_ref_Building ON EL.Building_ID = tbl_ref_Building.Building_ID
	) LEFT JOIN tbl_ref_Discipline ON EL.Discipline_ID = tbl_ref_Discipline.Discipline_ID
	) LEFT JOIN tbl_ref_Equipment_Status ON EL.Equipment_Status_ID = tbl_ref_Equipment_Status.Equipment_Status_ID
	) LEFT JOIN tbl_ref_Package ON EL.Package_ID = tbl_ref_Package.Package_ID
	) LEFT JOIN tbl_ref_UPN ON EL.UPN_ID = tbl_ref_UPN.UPN_ID
	) ON tbl_ref_Tag_Prefix.Tag_Prefix_ID = EL.Equipment_Tag_Prefix_ID
	) LEFT JOIN tbl_ref_Package AS tbl_ref_Package_1 ON EL.Prepurchase_Package_ID = tbl_ref_Package_1.Package_ID
	) LEFT JOIN tbl_ref_IMCS ON EL.IMCS_ID = tbl_ref_IMCS.IMCS_ID
	) LEFT JOIN tbl_ref_Voltage_Phase ON EL.Voltage_Phase_ID = tbl_ref_Voltage_Phase.Voltage_Phase_ID
	) LEFT JOIN tbl_ref_Motor_Data ON EL.Motor_ID = tbl_ref_Motor_Data.Motor_ID
	) LEFT JOIN tbl_Equipment_List AS EL_Parent ON EL.Parent_Eq_List_ID = EL_Parent.Equipment_List_ID

I typically use Poor Man's SQL Formatter plugins in SSMS and Notepad++, and not the Poor SQL website.

In case you are curious what this sample query looks like it is one main table "EL" that has a lot of normalized lookup values in reference tables. This query denormalizes the data for reporting purposes. This is a common use case in my environment.

image

bsacheri avatar Feb 08 '20 23:02 bsacheri