R
RCL
In access there is a first function. Is there anything the equivalent of
First() in Transact SQL?
First() in Transact SQL?
RCL said:First or Last function returns a field value from the first or last record
in the result set returned by a query.
I tried to use top 1 to get the same results but ran into the issue of
duplicates. See example below:
Please note that on IDToUse = 1158, top
1 works correctly because there are no duplicate values. On IDToUse =
1156
and 1157, top 1 returns multiple values.
SELECT PracSums.IDtoUse, PracSums.pname, PracSums.Claims, PracSums.Billed,
PracSums.Approved
FROM PracSums
WHERE (((PracSums.Approved)
In
(
SELECT TOP 1 [SubQ1].[Approved]
FROM [PracSums] AS [SubQ1]
WHERE [SubQ1].[IDtoUse] =[PracSums].[IDtoUse]
Order By [SubQ1].[Approved] Desc)))
Using sample data:
IDtoUse pname Claims Billed Approved
1156 TEST1 2 300 193
1156 TEST2 2 300 193
1156 TEST3 2 300 193
1157 Next1 1 80 63
1157 Next2 1 80 63
1158 Another1 0 0 1
1158 Another2 0 0 2
1158 Another3 0 0 3
1158 Another4 0 0 4
Datawonk said:I'm not familiar with the first function, but if you mean the first row
in a recordset, you would do SELECT TOP 1 * from table ....
If you can explain what the first function does, I can probably help
more.
Thanks,
Birgit
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.