By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Getting error :- Msg 170, Level 15, State 1, Line 18: Incorrect syntax near 'MAX'.

P: 4
Hi, I am using SQL Server 2005 and i am using Stored Procedure something like :-

I am getting error:-
Msg 170, Level 15, State 1,
Line 18: Incorrect syntax near 'MAX'.

DECLARE @jid AS VARCHAR(20),
@DBName As VARCHAR(50),
@Query AS VARCHAR(MAX)

SET @DBName = 'test'

SET @Query = '

DECLARE @jid AS VARCHAR(20),
@StartDate AS VARCHAR(50),
@endDate AS VARCHAR(50),
@DBName As NVARCHAR(50),

@PEditorId AS NVARCHAR(2000),
@IsDateAssigned BIT

SELECT @jid = '+ @PJID + ',
@startdate = ' +@Pstartdate+' ,
@enddate = '+@Penddate +'


DECLARE @reviewercount TABLE(
cont INT,
ms_id INT,
rev_no INT)

INSERT INTO @reviewercount
SELECT Count(*),
ms_id,
ms_rev_no
FROM ' + @DBName+'.reviewer
WHERE j_id = @jid
GROUP BY ms_id,
ms_rev_no

DECLARE @editorIds TABLE(
ed_id INT)

DECLARE @String VARCHAR(10)

WHILE Len('+ @PEditorId +') > 0
BEGIN
SET @String = Left(' + @PEditorId +', Isnull(Nullif(Charindex('','', ' + @PEditorId +') - 1, -1), Len('+ @PEditorId +')))

SET @PEditorId = Substring('+ @PEditorId +', Isnull(Nullif(Charindex('','', '+ @PEditorId +'), 0), Len('+@PEditorId+')) + 1, Len('+@PEditorId+'))

INSERT INTO @editorIds
([ed_id])
VALUES ( Cast(@String AS INT) )
END


I am getting error:-
Msg 170, Level 15, State 1,
Line 18: Incorrect syntax near 'MAX'.
Mar 31 '11 #1
Share this Question
Share on Google+
1 Reply


100+
P: 152
gpl
what does the generated SQL look like ?
try replacing your exec @Query with a Print @Query

Do you really need dynamic sql for this? a stored procedure would be much more efficient and would give a better clue as to where your problem is.
Mar 31 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.