# 如何從多值參數中找到最大值？

## 最佳答案

-- Check to see if only one value was selected
IF CHARINDEX(',', @month) = 0
BEGIN
SET @maxmonth = @month
END
ELSE
BEGIN
SET @maxmonth = RIGHT(@month, CHARINDEX(',', REVERSE(@month)) - 1)
END
PRINT @maxmonth


Now, if the multi-value parameter needs to first be sorted then you'll need to do a bit more work. See the following blog post to see how you can handle this situation: http://weblogs.asp.net/jmoon/archive/2005/04/01/396649.aspx