my code stock.com

Function which returns a range of integer values between two values supplied in argument.

Snippet options

Download: Download snippet as generate-integer-range.sql.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

/* ***************************************************************************************************
 * Project Name:          	THOT
 * Project Version:      	$VersionInfo$
 * Creation Date:         	10 may 2012
 * Author:                	dfe
 * Classes Name:          	$ClassName$
 * General Description:	
Function which returns a range of integer values between two values supplied in argument.
Example :
select * from tvf_generateMonth(25, 30)
returns :
	25
	26
	27
	28
	29
	30
 * References:            	$Reference$
 * ====================================================================================================
 * MODIFICATIONS
 * ----------------------------------------------------------------------------------------------------
 * Date            	Author        			Description			Project id
 * ----------------------------------------------------------------------------------------------------
 * Please complete after each code modification.
 * <date>          	<author>      			<fix id>			<documentation id>
 * <description of changes>
 * ************************************************************************************************* */
CREATE FUNCTION [dbo].[tvf_generateIntegerRange]
(	
	@Start as INT,
	@End INT
)
RETURNS TABLE 
AS
RETURN 
(
	with mycte as
	(
		select  @Start as RangeValue
		union all
		select RangeValue + 1
		from    mycte   
		where   (RangeValue + 1) <= (@Start + (@End - @Start))
	)

	SELECT 
		RangeValue
	FROM mycte
)


GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Function which returns a range of integer values between two values supplied in argument.
Example :
select * from tvf_generateMonth(25, 30)
returns :
	25
	26
	27
	28
	29
	30' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'FUNCTION',@level1name=N'tvf_generateIntegerRange'
GO

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.