-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
MSSQL SuperSet Incorect Syntax near the Keyword 'DECLARE' when attempting to create chart with a valid query. #31913
Comments
Hey @huafist! 👋 I'm here to help you with any bugs, questions, or contributions you have for Superset. I'm a bot designed to assist you while you wait for a human maintainer. Let's tackle this issue together! The issue you're encountering with the
To work around this issue, consider restructuring your query to avoid using To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
@sujiplr is the only person on our little rolodex who uses MSSQL... perhaps he can reproduce this or provide some input. |
I suspect that the issue is tied to the limit that superstack puts on the result of the query set. I'm guessing that it is injecting the "TOP XXXXX" directive in a way that's confusing the parser. |
@huafist I think that's a good hypothesis. I wonder if you could confirm that by looking at a MSSQL profiler, would that show the inbound query that is failing? |
@huafist , is there any specific reason why you are using the declare statement. As you mentioned the TOP command will cause issues, since you are using a declarative TSQL rather than a SQL statement. The requirement is looks like you are building certain intermediate dataset (as temp tables ) and wanted to use that in the final SQL statement for the chart data. This use case won't work with Superset Charts. You can make use of the CTE statements for this as an alternative. |
@sujiplr the reason was I'm inexperienced with SuperSet and I was copying/pasting from T-SQL code I had already written. Through a little more research, I determined that SS doesn't support DECLARE or SET in its queries. For this particular instance, I used OPENQUERY to execute a stored procedure that generates the data that I need, but I have ran into another issue with getting date filters to populate initially - this is causing any other filters I may add (such as a "Region" filter, to error on execution. Should I create a separate thread for that issue? |
@huafist , can you share the statement you are trying . |
@sujiplr so as I mentioned, I'm using openquery to execute a stored procedure that returns the data that I need. The stored procedure takes 2 parameters - Start Date, End Date. My end goal is a bar chart that I can add dashboard filters to that will let me change the date range, or filter the results by regionID. I added the following to the "Template Parameters" in the dataset's settings: Formatted in this way, it lets me filter by region, but the start and end dates are hard coded and do not change. |
Bug description
SuperSet v4.1.1, MSSQL Server.
I have a query that starts with a DECLARE Statement:
DECLARE
@StartDate SMALLDATETIME,
@EndDate SMALLDATETIME
SELECT @StartDate = '20241201',
@EndDate = '20241231',
IF OBJECT_ID('tempdb..#Temp') IS NOT NULL
DROP TABLE #Temp
IF OBJECT_ID('temdb..#Temp2') IS NOT NULL
DROP TABLE #Temp2
....
In this order, the query runs in SQL Lab, but if I try to create a chart or save the dataset, I get the following error:
(156, b"Incorrect syntax near the keyword 'DECLARE'.DB-Lib error message 20018,....)
Alternatively, if I move the DECLARE and SELECT statements below "DROP TABLE #Temp2", the query again runs, but if I try to create a chart, I get the error:
Error parsing near 'OBJECT_ID' at line 4:12
Screenshots/recordings
No response
Superset version
4.1.1
Python version
3.9
Node version
16
Browser
Chrome
Additional context
No response
Checklist
The text was updated successfully, but these errors were encountered: