I need to return X the number of records in the table based on the number of records in the subquery.
For example, if the TOP 80 PERCENT records in MYTABLE are 275 records, then I want to select 275 records from another table.
Is it possible to do this with simple dynamic SQL and without creating variables, etc.
My predecessor wrote something like this:
DECLARE @RecordVariable int SET @RecordVariable = (SELECT COUNT(*) * .8 FROM MYTABLE) SELECT TOP (@RecordVariable) * FROM MYOTHERTABLE ORDER BY NEWID()
source share