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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:52:12+00:00 2026-05-11T10:52:12+00:00

I have a table-value function that takes an ID number of a person and

  • 0

I have a table-value function that takes an ID number of a person and returns a few rows and columns. In another query, I am creating a SELECT that retrieves a lot of information about many people. How can I pass an id number from my main query to my function to sum a column and join it to my main query? I wish I didn’t have a table value function since that would work easily, however, this function is used elsewhere and I’d like to reuse it. Perhaps this isn’t even possible with a table-value function and I need to create a scalar one.

My main Query looks like this:

select id_num, name, balance  from listOfPeople 

And the table-value function looks like this:

calculatePersonalDiscount(id_number) 

I would like to do something like:

select id_num, name, balance  from listOfPeople left join  (   SELECT id_num, SUM(discount)   FROM calculatePersonalDiscount(listOfPeople.id_num) ) x ON x.id_num = listOfPeople.id_num 

But you can’t pass listOfPeople.id_num into the function since it’s not really the same scope.

  • 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. 2026-05-11T10:52:13+00:00Added an answer on May 11, 2026 at 10:52 am

    In SQL Server 2005 you can use the CROSS APPLY syntax:

    select id_num, name, balance, SUM(x.discount) from listOfPeople     cross apply dbo.calculatePersonalDiscount(listOfPeople.id_num) x 

    Likewise there’s an OUTER APPLY syntax for the equivalent of a LEFT OUTER join.

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

Sidebar

Related Questions

We have a table value function that returns a list of people you may
I have a function that takes two delimited strings and returns the number of
I'm making a function that takes a table name and a key value array
In MySQL I have a function that takes a number argument and spits out
I have the following query in VBA: DoCmd.RunSQL INSERT INTO table (value) VALUES ('example')
I have a table that looks like this: id value AGA 0.211 AGA 0.433
I have a function that takes a string object name and I need the
Ok we have a simple udf that takes a XML integer list and returns
I want to have a SelectAll function which takes in a few arguments (class,
Is it at all possible to have a table valued function in MSSQL that

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.