Click here to Skip to main content
15,891,253 members
Home / Discussions / Database
   

Database

 
QuestionUrgent Pin
Test27030730-Mar-07 2:51
Test27030730-Mar-07 2:51 
AnswerRe: Urgent Pin
Christian Graus30-Mar-07 3:06
protectorChristian Graus30-Mar-07 3:06 
GeneralRe: Urgent Pin
Test27030730-Mar-07 3:44
Test27030730-Mar-07 3:44 
GeneralRe: Urgent Pin
Christian Graus30-Mar-07 4:00
protectorChristian Graus30-Mar-07 4:00 
GeneralRe: Urgent Pin
Test27030730-Mar-07 4:02
Test27030730-Mar-07 4:02 
GeneralRe: Urgent Pin
Christian Graus30-Mar-07 4:04
protectorChristian Graus30-Mar-07 4:04 
AnswerRe: Urgent Pin
Christian Graus30-Mar-07 4:04
protectorChristian Graus30-Mar-07 4:04 
AnswerRe: Urgent Pin
DQNOK30-Mar-07 4:09
professionalDQNOK30-Mar-07 4:09 
SELECT Rate
FROM MyRateTable
WHERE 2 >= FromQty
AND 2 <= ToQty

Or, more generically,

SELECT Rate
FROM MyRateTable
WHERE @qty >= FromQty
AND @qty <= ToQty

Unless the FromQty and ToQty columns are indexed, the db will have to do a full scan to select ALL the rows that meet the @qty >= FromQty, then will have to do another full scan of all the selected rows to determine which of them meet the @qty <= ToQty requirement.

Alternately, if you're using a product that supports the "TOP" keyword, and you have the ToQty column indexed in assending order, you could use

SELECT TOP 1 Rate, ToQty
FROM MyRateTable
WHERE @qty <= ToQty
ORDER BY ToQty

and just ignore the ToQty in the return. This will guarantee good performance as the query will recognize the ORDER BY clause and use the existing index for the select.

Lastly, if your table really is as simple as the data you have used for your example, a mathematical formula would be better.

int getRate( int myQty )
{
if( myQty = 0 ) return 100;
else return (1+((myQty-1)/5))*100;
}

which could also be converted to SQL if you wanted.

Hope this helps.
GeneralRe: Urgent Pin
Test27030730-Mar-07 18:40
Test27030730-Mar-07 18:40 
AnswerRe: Urgent Pin
Noman Aftab31-Mar-07 1:01
Noman Aftab31-Mar-07 1:01 
Questionserver : error 18025 Pin
Navneet Hegde30-Mar-07 2:47
Navneet Hegde30-Mar-07 2:47 
AnswerRe: server : error 18025 Pin
kubben30-Mar-07 3:45
kubben30-Mar-07 3:45 
GeneralRe: server : error 18025 Pin
Navneet Hegde30-Mar-07 3:47
Navneet Hegde30-Mar-07 3:47 
GeneralRe: server : error 18025 Pin
kubben30-Mar-07 3:54
kubben30-Mar-07 3:54 
GeneralRe: server : error 18025 Pin
kubben30-Mar-07 3:56
kubben30-Mar-07 3:56 
GeneralRe: server : error 18025 Pin
Navneet Hegde30-Mar-07 3:58
Navneet Hegde30-Mar-07 3:58 
Questionselecting primary key from grid view Pin
govindkedia30-Mar-07 1:07
govindkedia30-Mar-07 1:07 
AnswerRe: selecting primary key from grid view Pin
gauthee30-Mar-07 1:47
gauthee30-Mar-07 1:47 
AnswerRe: selecting primary key from grid view Pin
Tirthadip30-Mar-07 1:54
Tirthadip30-Mar-07 1:54 
GeneralRe: selecting primary key from grid view Pin
govindkedia30-Mar-07 2:19
govindkedia30-Mar-07 2:19 
GeneralRe: selecting primary key from grid view Pin
Tirthadip30-Mar-07 2:39
Tirthadip30-Mar-07 2:39 
QuestionNeed Help In Query: Pin
Shahzad.Aslam30-Mar-07 0:44
Shahzad.Aslam30-Mar-07 0:44 
AnswerRe: Need Help In Query: Pin
Krish - KP30-Mar-07 1:00
Krish - KP30-Mar-07 1:00 
QuestionChange a field on all tabel ,, row by row ? Pin
kindman_nb30-Mar-07 0:33
kindman_nb30-Mar-07 0:33 
AnswerRe: Change a field on all tabel ,, row by row ? Pin
kubben30-Mar-07 2:19
kubben30-Mar-07 2:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.