Stored Procedure Problem

  • Hi all

    Please look the table query.

    SELECT [Post_ID]

    ,[Post_Category_ID]

    ,[Post_Title]

    ,[Post_Description]

    ,[Is_Email_Notification]

    ,[Attachment_URL]

    ,[User_ID]

    ,[Is_Delete]

    ,[Is_Move]

    ,[Is_Close]

    ,[Total_Views]

    FROM [Cfamla].[dbo].[Post_Detail]

    SELECT [Post_Reply_ID]

    ,[Last_Modification_Date]

    ,[Post_ID]

    ,[Reply_Title]

    ,[Reply_Description]

    ,[Is_Email_Notification]

    ,[Attachment_URL]

    ,[User_ID]

    ,[Is_Delete]

    FROM [Cfamla].[dbo].[Post_Reply]

    Above are two table I want to data in the next format!

    [Post_ID] ,[Post_Title]

    [Post_Reply_ID],[Reply_Title]

    Mean In the first Row of the select statement it will show me the Post_Id that is always

    After the next row... It will so all the reply of that post.

    Hope I explain the question correctly.

    Thanks

    Warm Regards,
    Shakti Singh Dulawat
    Before printing, think about the environment
    Do the impossible, and go home early.

  • Perhaps I am not understanding but you could just join the tables

    SELECT [Post_ID] ,[Post_Title]

    [Post_Reply_ID],[Reply_Title], ....

    FROM [Cfamla].[dbo].[Post_Detail]

    INNER JOIN [Cfamla].[dbo].[Post_Reply]

    ON [Cfamla].[dbo].[Post_Reply].[Post_ID] = [Cfamla].[dbo].[Post_Detail].[Post_ID]

  • can u explain your exact requirement. 😎

    I think you may be expected like the following:

    SELECT[Post_ID]

    ,[Post_Title]

    ,[Post_Reply_ID]

    ,[Reply_Title]

    FROM[Cfamla].[dbo].[Post_Detail] pd

    INNER JOIN [Cfamla].[dbo].[Post_Reply] pr ON (pd.[Post_ID] = pr.[Post_ID])

  • Thanks for the reply, nut I think you not get the question.

    Here is the example

    Post_Detail Table

    Post_ID Post_Title

    1 Basic Problem

    [Post_Reply] Table

    [Post_Reply_ID] [Post_ID],[Reply_Title]

    11 1 This is the solution of the problem

    12 1 I got it. Thanks

    13 1 I have no Idea

    If we use inner join then it will show only three record!

    But I want record in the following format! for post Id=1

    [ID] [Title]

    1 Basic Problem

    11 This is the solution of the problem

    12 I got it. Thanks

    13 I have no Idea

    Hope you got the exact problem

    Thanks

    Warm Regards,
    Shakti Singh Dulawat
    Before printing, think about the environment
    Do the impossible, and go home early.

  • Hi Shakti,

    I think you have to use a cursor

    Set nocount on

    Declare @Post_ID int, @Post_Title nvarchar(100)

    Create table #temp(Post_ID int, Post_Title nvarchar(100))

    Declare c cursor for SELECT distinct [Post_ID],[Post_Title] FROM [Cfamla].[dbo].[Post_Detail]

    Open c

    Fetch next from c into @Post_ID,@Post_Title

    While @@FETCH_STATUS = 0

    Begin

    insert into #temp values(@Post_ID,@Post_Title)

    insert into #temp

    Select [Post_Reply_ID] ,[Reply_Title] From [Cfamla].[dbo].[Post_Reply] where [Post_Reply_ID]=@Post_ID

    Fetch next from c into @Post_ID,@Post_Title

    End

    Close c

    Deallocate c

    Select * from #temp

    Drop table #temp

    Set nocount off

    Regards,

    Ahmed

  • Thanks fro reply

    Why we are not deleting temp table??

    Warm Regards,
    Shakti Singh Dulawat
    Before printing, think about the environment
    Do the impossible, and go home early.

  • Hi,

    It's just a temporary table, if you want to keep it, it ok.

    You can put this code in stored proc.

    Regards,

    Ahmed

  • I do not want to use that table again.

    I want to delete it!

    Thanks

    Warm Regards,
    Shakti Singh Dulawat
    Before printing, think about the environment
    Do the impossible, and go home early.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply