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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:26:45+00:00 2026-05-26T07:26:45+00:00

We have an invoice table. The invoice has an owner and customer, both id

  • 0

We have an invoice table. The invoice has an owner and customer, both id fields which link to a resource table. The resource table contains businesses which might have ‘child’ businesses under them. I have a query that checks if the current business is in the owner_id or customer_id like so:

SELECT * FROM invoices i WHERE @BusinessId IN ( i.owner_id, i.customer_id )

The problem I have at the moment is that I need to verify if the business or its child businesses are in the owner_id or customer_id. We have a function that returns a table containing the business ids from the resource table if I query it like so:

select business_id from  dbo.vfn_child_business(@BusinessId , 'Y')

The ‘Y’ parameter basically returns the main parent along with the child business id’s in the results (essentially looking for child businesses of a business and including itself).

I can’t figure out how to query to say

SELECT * from Invoices
where ANY OF MY RESULTS FROM CHILD BUSINESS FUNCTION IN ( i.owner_id, i.customer_id ).

I’ve tried:

... WHERE (select business_id 
           from  dbo.vfn_child_business(@BusinessId , 'Y'))
    IN ( i.owner_id, i.customer_id )

But I get this error:

Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= , >, >= or when the subquery is used as
an expression.

Please can anyone 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-05-26T07:26:45+00:00Added an answer on May 26, 2026 at 7:26 am

    I haven’t tested this, but the EXISTS predicate might help here:

    WITH children AS
        (SELECT business_id
         FROM dbo.vfn_child_business(@BusinessId , 'Y'))
    SELECT
        i.*
    FROM
        Invoices AS i
    WHERE
        EXISTS
            (SELECT 1
             FROM children
             WHERE children.business_id IN ( i.owner_id, i.customer_id ))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume we have an Invoice entity which has many InvoiceDetails . Each invoice detail
I have shipment has one invoice; invoice belongs to shipment. The shipments table is
Consider we have a database that has a table, which is a record of
I have a query to insert a row into a table, which has a
I have a table which has a list of invoices and their details: class
I have an Invoice model which belongs to Customer (and of course Customer has_many
If I have an Invoice Line Items table and a Products table, and I
I have a table called invoices with 3 fields (for the purposes of this
I have tree tables, Customer, Invoice and InvoiceRow with the standard relations. These I
I have two tables invoices and pending_payments both of which have the following rows

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.