C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

How to include order by in subqueries with joins


Posted Date: 04 Nov 2009      Posted By: anbu      Member Level: Gold     Points: 1   Responses: 3



alter PROCEDURE TSShwRelPrts
@ParticipantId bigint
AS
BEGIN
select distinct (a.username),a.pname,a.RecommanderId,a.ParticipantId,a.relatedpid,b.recom1,i.allowselect,r.RelationshipId,r.Relname from
(select p.username,p.pname,g.ParticipantId,g.relatedpid,g.RecommanderId,g.Relationshipid
from TSGroupParticipants as g inner join tsparticipants as p
on g.relatedpid=p.ParticipantId and g.ParticipantId=@ParticipantId) as a
inner join

(select r.username,isnull(r.pname,'admin') as recom1,gr.ParticipantId,gr.relatedpid,gr.RecommanderId,gr.Relationshipid from TSGroupParticipants as gr left outer join tsparticipants as r
on gr.RecommanderId=r.ParticipantId where gr.ParticipantId=@ParticipantId) as b

on a.RecommanderId=b.RecommanderId

inner join TSMailinvitation as i on a.ParticipantId=i.ParticipantId

inner join TSRelationships as r on r.Relationshipid=a.Relationshipid

END


.....................
in the above i want to include

order by rowid desc





Responses

Author: ABitSmart    04 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Which table does rowid belong to?


Author: anbu    04 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

rowid belongs to TSGroupParticipants


Author: ABitSmart    05 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Try this,

alter PROCEDURE TSShwRelPrts
@ParticipantId bigint
AS
BEGIN
select distinct (a.username),a.pname,a.RecommanderId,a.ParticipantId,a.relatedpid,b.recom1,i.allowselect,r.RelationshipId,r.Relname from
(select p.username,p.pname,g.ParticipantId,g.relatedpid,g.RecommanderId,g.Relationshipid
from TSGroupParticipants as g inner join tsparticipants as p
on g.relatedpid=p.ParticipantId and g.ParticipantId=@ParticipantId) as a
inner join

(select r.username,isnull(r.pname,'admin') as recom1,gr.ParticipantId,gr.relatedpid,gr.RecommanderId,gr.Relationshipid from TSGroupParticipants as gr left outer join tsparticipants as r
on gr.RecommanderId=r.ParticipantId where gr.ParticipantId=@ParticipantId) as b

on a.RecommanderId=b.RecommanderId

inner join TSMailinvitation as i on a.ParticipantId=i.ParticipantId

inner join TSRelationships as r on r.Relationshipid=a.Relationshipid
Order by g.rowid
END



Post Reply
You must Sign In to post a response.
Next : How to configure an reindexing job in sql server 2000
Previous : What is use of Cache transform in ssis
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use