| Author |
Topic |
|
sqlilliterate
Starting Member
40 Posts |
Posted - 2008-07-18 : 02:52:56
|
| I've the following values in a column(col1) in my table 1.01.10.121.121.91.102.12.102.122.2If i use select max(col1) from <table>am getting 2.2 as the max value. But I want 2.12 to be selected, which is the max value after the decimal point...Your query to make this work would immensely help me.thanks... |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-18 : 02:54:06
|
| what datatype is your column?Em |
 |
|
|
sqlilliterate
Starting Member
40 Posts |
Posted - 2008-07-18 : 02:58:37
|
| datatype is Varchar(10) |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-18 : 03:01:14
|
| max(cast(right(col1,charindex('.',col1,1)) as int))Em |
 |
|
|
charul
Starting Member
18 Posts |
Posted - 2008-07-18 : 03:17:02
|
quote: Originally posted by sqlilliterate I've the following values in a column(col1) in my table 1.01.10.121.121.91.102.12.102.122.2If i use select max(col1) from <table>am getting 2.2 as the max value. But I want 2.12 to be selected, which is the max value after the decimal point...Your query to make this work would immensely help me.thanks...Select A,CAST([NO] as Int)from (Select A, [NO]= SUBSTRING(cast(A as varchar),CHARINDEX('.',A,1)+1, LEN(A))from(Select 1.10 as [A]UNIONSelect 1.11 UNIONSelect 1.21UNIONSelect .13UNION Select 2.0)X )Y where CAST([NO] as Int)= (Select MAX(CAST([NO] as Int))from (Select A, [NO]= SUBSTRING(cast(A as varchar),CHARINDEX('.',A,1)+1, LEN(A))from(Select 1.10 as [A]UNIONSelect 1.11 UNIONSelect 1.21UNIONSelect .13UNION Select 2.0)X )Y )regdsCA
|
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-18 : 03:20:42
|
dude, don't you think that's just slightly over-complicating it?quote: Originally posted by charul
quote: Originally posted by sqlilliterate I've the following values in a column(col1) in my table 1.01.10.121.121.91.102.12.102.122.2If i use select max(col1) from <table>am getting 2.2 as the max value. But I want 2.12 to be selected, which is the max value after the decimal point...Your query to make this work would immensely help me.thanks...Select A,CAST([NO] as Int)from (Select A, [NO]= SUBSTRING(cast(A as varchar),CHARINDEX('.',A,1)+1, LEN(A))from(Select 1.10 as [A]UNIONSelect 1.11 UNIONSelect 1.21UNIONSelect .13UNION Select 2.0)X )Y where CAST([NO] as Int)= (Select MAX(CAST([NO] as Int))from (Select A, [NO]= SUBSTRING(cast(A as varchar),CHARINDEX('.',A,1)+1, LEN(A))from(Select 1.10 as [A]UNIONSelect 1.11 UNIONSelect 1.21UNIONSelect .13UNION Select 2.0)X )Y )regdsCA
Em |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-18 : 03:35:14
|
| declare @t table (col1 varchar(10))insert into @tselect '1.0'union all select '1.1'union all select'0.12'union all select'1.12'union all select'1.9'union all select'1.10'union all select'2.1'union all select'2.10'union all select'2.12'union all select'2.2' select MAX(cast(substring(col1,charindex('.',col1)+1,LEN(col1)) AS INT))from @tEm |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-18 : 04:08:33
|
| Select top 1 col from your_tableorder by parsename(col,2) desc,parsename(col,1)*1 descMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-18 : 04:12:11
|
I went for a meeting and didnt see the repliesMadhivananFailing to plan is Planning to fail |
 |
|
|
|