Function to return Sequential values


Working on some requirement I came across the situation where I have to generate the sequential values including each decimal from given input so; I created one function which generates the values in sequence from given input.

Workaround
Input = Minimum Value, Maximum Value
Output = Returns the Sequence table for given inputs

CREATE FUNCTION [dbo].[udf_utlGetSequencialValues]
(
      @nMinValue Numeric(5, 2),
      @nMaxValue Numeric(5, 2)
)
RETURNS @tblSequencialValues TABLE ( SequenceValue Numeric(5, 2) )
AS
BEGIN
      DECLARE @nCounter Numeric(5, 2)
      SET @nCounter = 0.1
      WHILE @nMinValue <= @nMaxValue BEGIN
            INSERT @tblSequencialValues VALUES( @nMinValue )
            SET @nMinValue = @nMinValue + @nCounter
      END
      RETURN
END
GO

 

How to Execute = SELECT * FROM [udf_utlGetSequencialValues](1, 2)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s