SQL Statement SELECT TOP * PERCENT

G

Guest

Hi all,

I'm trying to get an access query to select a top percentage based on a
value in a form. Here is my current SQL Statement:

SELECT dbo_eco_loan_map.loannum, dbo_eco_loan_map.contractcode
FROM dbo_eco_loan_map
WHERE (((dbo_eco_loan_map.contractcode)=[Forms]![ARMReviewfrm]![Text62]));

When adding "TOP [Forms]![ARMReviewfrm]![Text66] PERCENT" after SELECT I'm
getting an error. Is there a way to allow the TOP PERCENT to use a value
from a field/form rather than per defined?

Appreciate the help/
 
G

Guest

I apologize, I meant choose a RANDOM percentage. The RANDOM percentage being
the field in the form
 
V

Van T. Dinh

Not AFAIK of. The usual work-around is to construct the SQL dynamically
using VBA where the Percent value is resolved by VBA code, i.e. in the
resultant Query, the % value is an explicit value.
 
A

aaron.kempf

yeah just so it inline

CREATE PROC GetXPercentSales
(
@P TINYINT
)

AS

DECLARE @S_SQL VARCHAR(1000
SET @S_SQL = 'SELECT TOP ' + CONVERT(VARCHAR(3), @P) + ' PERCENT FROM
ORDERS ORDER BY GRANDTOTAL DESC'

XP_EXECUTESQL @S_SQL




that works for you right?

-Aaron
 

Ask a Question

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.

Ask a Question

Top