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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:03:56+00:00 2026-06-02T00:03:56+00:00

ok..i have 2 tables…they are exactly the same except for the column name in

  • 0

ok..i have 2 tables…they are exactly the same except for the column name in one of them because they deal with 2different “companies”, though..the data i want is in columns that have the same name.pretty much what i want to do…is if tableA.Col2 is > 0 or tableB.Col2 is > 0 then 1..else 0..they also need to be distinct…i can get them as separate tables…but i cant get them together..I need them in 1 column because of how it is sent to the C3 code page and how it reads it…the structure has already been previously set..and there are about 5 other statments that are being executed in this one stored procedure like this (also i wasnt the one who set this up). So if f this is possible..let me know please.. i will also paste the exact code i have if you feel like seeing the real life code..i just tried to simplify it to make it easier to understand.

DECLARE @id INT;
DECLARE @invest nvarchar(50);
SET @id = '7633';
SET @invest = '';


SELECT 'a' + CONVERT(nvarchar, orderfindings.risk_rating) AS cat, COUNT(DISTINCT orderfindings.prnt_id) AS stat
        FROM orderheader, orderaudits, orderfindings
        WHERE orderheader.id = orderaudits.orderheader_id AND orderaudits.ID = orderfindings.prnt_id
        AND orderheader.id = @id AND orderfindings.risk_rating > 0 AND orderaudits.Investor_Name LIKE '%' + @invest + '%'
        GROUP BY orderfindings.risk_rating
UNION ALL
SELECT 'a' + CONVERT(nvarchar, orderagencies.risk_rating) AS cat, COUNT(DISTINCT orderagencies.prnt_id) AS stat
        FROM orderheader, orderaudits, orderagencies
        WHERE orderheader.id = orderaudits.orderheader_id AND orderaudits.ID = orderagencies.prnt_id
        AND orderheader.id = @id AND orderagencies.risk_rating > 0 AND orderaudits.Investor_Name LIKE '%' + @invest + '%'
        GROUP BY orderagencies.risk_rating

-------------------
/*
Results from 1st statement
cat | stat
-----------
a1  |  4
-----------
a2  |  5
-----------

Results from 2nd statement
cat | stat
-----------
a1  |  3
-----------
a2  |  2
-----------

I pretty much want

Results from new awesome statement
cat | stat
-----------
a1  |  5
-----------
a2  |  5
-----------
I think those are the numbers that would be accurate
Simple version---    if tableA.Col2 is > 0 or tableB.Col2 is > 0 then 1 else 0
  |Table A                |               Table B                 |    result of query
  |   col_1     col2      |      col_1               col2         |
  --------------------------------------------------------------------
1 |   1           5       |       1                   3           |          1
2 |   1           45      |       1                   0           |          1
3 |   1           0       |       1                   0           |          0  
4 |   1           0       |       1                   3           |          1

so a1 would be 3...4 records in the tables..but only 3 of them matter because row 3 has 0 
whatevers in col 2 for both tables..there might be 100 records that have 1 for col 1..there 
might only be 1

i hope this makes more sense…it is kinda a weird task

  • 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-02T00:03:57+00:00Added an answer on June 2, 2026 at 12:03 am

    Try this:

    DECLARE @id INT;
    DECLARE @invest nvarchar(50);
    SET @id = '7633';
    SET @invest = '';
    
    
    SELECT  Findings.cat [cat], 
            CASE WHEN Findings.stat > 0 OR Agencies.stat > 0 THEN 1 ELSE 0 END [stat]
    
    FROM (SELECT 'a' + CONVERT(nvarchar, orderfindings.risk_rating) AS cat, COUNT(DISTINCT orderfindings.prnt_id) AS stat
            FROM orderheader, orderaudits, orderfindings
            WHERE orderheader.id = orderaudits.orderheader_id AND orderaudits.ID = orderfindings.prnt_id
            AND orderheader.id = @id AND orderfindings.risk_rating > 0 AND orderaudits.Investor_Name LIKE '%' + @invest + '%'
            GROUP BY orderfindings.risk_rating) Findings
    INNER JOIN (SELECT 'a' + CONVERT(nvarchar, orderagencies.risk_rating) AS cat, COUNT(DISTINCT orderagencies.prnt_id) AS stat
            FROM orderheader, orderaudits, orderagencies
            WHERE orderheader.id = orderaudits.orderheader_id AND orderaudits.ID = orderagencies.prnt_id
            AND orderheader.id = @id AND orderagencies.risk_rating > 0 AND orderaudits.Investor_Name LIKE '%' + @invest + '%'
            GROUP BY orderagencies.risk_rating) Agencies
    
    ON Findings.cat = Agencies.cat
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tables with latin1_swedish_ci column. I've done tests and inserted into them some
I have tables with listings, categories and one that maps them to each other.
I have several databases that have tables with the same name. I mean, I
I have tables named Contact and Address and both of them have ModifiedDate column.
I have tables Product ( ID, CategoryID, ... ) Category ( ID, Name, ..
hi i have tables like this: Persons: person_id, name then i have many langauge
I have tables A,B A holds a NETWORK_ID, column and a SUBSCRIPTION_ID B holds
I have tables: users {id, name} projects {id, name} roles {id, name} projects_users {id,
I have tables like tbl_biodata: id : int value=>1 name : varchar(50) value =>
i have tables driver, cars and trailers they are all in relationship. and main

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.