Options

Inconsistent new line behavior with windowed function

a.higginsa.higgins Posts: 90 Bronze 2
edited October 26, 2016 9:50AM in SQL Prompt
I've noticed that the ORDER BY list items within a windowed function do not follow the normal "Place first item on new line" settings. The following query was formatted using the "If there are subsequent items" option:
;WITH CTE AS
	(
		SELECT
			a = 1
		   ,b = 2
		   ,c = 3
		   ,x = 4
		   ,y = 5
		   ,z = 6
	)
SELECT Field = ROW_NUMBER() OVER (PARTITION BY
									  CTE.a
									 ,CTE.b
									 ,CTE.c
								  ORDER BY CTE.x	-- x ought to be on a new line
									 ,CTE.y
									 ,CTE.z
								 )
FROM CTE
ORDER BY
	CTE.x
   ,CTE.y
   ,CTE.z
Note that, though each list item in the PARTITION BY and the final ORDER BY statements are on new lines, the first list value within the windowed function's ORDER BY is still on the original line.

Comments

Sign In or Register to comment.