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 8332391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:42:33+00:00 2026-06-09T02:42:33+00:00

I am trying to look through two tables TableA and TableB get print out

  • 0

I am trying to look through two tables TableA and TableB get print out the TableA.ID of any that show more than 1 count. TableA looks like this:

ID  |  Code
------------
1   |  A
2   |  B
3   |  C

Table B Looks like

ID  |  AID |   EffectiveDate  |  ExpirationDate
------------------------------------------------
1   |  1   |  2012-01-01      |  2012-12-31
2   |  1   |  2012-01-01      |  2012-12-31
3   |  2   |  2012-01-01      |  2012-12-31
4   |  3   |  2012-01-01      |  2012-12-31

The Query I am using looks like this:

DECLARE @MoreThanOne varchar(250)
SET @MoreThanOne = ''
IF((SELECT COUNT(*) FROM TableA
WHERE EXISTS(
SELECT TableB.ID
        ,TableB.EffectiveDate
        ,TableB.ExpirationDate
     FROM TableB
     WHERE TableB.AID = TableA.ID
        and GETDATE() Between TableB.EffectiveDate and TableB.ExpirationDate
) 
GROUP BY TableA.Code) > 1)
BEGIN
--SET @MoreThanOne = @MoreThanOne + TableA.Code + CHAR(10)

END


PRINT @MoreThanOne

I know that my nested Query works when reworked it will print the counts for all in the unique codes in TableA.
I know that I can not use what I commented out because i don’t have access to TableA.Code.
My question is there another way to do this or how can I get access to TableA.Code for the Message MoreThanOne.

Thanks For the help!

  • 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-09T02:42:35+00:00Added an answer on June 9, 2026 at 2:42 am

    This query will get you the codes for all AIDs that are duplicated in table B:

    SELECT Code
    FROM TableA
    WHERE AID IN
    (
        SELECT AID
        FROM TableB
        GROUP BY AID
        HAVING COUNT(*) > 1
    )
    

    You may also wish to add the WHERE condition that have in your stored procedure to the inner select.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to grep through a bunch of files in nested subdirectories to look
I'm trying to have my application read through a text file and look for
I am trying to look at an execution plan for a sproc that has
I'm trying to look for a unique 32-bit integer that I can access in
I've been been trying to look for a piece of javascript code that compares
I'm trying to look through an array of records (staff members), in this loop,
I'm trying to figure out my first more complex SQL application and am having
Really trying to get my head around this but cannot see the light through
I'm trying to make a loop that will recurse through an array of bytes
I have two MySQL tables. What I am trying to do is to export

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.