Incorrect Syntax Near ''

Incorrect syntax near ''

Such unexpected problems can appear when you copy the code from a web page or email and the text contains unprintable characters like individual CR or LF and non-breaking spaces.

How to fix Incorrect syntax near ')'

Your issue is you are trying to select from a subquery without assigning an alias to the result set.

All you have to do is change your query from this

string query = "select sum(See) as[All] ,(select top 1 See from StateSite
where StatDate=@StatDate)as[Now], (select top 1 See from StateSite where
StatDate=@Yesterday)as[Last],(select sum(See) from (select top 7 * from
StateSite order by ID desc))as[week] From StateSite";

To this

string query = "select sum(See) as[All] ,(select top 1 See from StateSite
where StatDate=@StatDate)as[Now], (select top 1 See from StateSite where
StatDate=@Yesterday)as[Last],(select sum(See) from (select top 7 * from
StateSite order by ID desc) as [subQuery])as[week] From StateSite";

Incorrect syntax near (last line)

per @marc_s, I made these changes to fix it. Thank you for your help, Marc.

I was mistaking the CASE END for the BEGIN's END. I needed to uncomment this line:

END  --this was an extra END I commented out with no BEGIN

Also, I fixed my error message as follows, but this did not cause my initial question. It did cause errors running the SP, though:

DECLARE @error_message varchar(255) 

..
..

SET @error_message = (SELECT CONCAT(M.CID, TITLE, MemInd) FROM #UPDATES U INNER JOIN DB_DEV..MEMBER M WITH (NOLOCK) ON U.CID=M.CID WHERE MemInd='ERROR')

Incorrect syntax near ')' SQL SERVER

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
)

Incorrect syntax near ')'. SQL Server

The problem is that not in () is empty.

Run the scipt below:

select * from (select PMSEQ,SWERK,EQUNR,MPTYPE,DATE,TIME,RECDC,IDIFF,READR,IIND,QMART from P_PM_TBLIF240 where CAST(concat(concat(date,' '), time) as datetime2) >= CAST('12/30/1996 12:00:00 AM' as datetime2) and upper(status) = 'ACTIVE') a  where PMSEQ not in ('1')

Because I dont have the data, I am going with the guess that PMSEQ is text.
Let me know



Related Topics



Leave a reply



Submit