Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Im a SQL noob but here goes - I have a trigger in SQL which is giving me an incorrect syntax error E.G:

INSERT INTO aTable
 (
   tTypeId,
   opId,
   inserted.Id
 )
 SELECT 
  3,
  0,
  inserted.Id
FROM inserted, tblParents
WHERE inserted.blah = 308
   AND (
     inserted.type = 1
     AND((SELECT COUNT(*) FROM [dbo].[splitGUIDs] ([tblParents].[Parents]) 
            WHERE [inserted].[Id] IN ([dbo].[splitGUIDs].[item])) > 0 OPTION (maxrecursion 1000);
    )
   OR 
   (
     inserted.type = 2
     AND((SELECT COUNT(*) FROM [dbo].[splitGUIDs] ([tblParents].[Parents]) 
            WHERE [inserted].[Id] IN ([dbo].[splitGUIDs].[item])) > 0 OPTION (maxrecursion 1000);
   )

Each of the OPTION (maxrecursion 1000) causes an invalid syntax error - but they are required for the splitGUIDs function to work correctly. How can I resolve this syntax issue?

share|improve this question
    
Have you tried removing the semicolons after the option (maxrecursion 1000) ? –  WT_W Nov 8 '12 at 3:20
    
Hi, yeah tried that - but no luck –  Jim Nov 8 '12 at 3:26
    
Your insert into syntax also appears to be incorrect - you may want to review the syntax on Books On Line. –  WT_W Nov 8 '12 at 3:32
    
Right sorry - missed the select w copy and paste see updated question –  Jim Nov 8 '12 at 3:35
2  
Just a guess without looking at BOL: try moving the OPTION clause to the end of the INSERT statement instead. –  Jon Seigel Nov 8 '12 at 3:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.