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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:18:13+00:00 2026-06-17T03:18:13+00:00

Just got another query that I’m pulling what remaining hair I have left out

  • 0

Just got another query that I’m pulling what remaining hair I have left out over here.

I have 4 tables (Product, Customers, Orders and Order Details) I need to create a valued table function that passes Country Name to the function. I also need the function to join my Customers table with my Orders table. I ideally want to filter Countries by Order Date. So I’d like to able to Select from the function that tells me orders from a certain country within a certain date range.

So far I’ve tried the following with not much success:

USE sample;
GO
CREATE FUNCTION Orders_By_Country (@Country VARCHAR(50))
    RETURNS TABLE
    AS RETURN (SELECT Customers.Country, Customers.CompanyName
                    FROM Customers
                   WHERE Customers.Country = Orders.ShipCountry
                 AND Country = @Country);

I don’t have a Country column in my Orders table so maybe that is why it’s not working. Not sure how to join these two. Orders and Customers share CustomerID as a relation but trying that gave me an error as well.

Any ideas? I have to go to bed now, but I’ll check back first thing in the morning.

Thanks

  • 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-17T03:18:14+00:00Added an answer on June 17, 2026 at 3:18 am

    If you want to use the Orders table to make decisions or if you want to return one or multiple columns from that table in your TVF, you need to join to it!

    CREATE FUNCTION Orders_By_Country (@Country VARCHAR(50))
        RETURNS TABLE
        AS RETURN 
           (SELECT Customers.Country, Customers.CompanyName
            FROM Customers
            INNER JOIN Orders ON Orders.CustomerId = Customers.CustomerId
            WHERE 
                Customers.Country = Orders.ShipCountry
                AND Country = @Country);
    

    or then you might not need it at all – seeing that you have a Country column on the Customers table:

    CREATE FUNCTION Orders_By_Country (@Country VARCHAR(50))
        RETURNS TABLE
        AS RETURN 
           (SELECT Customers.Country, Customers.CompanyName
            FROM Customers
            WHERE 
                Customers.Country = @Country);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a text box that just disappeared. When I add another templateField anywhere
I've got a query that I've just found in the database that is failing
I just got another assignment for web design. And I was curios how to
i just got a call from Hosting company, they claimed that my application creates
I just got an email from twitter saying my keys have now been enabled
I just got out of a small project and I've tried to follow a
I have a Rails app whose major part is to query another web-service using
I've got a query here which does what it is supposed to but I'm
Using ASP.NET and Windows Stack. Purpose: Ive got a website that takes in over
I've got an sql query that contains a number of statements. It: sets a

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.