stored procedures - Syntax error when assign a variable for top clause in sql server -


i need top 10, top 100 records table. need assign value top clause such 10 or 100 in variable.

but when give below, gives syntax error "incorrect syntax near '@numberofrecords'.".

declare @numberofrecords int select @numberofrecords = configvalue tblconfigitems (nolock) configname = 'toprecords'  select top @numberofrecords [id],typeid, messagetype, operationdate notifytbl (nolock) status in ('1', '2') 

how achieve this?

avoid dinamic sql. use this:

select top (@numberofrecords) [id],typeid, messagetype, operationdate notifytbl (nolock) status in ('1', '2') 

you need @ least sql 2005 have working. yes () trick.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -