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 2008 Forums
 Transact-SQL (2008)
 Stored Procedure Help

Author  Topic 

hari4u6
Starting Member

12 Posts

Posted - 2009-12-17 : 01:13:38
Hello,
I'm creating a forum application like SQL Team..
I've have three tables ..
ForumTopic , ForumPost, ForumReply

The architechure is something like this..

ForumTopic ....ForumTopicId,TopicName,Description,CreatedDate,CreatedBy
ForumPost-ForumPostId,ForumTopicId,Subject,Description,PostDate,CreatedBy

and

ForumReply--ForumReplyId,ForumPostId,ReplyBy,ReplyDate,Description..


These are the three tables am using..

What I want is ..

The stored procedure with

no. of threads , last post , postedby,datetime, in a Topic

Anybody please help mee..

cat_jesus
Aged Yak Warrior

547 Posts

Posted - 2009-12-17 : 08:53:59
Try this


Declare @threads as int

select @threads = count(*) from ForumTopic

With LatestPost (TopicID,PostID) as
(
Select ForumTopicID,Max(forumpostid) from ForumPost group by ForumTopicID
)
Select @threads as NumberofThreads, B.TopicName,C.PostedBy as lastPoster,C.PostDate
From
LatestPost A
Join ForumTopic B on A.ForumTopicID = B.ForumTopicID
Join ForumReply C on C.ForumPostID = A.PostID

An infinite universe is the ultimate cartesian product.
Go to Top of Page

hari4u6
Starting Member

12 Posts

Posted - 2009-12-18 : 06:30:36
thank you for the reply,
It didnt help Sir.
I'm getting error in no. of threads.

Hari.
Go to Top of Page
   

- Advertisement -