Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having token unrecognized when case is in group by #128

Open
privrja opened this issue Apr 1, 2023 · 2 comments
Open

Having token unrecognized when case is in group by #128

privrja opened this issue Apr 1, 2023 · 2 comments

Comments

@privrja
Copy link

privrja commented Apr 1, 2023

Hi, i have sql input:

SELECT src.PERIOD, CASE WHEN src.STARTX = 21 THEN 1 ELSE 0 END AS X, SUM(src.STAR) as STAR
FROM l2.V_TECH_EX_STAR src
WHERE src.PERIOD = '2021-05-01'
GROUP BY src.PERIOD, CASE WHEN src.STARTX = 21 THEN 1 ELSE 0 END
HAVING SUM(src.STAR) > 0

when parsing is done in TSQLSelectStatement is TSQLHavingClause null and part of having code is in TSQLGroupByClause. I expected it to be in TSQLHavingClause.

When i use same select without case in group by it works OK. So it's something with case part.

I updated from version 1.5.3 to 2.6.0 (in 1.5.3 works OK)

Thanks

@privrja
Copy link
Author

privrja commented Apr 1, 2023

I found a similar problem in other example, but this is not with having clause, but with group by and order by clause.

SELECT src.USER_CODE, 
	ben.BENCHMARK_MTD, -- not show
	src.COEF_OFF_DEF,
	ben.BENCHMARK,
	ben.BENCHMARK * src.COEF_OFF_DEF AS BENCHMARK_OFF_DEF,
	sum(src.FLAG_FULL) AS PLANNED_MONTH
FROM CALENDAR src
	JOIN (
		SELECT COUNT(*) AS BENCHMARK, sum(CASE WHEN cal.DATE_DAY < CAST(GETDATE() AS DATE) THEN 1 ELSE 0 END) AS BENCHMARK_MTD
		FROM D_CALENDAR cal
			JOIN V_PERIOD_ACT act ON cal.DATE_DAY BETWEEN act.FIRST_DATE AND act.LAST_DATE
		WHERE 1 = 1
			AND cal.WORKING_DAY = 1
			AND cal.WEEK_DAY <> 5
	) ben ON 1 = 1
GROUP BY src.USER_CODE, ben.BENCHMARK, ben.BENCHMARK_MTD, src.COEF_OFF_DEF
ORDER BY src.USER_CODE ASC

TSQLGroupByClause and TSQLOrderByClause is null and group by and order by part is in TSQLFromClause. I expected it to be in TSQLGroupByClause and TSQLOrderByClause.

@bruce-dunwiddie
Copy link
Owner

Thank you for reporting these issues. I will review.

Bruce Dunwiddie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants