Rx_
Nothing In Moderation
- Local time
- Today, 12:02
- Joined
- Oct 22, 2009
- Messages
- 2,803
Trying to create a View that shows the Top 1 ID_Wells in a table where the Autocounter (record ID) is APD_FieldWorkDates.
The table name is APDFieldWorkDate_2
Here is an article with data example:
http://sqlserverplanet.com/tsql/selecting-top-n-records-per-group
I didn't do the first T-SQL statement because the two columns needed already exist.
My code looks like:
It works, but sadly, only returns 1 single record (a top 2 returns 2 records).
Trying to get the first Record for a Grouping of ID_Wells
also that meets the criteria shown.
Just baffled!
This View will eventually be outer joined by another query based on the ID_Wells.
I got this to work using Access SQL, using the Grouping
But, the sql won't translate into SQL Server.
The table name is APDFieldWorkDate_2
Here is an article with data example:
http://sqlserverplanet.com/tsql/selecting-top-n-records-per-group
I didn't do the first T-SQL statement because the two columns needed already exist.
My code looks like:
Code:
SELECT ID_Wells, ID_Bio_Svy_Type, Dt_Arch_Req AS DtRequested, Dt_Survey AS HasPlats, Dt_Arch_Rpt AS DtReceived, APD_FieldWorkDates
FROM APD_FieldWorkDate_2
WHERE (ID_Bio_Svy_Type IN (15, 18)) AND (NOT (Dt_Survey IS NULL)) AND (NOT (Dt_Arch_Rpt IS NULL)) AND (ID_Wells IN
(SELECT top 1 APD_FieldWorkDate_2.ID_Wells
FROM APD_FieldWorkDate_2
Where APD_FieldWorkDates = APD_FieldWorkDate_2.APD_FieldWorkDates
Order by APD_FieldWorkDate_2.APD_FieldWorkDates))
order by ID_Wells
It works, but sadly, only returns 1 single record (a top 2 returns 2 records).
Trying to get the first Record for a Grouping of ID_Wells
also that meets the criteria shown.
Just baffled!
This View will eventually be outer joined by another query based on the ID_Wells.
I got this to work using Access SQL, using the Grouping
But, the sql won't translate into SQL Server.