Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 using varibale with top in query

Author  Topic 

xpandre
Posting Yak Master

212 Posts

Posted - 2003-11-24 : 03:51:26
hi,
this is my query

select top 1 * from (select top @num * from emptest order by sal desc) b order by sal asc

it gives Line 3: Incorrect syntax near '@num'.

can any one pls correct this query..
thank you

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-11-24 : 04:06:20
declare @sql nvarchar(500)
declare @num int
set @sql='select top 1 * from (select top'+convert(varchar(10), @num)+' * from emptest order by sal desc) b order by sal asc'
exec sp_executesql @sql

The Judgement of the Judge is as good as the Judge.
Go to Top of Page

xpandre
Posting Yak Master

212 Posts

Posted - 2003-11-24 : 04:18:57
thanks harshal..
Go to Top of Page
   

- Advertisement -