  | 
			
				SoftTree Technologies 
				Technical Support Forums
			 | 
		 
		  | 
	 
	 
	
	
	
		
	
	
	
		| Author | 
		Message | 
	 
	
		
			Mindflux 
			 
			
  
			
			
				Joined: 25 May 2013 Posts: 861 Country: United States | 
			 
			  
		 | 
		
			
				  SA Pro: 12.2.387 CTE semicolon throws off bracket matching | 
				     | 
			 
			
				
	  | 
	
 
	  | 
	BEGIN
 
   BEGIN TRY
 
      BEGIN
 
         DECLARE @z AS INT;
 
         
 
         DECLARE foo CURSOR STATIC 
 
         FOR
 
             SELECT bar
 
             FROM   baz
 
             WHERE  bar.ID = 'FOO'
 
         
 
         OPEN foo
 
         FETCH NEXT FROM foo INTO @z
 
         
 
         WHILE @@FETCH_STATUS = 0
 
         BEGIN
 
            ;WITH nohits AS ()
 
         END
 
         CLOSE foo
 
         DEALLOCATE foo
 
      END
 
   END TRY
 
END | 
	 
 
 
 
 
If you paste this into SSMS or SA Editor
 
 
The "end" at line 18 matches with the begin at line 3, instead of line 16.  If you remove the semicolon before the ;WITH statement the bracket matching works.
 
Likewise if you highlight begin try at line 2, it highlights the END at 21, instead of the END TRY at 22.  Again removing the semicolon fixes it.
 
 
 
IIRC the semicolon is required to use a CTE in this manner, so can the bracket matching be fixed?
  | 
			 
		  | 
	 
	
		| Wed Feb 22, 2023 3:36 pm | 
		          | 
	 
	
		  | 
	 
	
		 | 
	 
 
  
	 
	    
	   | 
	
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
  | 
   
 
		 | 
	 
	  |