C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




TOP function


Posted Date: 05 Sep 2008      Total Responses: 8

Posted By: Neethul Raveendran       Member Level: Silver     Points: 1


Hi All,
Can i pass the column count of subquery to the outer query having TOP

example:
select top c * from (select count(*) as c from ##temp)

Please revert back at the earliest
And also provide any alternative solutions but i need to use
"Top" clause compulsoryly...

Thanks in advance.




Responses

Author: ANIL PANDEY    05 Sep 2008Member Level: DiamondRating:     Points: 2
hi,

u can use like this,

select top 1 count(*) as c from ##temp


hope this will work for u...


regards
Anil


Author: Neethul Raveendran    05 Sep 2008Member Level: SilverRating:     Points: 2
thats k... but i need to apply where subquery will be returning values only because in my project the subquery count will return more than one
values which i need to use based on the conditions
Please put ur thoughts to this.

Thanks in advance.


Author: Geetha    05 Sep 2008Member Level: GoldRating:     Points: 1
hi
i tried a query like that.
but it is not possible it seems.
better u split it into two queries and try.
First get the count. and then use it with the top.

Geetha.


Author: Neethul Raveendran    05 Sep 2008Member Level: SilverRating:     Points: 1
thats fine... hope ur telling the alternative solutions.
If yes please can u demostrate with an example

Thanks in advance.



Author: Barani     05 Sep 2008Member Level: SilverRating:     Points: 1
can u give me somemore details regarding wht u need so that i can help u..
i am sure there will be a solution for it... revert me soon



Author: Lakhan Pal    05 Sep 2008Member Level: GoldRating:     Points: 2
First Get the Count in A Variable in a Seprate Query Like
Declare @Count int
DECLARE @SQLQuery
select @Count=count(*) from ##temp
SET @SQLQuery='select top'+ Convert(Varchar(10),@Count)+' * from <Table Name>'
EXEC (@SQLQuery)

Hope This will Work.



Author: Neethul Raveendran    05 Sep 2008Member Level: SilverRating:     Points: 1
Thanks yaaar.... i am very glad....
Thanks Once again to all...


Author: Suba Ganesh    06 Sep 2008Member Level: SilverRating:     Points: 2
hi,

u can use like this,

select top 1 count(*) as c from ##temp


hope this will work for u...


Post Reply
You must Sign In to post a response.
Next : Linked Service
Previous : sql query
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

silicone halloween masks

Contact Us    Privacy Policy    Terms Of Use