See
How to return a value from dynamicaly executed T-SQL code FAQ #8130
>I want to write a generic stored procedure to get the max value in a field. In VFP I would do it something like
>SELECT MAX(&lcField) FROM &lcTable
>how should I do this as a stored procedure in SQL?
--sb--