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 2005 Forums
 Transact-SQL (2005)
 SELECT TOP @MyVar * FROM EMPLOYEES

Author  Topic 

nice123ej
Starting Member

48 Posts

Posted - 2007-08-03 : 13:46:38
what can work similar to this other than dynamic sql EXEC('....')?!

DECLARE @MyVar int

SET @MyVar = 7

SELECT TOP @MyVar * FROM EMPLOYEES

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-08-03 : 13:50:05
SELECT TOP(@MyVar) * FROM EMPLOYEES

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-08-03 : 13:51:06
You need to use brackets.


SELECT TOP (@MyVar) *
FROM EMPLOYEES


Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-08-03 : 13:51:28


Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-08-10 : 08:05:59
hmmmm
7 days to give a wrong answer to an already (twice) answered question :).

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -