Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble using TOP operator

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am trying to do a query that involves a select with a top clause and i don't know how to receive the top parameter as a stored procedure parameter. It is, i am receiving the parameter as @n but when i do the

select top @n * from table

this is not accepted by the interpreter. Thanks for help me.
 
Try this:

[tt]exec ('select top ' + @n + ' * from mytable order by mycol')[/tt]

Ensure that @n is declared as char or varchar to use this syntax, or use CONVERT to convert an integer.

Robert Bradley

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top