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
 SELECT MAX

Author  Topic 

spoutnick
Starting Member

6 Posts

Posted - 2011-08-19 : 09:51:46
HELLO ALL,

I HAVE A TABLE LIKE THIS

NBR_PO VAL
500 40
1000 555
1500 666
2000 777
2500 1566
3000 55555
3500 22222
10000 444444

I WOULD LIKE TO GET RESULT WHEN VARIABLE SUBMITED LIKE THIS
EXAMPLE 1
VAR_NBRE= 1689
OUTPOUT
NBR_PO VAL
1500 666
EXAMPLE 2
VAR_NBRE= 1100
OUTPOUT
NBR_PO VAL
1000 555

THANKS FOR HELP

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-08-19 : 10:19:09
Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Be One with the Optimizer
TG
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-08-19 : 10:19:47
You want the row with the next-lower NBR_PO value?

SELECT TOP 1 NBR_PO, VAL
FROM MyTable
WHERE NBR_PO <= VAR_NBRE
ORDER BY NBR_PO DESC
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-19 : 10:20:01
[code]
select top 1 *
FROM Table
WHERE NBR_PO < = @VAR_NBRE
ORDER BY NBR_PO DESC
[/code]

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

Go to Top of Page

spoutnick
Starting Member

6 Posts

Posted - 2011-08-19 : 10:44:00
THNAKS FOR REPLY ITS SO EASY
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-20 : 01:58:50
wc

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

Go to Top of Page
   

- Advertisement -