Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

SQL Function to get Max, Min values from given collection of values

By Bharat Panthee,

The 2 parameters in function are

Collection of values separated by specified separator(the separator defined in second parameter)

The second parameter is separator of collection values.


The function returns

The max value in the collection, min value in the collection and number of values in the collection.


For example:

if we run this statement

select * from dbo.GetMaxandMinValue('2,22,5,1,88,2000,7897,800',',')


The result will be:


minValue maxValue CountOfNumberSupplied
--------------------------------------- ----------------------------
1.00 7897.00 8


Total article views: 1692 | Views in the last 30 days: 8
Related Articles

problem in using parameters collection

problem in using parameters collection


Parsing Parameters in a Stored Procedure

This article shows a clean non-looping method to parse comma separated values from a parameter passe...


Problem with Data Collection

Data Collection, Query Statistics, collection_set_3_upload job failing





Operations Manager Custom Collection

An overview of how to collect data from TSQL into Operations Manager Performance Rules.


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones