| Author | 
		Message | 
	
	
		
			sangha 
			 
			
  
			
			
				Joined: 19 Dec 2006 Posts: 18
  | 
			 
			  
		 | 
		
			
				  SQL Server Formatting bug | 
				     | 
			 
			
				This happens if the select statement has an IN keyword. Also note that the last character i.e ')' is missing after formatting.
 
Paste the following in QA and Format the code
 
	  | 
	
 
	  | 
	SELECT * FROM   Customers WHERE  CustomerID IN(1,2)
 
 
SELECT * FROM   Customers WHERE  CustomerID IN(1,2)
 
 
SELECT * FROM   Customers WHERE  CustomerID IN(1,2)
 
 
SELECT * FROM   Customers WHERE  CustomerID IN(1,2) | 
	 
 
 
 
This is the ouput of the formatting
 
	  | 
	
 
	  | 
	SELECT *
 
FROM   Customers
 
WHERE  CustomerID IN (SELECT CustomerCustomerDemo.CustomerID
 
                      FROM   CustomerCustomerDemo)
 
                  
 
                  SELECT *
 
                  FROM   Customers
 
                  WHERE  CustomerID IN (SELECT CustomerCustomerDemo.CustomerID
 
                                        FROM   CustomerCustomerDemo)
 
                                    
 
                                    SELECT *
 
                                    FROM   Customers
 
                                    WHERE  CustomerID IN (SELECT CustomerCustomerDemo.CustomerID
 
                                                          FROM   CustomerCustomerDemo)
 
                                                      
 
                                                      SELECT *
 
                                                      FROM   Customers
 
                                                      WHERE  CustomerID IN (1, 2)
 
                                                                        
 
                                                                        SELECT *
 
                                                                        FROM   Customers
 
                                                                        WHERE  CustomerID IN (1, 2 | 
	 
 
  | 
			 
		  | 
	
	
		| Wed Jun 27, 2007 11:19 pm | 
		          | 
	
	
		  | 
	
	
		
			SysOp 
			Site Admin 
			
  
			
			
				Joined: 26 Nov 2006 Posts: 7992
  | 
			 
			  
		 | 
		
			
				   | 
				     | 
			 
			
				I actually get this
 
 
	  | 
	
 
	  | 
	SELECT *
 
FROM   Customers
 
WHERE  CustomerID IN (1, 2)
 
                  
 
                  SELECT *
 
                  FROM   Customers
 
                  WHERE  CustomerID IN (1, 2)
 
                                    
 
                                    SELECT *
 
                                    FROM   Customers
 
                                    WHERE  CustomerID IN (1, 2)
 
                                                      
 
                                                      SELECT *
 
                                                      FROM   Customers
 
                                                      WHERE  CustomerID IN (1, 2) | 
	 
 
  | 
			 
		  | 
	
	
		| Wed Jun 27, 2007 11:27 pm | 
		          | 
	
	
		  | 
	
	
		
			sangha 
			 
			
  
			
			
				Joined: 19 Dec 2006 Posts: 18
  | 
			 
			  
		 | 
		
			
				   | 
				     | 
			 
			
				Oops I pasted the wrong  set of queries.
 
Try this:-
 
	  | 
	
 
	  | 
	SELECT * FROM   Customers WHERE  CustomerID IN (SELECT CustomerCustomerDemo.CustomerID FROM   CustomerCustomerDemo)
 
 
SELECT * FROM   Customers WHERE  CustomerID IN (SELECT CustomerCustomerDemo.CustomerID FROM   CustomerCustomerDemo)
 
 
SELECT * FROM   Customers WHERE  CustomerID IN (SELECT CustomerCustomerDemo.CustomerID FROM   CustomerCustomerDemo)
 
 
SELECT * FROM   Customers WHERE  CustomerID IN(1,2)
 
 
SELECT * FROM   Customers WHERE  CustomerID IN(1,2) | 
	 
 
 
 
You will get the following after formatting:-
 
	  | 
	
 
	  | 
	SELECT *
 
FROM   Customers
 
WHERE  CustomerID IN (SELECT CustomerCustomerDemo.CustomerID
 
                      FROM   CustomerCustomerDemo)
 
                  
 
                  SELECT *
 
                  FROM   Customers
 
                  WHERE  CustomerID IN (SELECT CustomerCustomerDemo.CustomerID
 
                                        FROM   CustomerCustomerDemo)
 
                                    
 
                                    SELECT *
 
                                    FROM   Customers
 
                                    WHERE  CustomerID IN (SELECT CustomerCustomerDemo.CustomerID
 
                                                          FROM   CustomerCustomerDemo)
 
                                                      
 
                                                      SELECT *
 
                                                      FROM   Customers
 
                                                      WHERE  CustomerID IN (1, 2)
 
                                                                        
 
                                                                        SELECT *
 
                                                                        FROM   Customers
 
                                                                        WHERE  CustomerID IN (1, 2 | 
	 
 
  | 
			 
		  | 
	
	
		| Wed Jun 27, 2007 11:32 pm | 
		          | 
	
	
		  | 
	
	
		
			SysOp 
			Site Admin 
			
  
			
			
				Joined: 26 Nov 2006 Posts: 7992
  | 
			 
			  
		 | 
		
			
				   | 
				     | 
			 
			
				I tried this in v2.5 preview version that is not yet released. The result is the same. Obviously the incremental offset between SELECT statements is wrong.
 
 
Also interesting that if I highlight each statement separately and do the formating statement by statement I get the following 
 
 
	  | 
	
 
	  | 
	SELECT *
 
FROM   Customers
 
WHERE  CustomerID IN (1, 2)
 
 
SELECT *
 
FROM   Customers
 
WHERE  CustomerID IN (1, 2
 
FROM   Custome 
 
 
SELECT *
 
FROM   Customers
 
WHERE  CustomerID IN (1, 2)
 
FROM   Custome
 
 
SELECT *
 
FROM   Customers
 
WHERE  CustomerID IN (1, 2
 
FROM   Custome | 
	 
 
  | 
			 
		  | 
	
	
		| Wed Jun 27, 2007 11:34 pm | 
		          | 
	
	
		  | 
	
	
		
			SysOp 
			Site Admin 
			
  
			
			
				Joined: 26 Nov 2006 Posts: 7992
  | 
			 
			  
		 | 
		
			
				   | 
				     | 
			 
			
				I get the same result here for the set of statements you posted in the last message. I will let developers know.
  | 
			 
		  | 
	
	
		| Wed Jun 27, 2007 11:37 pm | 
		          | 
	
	
		  | 
	
	
		
			sangha 
			 
			
  
			
			
				Joined: 19 Dec 2006 Posts: 18
  | 
			 
			  
		 | 
		
			
				   | 
				     | 
			 
			
				Yes, the last 2 characters are missing for each query after the first query.
  | 
			 
		  | 
	
	
		| Wed Jun 27, 2007 11:38 pm | 
		          | 
	
	
		  | 
	
	
		
			SysOp 
			Site Admin 
			
  
			
			
				Joined: 26 Nov 2006 Posts: 7992
  | 
			 
			  
		 | 
		
			
				   | 
				     | 
			 
			
				this all seem to happen when a query ends with ")". If you add at the end of these queries "AND 1=1", the formatted results appear ok.
  | 
			 
		  | 
	
	
		| Wed Jun 27, 2007 11:44 pm | 
		          | 
	
	
		  | 
	
	
		
			sangha 
			 
			
  
			
			
				Joined: 19 Dec 2006 Posts: 18
  | 
			 
			  
		 | 
		
			
				   | 
				     | 
			 
			
				Yes that's right. It's missing some ')' in some cases and adding 'FROM   Custome' to the end of the query.
 
Here's another example of separate formatting with strange results:-
 
	  | 
	
 
	  | 
	SELECT * FROM   Customers WHERE  CustomerID IN (1, 2)  AND  1 = (1)
 
SELECT * FROM   Customers WHERE  CustomerID IN (1, 2)  AND  1 = (1) | 
	 
 
 
 
	  | 
	
 
	  | 
	SELECT *
 
FROM   Customers
 
WHERE  CustomerID IN (1, 2)
 
  AND  1 = (
 
           1SELECT T
 
            FROM     Custome
 
            WHERE    CustomerIIN ( , ,)
 
              AND    = (
 
                        
 
                   )
 
SELECT *
 
FROM   Customers
 
WHERE  CustomerID IN (1, 2)
 
  AND  1 = (
 
           1
 
FROM   Custome | 
	 
 
  | 
			 
		  | 
	
	
		| Wed Jun 27, 2007 11:54 pm | 
		          | 
	
	
		  | 
	
	
		 |