|
Hello friends,
I have a table..suppose having 3 columns.(Rate,FromQty,ToQty)
Now the Table have data on this format:
Rate FromQty ToQty
100 0 5
200 6 10
300 11 15
Now see for a particular product 0 to 5 have Rs.100.
Then 6 to 10 rate is Rs.200. and 11 to 15 is 300.
How can i get the rate of 2 qty.(i.e Rs.100 (0-5))
Pls can anybody send me the proper select statement..
thanks.
|
|
|
|
|
select rate where FromQty >= 0 and ToQty <= 5 ?
I'm not sure that I understand the question.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
No. i can enter any value through store procedure.it may be 2/8/13/19.
suppose i enter 2 then the row will be 100 0 5.
if i enter 8 then the row will be 200 6 10.
if i enter 13 then the row will be 300 11 15.
like this.
now if i generate this statement "select * from mratedetail where productcategoryid=49 and (toqty<=14.0 or fromqty>=14.0)" i have got all rows.
but in case of i want just "300 11 15".
thanks
|
|
|
|
|
Test270307 wrote: (toqty<=14.0 or fromqty>=14.0
That obviously won't work. I think if you use AND instead of OR, it may well work.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have many fields and many rows.
so if i put or then it return so many records.
doesn't work for "or".
thanks
|
|
|
|
|
Test270307 wrote: doesn't work for "or".
That's why I said you need to use AND
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
select rate from tbl where FromQty <= @amt and ToQty >= @amt
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
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.
|
|
|
|
|
|
SELECT rate
FROM Table1
WHERE (2 BETWEEN startQty AND endQty)
Pakistani Memon
Prime Minister
Post Meridian
|
|
|
|
|
please do help me to send mail from sql server via xp_sendmail
Develop2Program & Program2Develop
|
|
|
|
|
|
How can I do that, Please help a bit , for last 5 hours I am wrestling with it
Develop2Program & Program2Develop
|
|
|
|
|
|
|
thanks for your prompt reply , I will try those link , Hope i get the result
again thanks a lot
Develop2Program & Program2Develop
|
|
|
|
|
HI,
I am stuck in my project as.
i want to select primary key frm the data listed in grid view..so that i can use that key value to actually list the data which are related to tht key in other table...
so could any one tell how can i do tht...
|
|
|
|
|
You would have a datasource to ur grid right! that is datatable/dataset for this you can set a primary key.
Gautham
|
|
|
|
|
bind your Primary key field to the DataKey of gridview..
and then retreive data with....
Dim primaryField As String<br />
primaryField =myGridview.Datakeys(Seletedrow.index).value.tostring()
Tirtha
Miles to go before I sleep
|
|
|
|
|
thanks so much...for the tip..
but tell me one more thing now..
could i use this
"primaryfield" to comapre with detailview which is binded with anotehr dataset in which this primaryfield is a forign key
so will it work
detailview.pageindex = primaryField.to string() ;
or if u could guide me a bit on this..
tht will be very helpful
i am using C#
thanks again
govind
|
|
|
|
|
please be specific...I could't understand your problem
Tirtha
Miles to go before I sleep
|
|
|
|
|
Hi
select CAST((datediff(day,createdon,getdate())/30) as float) Avg, from customers
I want to give the result in Fraction is it possible? it is not showing the fraction result.
createdon is the datetime field
Any Help is appreciated.
Regards
Shahzad Aslam
Software Engineer
|
|
|
|
|
datediff function's date part "day"
returns difference in number of days i.e 1 / 2 / 3 .....
if u r looking for even part of day, get the difference in hours/minutes/ ...
then try converting that to days so that you get the result as you are expecting
Regards
KP
|
|
|
|
|
|
You can use a cursor to do something similar to a for loop, but it is very slow compared to a single update statement. I would suggest you think seriously about using a single update statement instead.
Ben
|
|
|
|