开发者

How can I find the maximum value from a multi value parameter?

I have a multi select parameter (@month) that lists all 12 m开发者_如何转开发onths. The label is the abbreviation (Jan, Feb), the value is the integer for the month (1, 2).

I have another parameter (@maxmonth) that is internal that I want to store the maximum month that was selected in. So if the user selected January and March, @maxmonth would = 3.

Any ideas?


In your stored procedure, you'll need to set @maxmonth to the last value of @month. Since SQL Server treats multi-value parameters as a comma-delimited string, the following will help you to get the last value.

-- 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜