Formating query with OUTER APPLY to a function causes alignment issues

I have an issue where the an OUTER APPLY is causing odd formatting.  With the OUTER APPLY the query formats like this
<div>&nbsp; &nbsp; SELECT</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T1.[Field1],</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IIF(T1.[Field2] = 10 OR T1.[Field2] = 14, NULL, ISNULL(T1.[Field3], OCD.[Blah])) AS Yadda,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T1.[Field3],</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AA.[Field4]</div><div>&nbsp; &nbsp; FROM</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [schema1].[Table1] T1</div><div>&nbsp; &nbsp; &nbsp; INNER JOIN</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [schema2].[Table2] AA</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON T1.[Field5] = AA.[Field6]</div><div>&nbsp; &nbsp; &nbsp; OUTER APPLY [schema3].[Function1](T1.[Field7], T1.[Field8]) OCD</div><div>&nbsp; &nbsp; WHERE</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T1.[Field8] >= @Something</div><div>&nbsp; &nbsp; &nbsp; AND T1.[Field8] < @SomethingElse;</div>


Remove the OUTER APPLY and it looks like (which is more what we are looking for)

<div>SELECT</div><div>&nbsp; &nbsp; T1.[Field1],</div><div>&nbsp; &nbsp; IIF(T1.[Field2] = 10 OR T1.[Field2] = 14, NULL, ISNULL(T1.[Field3], T1.[Blah])) AS Yadda,</div><div>&nbsp; &nbsp; T1.[Field3],</div><div>&nbsp; &nbsp; AA.[Field4]</div><div>FROM</div><div>&nbsp; &nbsp; [schema1].[Table1] T1</div><div>&nbsp; INNER JOIN</div><div>&nbsp; &nbsp; [schema2].[Table2] AA</div><div>&nbsp; &nbsp; &nbsp; ON T1.[Field5] = AA.[Field6]</div><div>WHERE</div><div>&nbsp; &nbsp; T1.[Field8] >= @Something</div><div>&nbsp; AND T1.[Field8] < @SomethingElse;</div>


Essentially the OUTER APPLY is causing the columns to align with the function's name except the everything after the first condition in the WHERE clause

Anyone find a way to stop/prevent the function from messing up the alignment of fields?

Formating query with OUTER APPLY to a function causes alignment issues
Tagged:

Answers

  • Good Afternoon Wayne Francis,

    Thanks for reaching out to Redgate with your Formatting Style inquiry. In order for me to get an exact 1:1 of what you are experiencing, can you let me know which version of SQL Prompt you are utilizing? Additionally, could I kindly request that you provide me with your formatting style that you are testing with? You can locate your custom styles in the following directory C:\Users\<YOURUSER>\AppData\Local\Red Gate\SQL Prompt 10\Styles and attach it here. 

    I can then test this locally and see if I can provide you with a solution that fits your style.
Sign In or Register to comment.