SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 sort result
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

HenryFulmer
Posting Yak Master

USA
110 Posts

Posted - 06/26/2013 :  03:52:34  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 06/26/2013 :  04:04:01  Show Profile  Reply with Quote

SELECT MIN(Val)
FROM dbo.ParseValues(YourResultCol,',')f


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

USA
110 Posts

Posted - 06/26/2013 :  04:32:05  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 06/26/2013 :  04:41:11  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

4604 Posts

Posted - 06/26/2013 :  12:44:42  Show Profile  Reply with Quote
Another option would be to modify the or create a new parse function that returns integer values.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000