Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with.
    
        
            
                
                    
                        
                            
                                | Author | 
                                
                                 Topic  | 
                             
                            
                                    | 
                                         2revup 
                                        Posting Yak  Master 
                                         
                                        
                                        112 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2013-04-29 : 19:07:09
                                            
  | 
                                             
                                            
                                            | Here is my query  Select userid, COUNT(userid)as count, cast(avg(rating)AS decimal(10,2)) as avg  from userratings_all   group by UserIDthis is rounding the numbers as wholes like:userid	count	avgweqweq	31	4.00ewewee	51	4.00jkuudd	32	2.00juddes	1	3.00I need the decimals to show how can I get SQL to output the real value? | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     chadmat 
                                    The Chadinator 
                                     
                                    
                                    1974 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-04-29 : 19:25:35
                                          
  | 
                                         
                                        
                                          | declare @t1 table (c1 int)insert into @t1 values (1)insert into @t1 values (4)insert into @t1 values (3)insert into @t1 values (6)insert into @t1 values (9)insert into @t1 values (12)SELECT AVG( c1 * 1.0)from @t1-Chad  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     2revup 
                                    Posting Yak  Master 
                                     
                                    
                                    112 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-04-29 : 19:38:14
                                          
  | 
                                         
                                        
                                          | Thanks so much!  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     ScottPletcher 
                                    Aged Yak Warrior 
                                     
                                    
                                    550 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-04-30 : 12:20:19
                                          
  | 
                                         
                                        
                                          | Select     userid, COUNT(userid)as count,     avg(cast(rating AS decimal(10,2))) as avg from userratings_all group by UserIDThe * 1.0 will give you only one decimal place; you could use 1.00 if you wanted.  I personally prefer to explicitly state the type, particularly if I already know the specific data type I want.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |