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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 sort result

Author  Topic 

HenryFulmer
Posting Yak Master

110 Posts

Posted - 2013-06-26 : 03:52:34
I have a query result that gives me the follwoing value:
296,492,50
This gets return as a string.
I need to be able to extract the lowest numerical value in this string.
How do I go about it?
Thanks for your help.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-26 : 04:04:01
[code]
SELECT MIN(Val)
FROM dbo.ParseValues(YourResultCol,',')f
[/code]

Parsevalues can be found here

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

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

HenryFulmer
Posting Yak Master

110 Posts

Posted - 2013-06-26 : 04:32:05
Thanks - when I use this it seems to sort by the value of the first number only.
SELECT MIN(Val)
FROM dbo.ParseValues('296,482,50',',')f
returns 296
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-26 : 04:41:11
i got issue. the return type was varchar

you could use this small modification


SELECT MIN(Val*1)
FROM dbo.ParseValues('296,482,50',',')f


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-06-26 : 12:44:42
Another option would be to modify the or create a new parse function that returns integer values.
Go to Top of Page
   

- Advertisement -