OUTER APPLY doesn't honor 'Parentheses style' settings
StereoType
Posts: 3 Bronze 1
in SQL Prompt
This is how SQL Prompt 8.2.3.2750 formats the code:
Can't get something close to this with style options:
Why extra spaces in 'SUM( CASE..' and 'DATEDIFF( DAY...' clauses?
SELECT emp.EmployeeId ,history.WorkType1 - (history.WorkType2 + history.WorkType3) FROM Emp.Employee emp OUTER APPLY ( SELECT SUM( CASE WHEN hst.WorkType = 1 THEN DATEDIFF( DAY, hst.StartDate, CASE WHEN hst.EndDate < @ActualDate THEN hst.EndDate ELSE @ActualDate END ) ELSE NULL END ) AS WorkType1 ,SUM( CASE WHEN hst.WorkType = 2 THEN DATEDIFF( DAY, hst.StartDate, CASE WHEN hst.EndDate < @ActualDate THEN hst.EndDate ELSE @ActualDate END ) ELSE NULL END ) AS WorkType2 ,SUM( CASE WHEN hst.WorkType = 3 THEN DATEDIFF( DAY, hst.StartDate, CASE WHEN hst.EndDate < @ActualDate THEN hst.EndDate ELSE @ActualDate END ) ELSE NULL END ) AS WorkType3 FROM Emp.WorkHistory hst ) AS history
Can't get something close to this with style options:
SELECT emp.EmployeeId ,history.WorkType1 - (history.WorkType2 + history.WorkType3) FROM Emp.Employee emp OUTER APPLY( SELECT SUM(CASE WHEN hst.WorkType = 1 THEN DATEDIFF(DAY, hst.StartDate, CASE WHEN hst.EndDate < @ActualDate THEN hst.EndDate ELSE @ActualDate END) ELSE NULL END ) AS WorkType1 ,SUM(CASE WHEN hst.WorkType = 2 THEN DATEDIFF(DAY, hst.StartDate, CASE WHEN hst.EndDate < @ActualDate THEN hst.EndDate ELSE @ActualDate END) ELSE NULL END ) AS WorkType2 ,SUM(CASE WHEN hst.WorkType = 3 THEN DATEDIFF(DAY, hst.StartDate, CASE WHEN hst.EndDate < @ActualDate THEN hst.EndDate ELSE @ActualDate END) ELSE NULL END ) AS WorkType3 FROM Emp.WorkHistory hst ) AS history
Why extra spaces in 'SUM( CASE..' and 'DATEDIFF( DAY...' clauses?
Tagged:
Answers
I've logged a bug for it with internal reference, SP-6667. We'll post here once we have an update on a fix.
Jessica Ramos | Product Support Engineer | Redgate Software
Have you visited our Help Center?
do you have any news on this issue?
No update yet, I'm afraid, but I'm following up on this.
Jessica Ramos | Product Support Engineer | Redgate Software
Have you visited our Help Center?
Krzysztof
thank you for the fix, now 'OUTER APPLY' is following the Parentheses settings, but the problem with extra leading spaces in SUM and DATEDIFF clauses is still here:
I have 'Expanded, simple' selected and 'Indent parentheses contents' unchecked in Parentheses settings. How to get rid of these extra spaces?
You're absolutely right, those extra spaces definitely shouldn't be there. We've logged a bug for it, internal reference SP-6927. We'll post here once we have an update on a fix.
Kind Regards,
Tom
Redgate Software
We've done some investigation into the issue, and we think the cause could be the "Indent List Items" setting in the formatting options. Would you be able to disable this option and see if it improves the situation?
If the issue persists, would you be able to provide your full style file so we can better reproduce and diagnose the issue?
Kind Regards,
Tom
Redgate Software