Skip to content
Advertisement

Incorrect syntax near ‘)’ SQL SERVER

I am trying to find data of One Table where Weeks column is greater than result of Subquery.But somehow that is not running due to Incorrect syntax

SELECT * FROM Table1 a WHERE CONVERT(DATE,SUBSTRING(a.WEEKS,CHARINDEX('W/E',WEEKS)+4,12),1)>
(SELECT MAX(x.WEEKS) AS MONTHLY_MAX_WEEKS FROM
(
(SELECT MAX(CONVERT(DATE,SUBSTRING(WEEKS,CHARINDEX('W/E',WEEKS)+4,12),1)) AS WEEKS  FROM Table2 
UNION ALL
SELECT MAX(CONVERT(DATE,SUBSTRING(WEEKS,CHARINDEX('W/E',WEEKS)+4,12),1)) AS WEEKS FROM Table3 
) AS x))

Advertisement

Answer

You should change like this

SELECT * FROM Table1 a WHERE CONVERT(DATE,SUBSTRING(a.WEEKS,CHARINDEX('W/E',WEEKS)+4,12),1)>
(
SELECT MAX(x.WEEKS) AS MONTHLY_MAX_WEEKS 
FROM
(
  (SELECT MAX(CONVERT(DATE,SUBSTRING(WEEKS,CHARINDEX('W/E',WEEKS)+4,12),1)) AS WEEKS  FROM Table2 
  UNION ALL
  SELECT MAX(CONVERT(DATE,SUBSTRING(WEEKS,CHARINDEX('W/E',WEEKS)+4,12),1)) AS WEEKS FROM Table3 
  ) 
)as x
)
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement