The error points to line 1 saying F-string: unterminated string (pyflakes E)
Query = f"""SET NOCOUNT ON
DECLARE @StartDate DateTime
DECLARE @EndDate DateTime
SET @StartDate = '{BEGINDATE}'
SET @EndDate = '{ENDDATE}'
SET NOCOUNT OFF
SELECT * FROM (
SELECT History.TagName, DateTime, Value, StartDateTime
FROM History
WHERE History.TagName IN ({str(stat_tags_final[j])[1:-1]}, '{(ft_tags_final[i][j])')
AND wwRetrievalMode = 'Cyclic'
AND wwResolution = 1800000
AND wwVersion = 'Latest'
AND DateTime >= @StartDate
AND DateTime <= @EndDate) temp WHERE temp.StartDateTime >= @StartDate"""
Previously, I did it without f-strings as shown below and it worked fine but looked much more messy. The error occurs when I edit the line "WHERE History.TagName IN(…. I don’t see any unclosed parentheses or quotes here so can anyone point out what’s wrong with the syntax here?
Query = """SET NOCOUNT ON
DECLARE @StartDate DateTime
DECLARE @EndDate DateTime
SET @StartDate = """+"'"+(BEGINDATE)+"'""""
SET @EndDate = """+"'"+(ENDDATE)+"'""""
SET NOCOUNT OFF
SELECT * FROM (
SELECT History.TagName, DateTime, Value, StartDateTime
FROM History
WHERE History.TagName IN (""" + str(stat_tags_final[j])[1:-1] + ", '" + (ft_tags_final[i][j]) + "'" + """)
AND wwRetrievalMode = 'Cyclic'
AND wwResolution = 1800000
AND wwVersion = 'Latest'
AND DateTime >= @StartDate
AND DateTime <= @EndDate) temp WHERE temp.StartDateTime >= @StartDate"""
>Solution :
Your error is probably in this line:
WHERE History.TagName IN ({str(stat_tags_final[j])[1:-1]}, '{(ft_tags_final[i][j])')
You have an opening { but no closing } where you use ft_tags_final.