Is there a way to select top n records based on the value from the table? Basically I want to pass that "n" value using a variable.
So from example shown below, I want to select top 9 records using the query below for CompA and top 77 records for CompB and so on..
How can I do that?
I have a temp table that has value as below
Select details.Item as Barcode
, details.user_component as user_component
, details.component as Purchased_by
, details.location + '/' + details.ROOM_CUBICLE as Location
, mac.UserName as LastLogon
from dbo.VW_ASSETS_DETAILS details
left join TBL_REFRESHED refreshed on refreshed.Barcode = details.Item
left join dbo.TBL_All_ActiveUsers epic on details.ein = epic.ein
left join dbo.TBL_All_MachineName mac on details.item = mac.barcode
Where category like 'SMW' and not details.location in ('Dept')
and (refreshed.refreshed like 'No' or refreshed.refreshed is null) and asset_status = 'Deployed'
and details.manufacturer like 'Dell' and not details.model in ('E-6420','E-6320')
order by warranty_exp_date asc