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 2005 Forums
 Transact-SQL (2005)
 select query to get max decimal value

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2010-05-14 : 14:29:44
I have field name sequenceno.
eaxmple:
if i pass 7 as sequence to get max sequence in seven series to check table_orderdetails.

i have 7.0, 7.01, 7.02, 7.03
then it should get 7.03 is the max is 7 series.

Can you please tell me how to wrtite select to get max in that number series.

select max(seqNo) from table_orderdetails
where seqno in series 7

Thank you very much for the helpful info.

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-05-14 : 14:37:15
[code]select max(seqno) from table_orderdetails
where seqno >= @search_int
and seqno < (@search_int + 1)[/code]
or
[code]select max(seqno) from table_orderdetails
where seqno like convert(varchar(10),@search_int) + '%'[/code]

@search_int can be your value that you pass
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-05-14 : 15:07:02
Are you looking for something like this?


CREATE TABLE #myTable99 (
id int IDENTITY(1,1)
, Series decimal(10,2)
)
GO


INSERT INTO #myTable99 (Series)
SELECT 7.0 UNION ALL
SELECT 7.01 UNION ALL
SELECT 7.02 UNION ALL
SELECT 7.03 UNION ALL
SELECT 8.0 UNION ALL
SELECT 8.01 UNION ALL
SELECT 8.02
GO



SELECT FLOOR(Series), MAX(Series)
FROM #myTable99
GROUP BY FLOOR(Series)
GO

DROP TABLE #myTable99
GO




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-05-14 : 22:58:40
select max(seqNo) from table_orderdetails
where seqno >= 7 and seqno < 8

______________________
Mayazar Mori Ke Dane Keshast
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-15 : 03:19:15
quote:
Originally posted by cplusplus

I have field name sequenceno.
eaxmple:
if i pass 7 as sequence to get max sequence in seven series to check table_orderdetails.

i have 7.0, 7.01, 7.02, 7.03
then it should get 7.03 is the max is 7 series.

Can you please tell me how to wrtite select to get max in that number series.

select max(seqNo) from table_orderdetails
where seqno in series 7

Thank you very much for the helpful info.



whats datatype of field containing the values?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -