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 |
|
yukiever
Starting Member
13 Posts |
Posted - 2011-03-01 : 13:20:27
|
Hi,This seems hard for me....I have a table with column 'number'In that column I have 50,100,150,200,250,300 values.When a user choose a number 29, I want the row with '50' to return.When a user choose a number 99, I want the row with '100' to return.When a user choose a number 260, I want the row with '300' t return.So basically I want the floor of the number, increasing by 50.I tried different way, but too hard for me T.TSELECT * From test_table28 WHERE number BETWEEN GOT STUCK HERE |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2011-03-01 : 13:49:19
|
| Try this:--Sample DataCreate table #test(TestVal int)Insert into #testSelect 50 unionSelect 100 unionSelect 150 unionSelect 200 unionSelect 250 --Code to get the result.Declare @SearchVal intset @SearchVal = 29select * from #test where TestVal = (convert(int, @SearchVal +50)/50)*50Regards,Bohra |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-03-01 : 14:18:35
|
Check this out select top 1 col1 from tableName where Col1>=@value order by col1As per your inputs use Only > (greater than) sign in order to get the required results. But what if you provide input as 50 , still it should return 100? if so it would be fine to use > sign, but if you need to return 50 as a result of input=50 then use >= signCheersMIK |
 |
|
|
yukiever
Starting Member
13 Posts |
Posted - 2011-03-03 : 16:47:07
|
quote: Originally posted by MIK_2008 Check this out select top 1 col1 from tableName where Col1>=@value order by col1As per your inputs use Only > (greater than) sign in order to get the required results. But what if you provide input as 50 , still it should return 100? if so it would be fine to use > sign, but if you need to return 50 as a result of input=50 then use >= signCheersMIK
Thanks It works~! |
 |
|
|
yukiever
Starting Member
13 Posts |
Posted - 2011-03-03 : 16:47:39
|
quote: Originally posted by pk_bohra Try this:--Sample DataCreate table #test(TestVal int)Insert into #testSelect 50 unionSelect 100 unionSelect 150 unionSelect 200 unionSelect 250 --Code to get the result.Declare @SearchVal intset @SearchVal = 29select * from #test where TestVal = (convert(int, @SearchVal +50)/50)*50Regards,Bohra
Thanks for the reply!I got it working |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2011-03-04 : 10:15:10
|
Not happening Bret. Ever. EVAR.Now a tequila DB... possible http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
|
|
|
|
|