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.
Author |
Topic |
kulkarni_ajit
Starting Member
4 Posts |
Posted - 2009-03-11 : 06:31:55
|
HiI have table called LTDriveSelectionNewwith Field ref Voltage ref1 0.1ref2 0.2ref3 0.3ref4 0.4ref5 0.5...... and so oni want to select vaules Nerest valuefor Eg.Select Ref,Voltage from LTDriveSelectionNewwhere voltage= 0.31then it should displaynearest Min values ie Ref2 0.3please reply me it is urgentwaiting for your replyregardsajit |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-03-11 : 06:40:54
|
[code]-- Prepare sample dataDECLARE @Sample TABLE ( ref VARCHAR(10), Voltage DECIMAL(5, 2) )INSERT @SampleSELECT 'ref1', 0.1 UNION ALLSELECT 'ref2', 0.2 UNION ALLSELECT 'ref3', 0.3 UNION ALLSELECT 'ref4', 0.4 UNION ALLSELECT 'ref5', 0.5-- Initialize user supplied parameterDECLARE @v DECIMAL(5, 2)SET @v = 0.31-- Display the resultSELECT TOP 1 WITH TIES ref, VoltageFROM @SampleORDER BY ABS(Voltage - @v)[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|