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
 get the minimum value

Author  Topic 

vmurali
Yak Posting Veteran

88 Posts

Posted - 2007-09-17 : 03:20:02
In my table I have values like (2,3). I want to get the minimum value from the column

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-17 : 03:42:10
use min() function

select min(yourcol) from yourtable



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

vmurali
Yak Posting Veteran

88 Posts

Posted - 2007-09-17 : 03:44:08
i have values like

task
2,3
5,4
8,9

I need to minimum value of task

task
2
4
8
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-17 : 03:46:18
are you using SQL Server 2005 or 2000 ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

vmurali
Yak Posting Veteran

88 Posts

Posted - 2007-09-17 : 03:47:28
SQL 2005
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-17 : 03:58:44
[code]DECLARE @TABLE TABLE
(
task varchar(10)
)
INSERT INTO @TABLE
SELECT '2,3' UNION ALL
SELECT '5,4' UNION ALL
SELECT '8,9'

SELECT min_value = MIN(numberval)
FROM @TABLE t CROSS apply CSVTable(task) c
GROUP BY task

/*
min_value
-----------
2
4
8
*/
[/code]

-- CSVTable can be obtain from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25830&SearchTerms=CSVTable


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-17 : 04:10:46
Also make sure you follow normalization
http://databases.about.com/od/specificproducts/a/normalization.htm

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

nkarthick
Starting Member

3 Posts

Posted - 2007-09-17 : 07:48:09
Hi,

Try this See it ok for you :-

create TABLE TestMin
(
Test varchar(10)
)

INSERT INTO TestMin
SELECT '2,3' UNION ALL
SELECT '5,4' UNION ALL
SELECT '8,9'


select
case
when convert(int,Left(Test,charindex(',',Test) - 1)) > convert(int,Right(Test,Len(Test) - charindex(',',Test))) then Right(Test,Len(Test) - charindex(',',Test))
else Left(Test,charindex(',',Test)- 1)
end
from TestMin

Regards,

Narayana Karthick
(VBA Developer)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-17 : 08:09:58
Narayana,

this would limit to only 2 value in the csv string right ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-17 : 08:14:58
Who knows? The sample data only demonstrates this.
OP do not tell us...



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

nkarthick
Starting Member

3 Posts

Posted - 2007-09-17 : 08:23:53
Khtan,

Yes, my query is limited to 2 values in a column. Do u need more than that?

Regards,

Narayana Karthick
(VBA Developer)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-17 : 08:28:59
nope. Not for me. It is up to the OP


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-17 : 08:29:23
quote:
Originally posted by nkarthick

Khtan,

Yes, my query is limited to 2 values in a column. Do u need more than that?

Regards,

Narayana Karthick
(VBA Developer)


There wont be any complexity in code if you follow my suggestion
You can send array of data and dont store them

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -