SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select TOP
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sign_seventh
Yak Posting Veteran

66 Posts

Posted - 04/12/2007 :  03:55:14  Show Profile  Send sign_seventh a Yahoo! Message  Reply with Quote
Hi guys,
what is the right syntax for
< select TOP (select count(*) from tablename) >

is is possible?

thnx

SwePeso
Patron Saint of Lost Yaks

Sweden
30219 Posts

Posted - 04/12/2007 :  03:57:56  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Did you get any error when you tried?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30219 Posts

Posted - 04/12/2007 :  03:59:08  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT	TOP (SELECT COUNT(*) FROM sys.sysobjects) 
	*
FROM	master..spt_values


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

sign_seventh
Yak Posting Veteran

66 Posts

Posted - 04/12/2007 :  04:05:53  Show Profile  Send sign_seventh a Yahoo! Message  Reply with Quote
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

Sweden
30219 Posts

Posted - 04/12/2007 :  04:15:14  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 - 04/12/2007 :  04:20:49  Show Profile  Send sign_seventh a Yahoo! Message  Reply with Quote
ok thnx
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000