Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7941325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:38:10+00:00 2026-06-03T23:38:10+00:00

I have 3 tables like so bug_groups ID NAME DESCRIPTION ————————————– 1 Group1 Some

  • 0

I have 3 tables like so

bug_groups

ID        NAME        DESCRIPTION
--------------------------------------
1         Group1      Some description
2         Group2      Some description
3         Group3      Some description

bugs

ID        NAME        DESCRIPTION        BELONGSTO
--------------------------------------------------
1         Bug1        something          1
2         Bug2        something          1
3         Bug3        something          2

bug_comments

ID        BUGID       COMMENT
-----------------------------
1         1           something
2         1           something
3         2           something
4         2           something
5         3           something

I want to create a stored procedure that will get 2 result sets, one with all the bugs for a given bug group and one with all the comments for all of the bugs in the group. The BELONGSTO field specifies which group that the bug is a part of. So If I wanted to run this query, passing in 1 for the bug group ID I would expect this result

RESULT SET 1

ID        NAME         DESCRIPTION         BELONGSTO
----------------------------------------------------
1         Bug1         something           1
2         Bug2         something           1

RESULT SET 2

ID        BUGID        COMMENT
------------------------------
1         1           something
2         1           something
3         2           something
4         2           something

I think I may need to use a temporary table but I’m unsure how to do this. This is what I have so far (which doesn’t work)

ALTER PROCEDURE bugs_getAllBugGroupData
    @groupid int
AS
BEGIN
    DECLARE @bugids TABLE (id int)
    INSERT @bugids
    SELECT id FROM bugs
    WHERE belongsto = @groupid

    SELECT * FROM bugs WHERE belongsto = @groupid
    SELECT * FROM bugs_comments WHERE bugid IN (@bugids)
END
GO

The error message I get is “Must declare the scalar variable @bugids” at the last select statement.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:38:12+00:00Added an answer on June 3, 2026 at 11:38 pm

    This line

    SELECT * FROM bugs_comments WHERE bugid IN (@bugids)
    

    has to be

    SELECT * FROM bugs_comments WHERE bugid IN (SELECT id FROM @bugids).
    

    However you don’t need an auxiliary table. You can query directly using a join:

    1.

    SELECT * FROM bugs WHERE belongsto = @groupid
    

    2.

    SELECT * FROM bugs_comments AS bc
        INNER JOIN bugs AS b ON (bc.bugid = b.id)
        WHERE b.belongsto = @groupid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i have tables like this: Persons: person_id, name then i have many langauge
I have two tables like this: Table Name: users emx | userid --------------- 1
I have three tables like this: Person table: person_id | name | dob --------------------------------
Say that I have two tables like those: Employers (id, name, .... , deptId).
I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int
I have three tables like that: Articles IdArticle Title Content Tags IdTag TagName ContentTag
I have 2 tables like this: Stock Table product_id bigint(20) qty float Sales Table
I have two tables like the ones below. I need to find what exchangeRate
I have two tables like of this structure: content (content_id, content_type, user_id, time, comment_count)
i have four tables like below in sql server 2008 : TABLE 1 ->

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.