Monday, September 16, 2013

SQL Server Function return FreightAmount as Decimal

Here's a simple function that will return the freight amount in decimal format.
 use Your_Database_Name  
 if object_id (N'dbo.getFreightValue', N'FN') is not null  
 drop function getFreightValue  
 go  
 create function getFreightValue  
 (  
   @salesID nvarchar(50)  
 )  
 returns decimal(10,2)   
 as  
 begin   
 declare @result varchar(50)   
 set @result =   
 (  
   select Freight   
     from dbo.Orders  
   where OrderID = @salesID   
 )  
 return @result  
 end  
 go  
 -- run function  
 -- select dbo.getSomeValue(10248) as freight_value;  
Cheers!

0 comments:

Post a Comment