Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Lowest value of list, not MIN()

Author  Topic 

detlion1643
Yak Posting Veteran

67 Posts

Posted - 2010-05-28 : 10:17:02
I am looking for a way to find the lowest value in a list of 6 values. Lets say I am looking to do something like this: MIN(3,4,1,8,2,9), it should return 1. But since MIN only works for a column, I'm not sure what else could be used.

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-05-28 : 10:34:07
You can use row_number() function for the same.

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-05-28 : 10:34:49
quote:
Originally posted by detlion1643

I am looking for a way to find the lowest value in a list of 6 values. Lets say I am looking to do something like this: MIN(3,4,1,8,2,9), it should return 1. But since MIN only works for a column, I'm not sure what else could be used.


Can you explain with some sample data from your tables and expected output?
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-05-28 : 10:35:28
use visakhs function ParseValues. It will return a column that you can take a min on

SELECT MIN(f.Val)
FROM Table t
CROSS APPLY dbo.ParseValues(t.field,'_')f
GROUP BY t.Field

http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

detlion1643
Yak Posting Veteran

67 Posts

Posted - 2010-05-28 : 10:45:59
Thanks jimf!
Changed a little bit up to fit my needs, but works nonetheless!
Go to Top of Page
   

- Advertisement -