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 |
|
indraja
Starting Member
6 Posts |
Posted - 2007-02-15 : 02:14:34
|
| I have to pick values from a table.Like if i have 1 i need to pick 2,if 2 is not there the next higher number like 3,4........ |
|
|
eyechart
Master Smack Fu Yak Hacker
3575 Posts |
Posted - 2007-02-15 : 02:30:24
|
something like this maybe:SELECT MIN(val)FROM yourtableWHERE val > seedvalue seedvalue being 1 (as in your example). If 2 was not the next value available, it would grab the next highest as you want. Give it a shot.btw, we can better answer these questions if you post DDL of your table, some sample data and and example of the desired output.-ec |
 |
|
|
indraja
Starting Member
6 Posts |
Posted - 2007-02-15 : 03:45:33
|
quote: Originally posted by eyechart something like this maybe:SELECT MIN(val)FROM yourtableWHERE val > seedvalue seedvalue being 1 (as in your example). If 2 was not the next value available, it would grab the next highest as you want. Give it a shot.btw, we can better answer these questions if you post DDL of your table, some sample data and and example of the desired output.-ec
Sample Data123568...if i pick 1 i must get 2.if i pick 2 i must get 3.if i pick 3 then 4 is not there then i shud get 5then so on..... |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-15 : 04:27:12
|
| SELECT TOP 3 Col1FROM Table1ORDER BY Col1Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-15 : 04:28:11
|
| DECLARE @TopMost INTSELECT @TopMost = 7SELECT TOP (@TopMost) Col1FROM Table1ORDER BY Col1Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|