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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:52:41+00:00 2026-06-14T04:52:41+00:00

I am attempting to do something using MSSQL that I believe is possible (easily)

  • 0

I am attempting to do something using MSSQL that I believe is possible (easily) but I do not know how to vocalize the correct search string. I have the situation below.

Table A
UID  | Value....
1    | a
2    | b
3    | c


Table B
PartTypes_uid_fk   | Value....
1           | a
1           | b
1           | c
1           | d
1           | e
3           | 67
3           | 1354

I am attempting to get the following result, query Table A for all results {TableA.*} and on the same row result show the number of table b references {count TableB.tableA_fk}
What I have so far is the following.

SELECT DISTINCT t1.uid, CONVERT(varchar(MAX), t1.Name) AS Name, CONVERT(varchar(MAX), t1.Description) AS Description,
Count(t2.Items_uid_fk) OVER (Partition By t2.PartTypes_uid_fk) as Count
FROM [Table1] as t1 left outer join Table2 as t2 on t2.PartTypes_uid_fk=t1.uid;

This works for all of Table A records with an associated record in Table B but if there are 0 entries in Table B it won’t work. The conversion of the varchars was required due to the fact they are ntext format and it was distinct.

Thank you for all your help in advance.
Stephen

  • 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-14T04:52:42+00:00Added an answer on June 14, 2026 at 4:52 am

    Instead of running into problems with the GROUP BY on N/TEXT columns, and to run faster, you would want to pre-aggregate the B table and LEFT JOIN that against A.

    select t1.*, ISNULL(t2.c, 0) AS CountOfB
    from table1 t1
    left join
    (
        select parttypes_uid_fk, count(*) c
        from table2
        group by parttypes_uid_fk
    ) t2 on t2.PartTypes_uid_fk=t1.uid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed something when I was attempting this today: <g:remoteField action=getReportsToResults update=reportsToResultsDiv paramName=search name=reportsToResults
I'm attempting to do something using Silex (which uses the Symfony routing component -
Attempting something like public string MyText { get {return lbl.Text;} set {lbl.Text = value;}}
I'm attempting something which I feel should be fairly obvious to me but it's
I am attempting to find a binary file in a Linux system using something
I'm attempting to construct a search query in MySQL using multiple arguments, and I
Hi I'm using MODx on a site, but something has gone wrong with the
I am attempting to pipe something to a subprocess using the following line: p.communicate(insert
I am attempting to do something simple (I thought) - securing my application using
I'm attempting to do something which should be relatively simple. I'm using a ListView

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.