Donate

SQL Server Function Date Range Example

The function below retrieves the top Freight amount specified by date range values
use CompanySales  
 IF object_id (N'dbo.GetTopFreightValueRange', N'FN') IS NOT NULL  
 drop function GetTopFreightValueRange  
 go  
 create function GetTopFreightValueRange  
 (  
   @startDate nvarchar(50), @endDate nvarchar(50)  
 )  
 returns decimal(10,2)   
 as  
 begin   
 declare @result varchar(50)   
      set @result =   
      (  
            select FreightAmount   
                 from dbo.Orders  
            where CONVERT(VARCHAR(10), ShippedDate, 120) >= @startDate  
                  and  
                  CONVERT(VARCHAR(10), ShippedDate, 120) <= @endDate  
      )  
 return @result  
 end  
 go  
-- select dbo.GetTopFreightValueRange('1996-11-01','1996-11-30') as freight_value;

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input