title: T SQL Table Valued function SQL46010 :: Incorrect syntax near declare
body: <p>I get the above error when i try to save this to the SQL Server db.  Any clue why? the Select distinct query works without issue</p>
  
  <pre><code>CREATE FUNCTION [dbo].[fnGetSeqsInAllSegments]
  (
  )
  RETURNS @ret  TABLE
  (
      SequenceID int
  )
  AS
  BEGIN
      insert @ret
       select distinct SequenceID from dbo.Segments where SequenceID in 
      ( 
          select  SequenceID from dbo.Segments
          group by SequenceID
          having count(DISTINCT SegmentID) = ( select count(*) from ( select distinct SegmentID from dbo.Segments ) AS A
      ))
      RETURN
  END
  </code></pre>
  
  <p>UPDATE:  It only throws that error inside of SQL Server Data Tools 2015.  Does not do it in SQL management studio.</p>