For one report I am making query where users suppose have to choice TOP values based on percents or fix amount of rows.
I have two ideas
Calling two different sub sproc based on passed param.
if @param ='percent' begin exec sp_data_TOP_by_Percent end if @param ='perRow' begin exec sp_data_TOP_by_PerRow end
other idea is to make dynamic TSQL query something like this
declare @command nchar(max) select @command = 'select top(10) ' + case @param when 'percent' then percent else ' ' end + ' * ' + 'from table order by 1'; exec sp_executesql @command
Is there third solution for something like this ?
What is better approach ? First one avoiding dynamic TSQL but is harder to maintain code in two places. I am using MSSQL2005 as databse.