TOP x PERCENT

  • Thread starter Thread starter jonathan
  • Start date Start date
J

jonathan

hi all,

was wondering if i can do user input variable x rather
than fixed value on SELECT TOP.what i did at the moment is
fixed one whioch sql shown below;

SELECT TOP 1 table.* FROM(SELECT TOP 60 PERSENT table.*
from table) AS x ORDER BY id DESC;

now is it possible that i can make that x as input value
by user so that it would be somthing like this

SLECT TOP [input persent]*count(table.[id]) table.* FROM
table

thanks
 
I don't believe you can use a parameter in the predicate of the query like
that.

However, you can build a string, and then assign it to the SQL property of
your QueryDef, to the RecordSource of your form, or (in Report_Open only) to
the RecordSource of your report.
 
can you please share me its code?im quite new to vba so
cant really understand how to do

thanks
-----Original Message-----
I don't believe you can use a parameter in the predicate of the query like
that.

However, you can build a string, and then assign it to the SQL property of
your QueryDef, to the RecordSource of your form, or (in Report_Open only) to
the RecordSource of your report.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

was wondering if i can do user input variable x rather
than fixed value on SELECT TOP.what i did at the moment is
fixed one whioch sql shown below;

SELECT TOP 1 table.* FROM(SELECT TOP 60 PERSENT table.*
from table) AS x ORDER BY id DESC;

now is it possible that i can make that x as input value
by user so that it would be somthing like this

SLECT TOP [input persent]*count(table.[id]) table.* FROM
table

thanks


.
 
What is the context where you want to do this?
For a report?
For a form?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

jonathan said:
can you please share me its code?im quite new to vba so
cant really understand how to do

thanks
-----Original Message-----
I don't believe you can use a parameter in the predicate of the query like
that.

However, you can build a string, and then assign it to the SQL property of
your QueryDef, to the RecordSource of your form, or (in Report_Open only) to
the RecordSource of your report.


was wondering if i can do user input variable x rather
than fixed value on SELECT TOP.what i did at the moment is
fixed one whioch sql shown below;

SELECT TOP 1 table.* FROM(SELECT TOP 60 PERSENT table.*
from table) AS x ORDER BY id DESC;

now is it possible that i can make that x as input value
by user so that it would be somthing like this

SLECT TOP [input persent]*count(table.[id]) table.* FROM
table

thanks
 
Back
Top