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  | 
                             
                            
                                    | 
                                         RedMittens 
                                        Starting Member 
                                         
                                        
                                        1 Post  | 
                                        
                                        
                                            
                                            
                                             Posted - 2015-05-01 : 19:41:44
                                            
  | 
                                             
                                            
                                            | Hello, I'm trying to create a function to correctly return the TotalExtendedPrice incorporating a discount.  I need the discount field to be a decimal (5,4) with input parameters of unitprice, quantity and the discount.  As an example, the result should yield 9.5 upon entering these values for the input parameters (2, 5, .05) respectively.  The following below is what I have so far but I'm still having trouble figuring this out.  Any help would be greatly appreciated.CREATE FUNCTION TEP(@unitprice AS INT NOT NULL,@quantity AS INT NOT NULL,@discount AS DECIMAL(5,4) NOT NULL)RETURNS INTASBEGINRETURN (TEP = @unitprice*@quantity-=@discount)ENDAs an example, the result after running the statement below,SELECT TotalExtendedPrice = dbo.TotalExtendedPrice(2, 5, .05) should be 9.5Thanks for your help in advance!RM | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     Kristen 
                                    Test 
                                     
                                    
                                    22859 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2015-05-02 : 03:42:31
                                          
  | 
                                         
                                        
                                          | [code]RETURN (TEP = @unitprice*@quantity-=@discount)[/code]should probably be[code]RETURN (@unitprice*@quantity) - (1.0-@discount)[/code]  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |