Re: Top10 from another view
- From: "Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
- Date: Tue, 14 Feb 2006 12:37:18 -0500
Nope, I have no other idea. This query is the best thing that I could make
from what I've understood of your description of the problem and the fact
that I cannot test it because I don't have access to your design and data.
I suggest that you first try by using a SP and a temporary table (or a local
variable table) instead of a View. With the use of a temporary table, you
can easily divide your problem into each of its steps. Sometimes, it may
also require the use of a Cursor but as it seems that I don't really
understand your problem, I cannot tell you more on this.
Often, you can achieve the same result with correlated subqueries but this
require a lot more of experience because their understanding is much more
complicated.
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
"Jose Perdigao" <perdijc@xxxxxxxxxxx> wrote in message
news:uGEe7cWMGHA.500@xxxxxxxxxxxxxxxxxxxxxxx
Hi Sylvain,
Have you any ideia how to crete the query?
Thanks
josé perdigão
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:uCG7Q4ZLGHA.3984@xxxxxxxxxxxxxxxxxxxxxxx
Creating such a query is called Ranking and is usually done with the use
of correlated subqueries. In the case of a SP, you can also use a cursor
and a temporary or a local table to achieve it. For the View, it is also
a requirement that each record has a primary key (you can achieve it
without using a primary key but it's much more complicated.
Here a possible solution that I didn't test. It's based on the fact that
the primary column is the ID field. Notice the use of the alias w1 and
w2:
SELECT w1.dDate, w1.Well, w1.TestGood, w1.TestOil, w1.TestWater
FROM dbo.J1_WTzDL w1
Where w1.Id in (select top 10 w2.Id from dbo.J1_WTzDL w2 where
(w2.Well = w1.Well) and (w2.dDate <= dbo.iDate()) order by dDate desc)
ORDER BY w1.Well ASC, w1.dDate DESC
Also, using a temporary or local table with a cursor will probably be a
much more efficient design. For other ideas on ranking issues; see
http://www.aspfaq.com/show.asp?id=2427 .
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
"Jose Perdigao" <perdijc@xxxxxxxxxxx> wrote in message
news:u2ks%23dYLGHA.3468@xxxxxxxxxxxxxxxxxxxxxxx
I would like to create a view based in a sp or another view like the
following example:
SELECT dDate, Well
FROM dbo.J1_WTzDL
WHERE (dDate = iDate())
We have results as below:
dDate
Well
10/12/2005
ALB - 4H
10/12/2005
BAG - 4L
10/12/2005
CHO - 1
10/12/2005
EST-A-2
10/12/2005
EST-B-1
Now, I would like to create a view to show the top 10 for each well from
the results above and dDate<=iDate()
The following view is not complete I don't know how I can report the top
10 for each well.
SELECT TOP 10 dDate, Well, TestGood, TestOil, TestWater
FROM dbo.J1_WTzDL
WHERE (dDate <= dbo.iDate())
ORDER BY dDate DESC
How can I create this view?
Thanks
josé perdigão
.
- Follow-Ups:
- Re: Top10 from another view
- From: Jose Perdigao
- Re: Top10 from another view
- References:
- Top10 from another view
- From: Jose Perdigao
- Re: Top10 from another view
- From: Sylvain Lafontaine
- Re: Top10 from another view
- From: Jose Perdigao
- Top10 from another view
- Prev by Date: Re: Help with Master/Detail UI in ADPs
- Next by Date: Re: ADP closing application without warning
- Previous by thread: Re: Top10 from another view
- Next by thread: Re: Top10 from another view
- Index(es):
Relevant Pages
|