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
 General SQL Server Forums
 New to SQL Server Programming
 Select TOP

Author  Topic 

sign_seventh
Yak Posting Veteran

66 Posts

Posted - 2007-04-12 : 03:55:14
Hi guys,
what is the right syntax for
< select TOP (select count(*) from tablename) >

is is possible?

thnx

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-12 : 03:57:56
Did you get any error when you tried?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-12 : 03:59:08
[code]SELECT TOP (SELECT COUNT(*) FROM sys.sysobjects)
*
FROM master..spt_values[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

sign_seventh
Yak Posting Veteran

66 Posts

Posted - 2007-04-12 : 04:05:53
FOR EXMPLE:
select top (select count(*) from GRP_GROUPS) GRP_GROUP_ID from GRP_GROUPS

ERROR MSG:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '('.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'GRP_GROUP_ID'.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-12 : 04:15:14
You know that dynamic TOP value only applies to SQL Server 2005?
If you are using SQL Server 2000,

DECLARE @X INT
SELECT @X = COUNT(*) FROM Table1

SET ROWCOUNT @X

SELECT * FROM Table2

SET ROWCOUNT 0


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

sign_seventh
Yak Posting Veteran

66 Posts

Posted - 2007-04-12 : 04:20:49
ok thnx
Go to Top of Page
   

- Advertisement -