Click here to monitor SSC
SQLServerCentral is supported by Redgate
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: 1719 | Views in the last 30 days: 2
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.