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

  • Home
  • SEARCH
  • 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 3938278
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:09:59+00:00 2026-05-20T00:09:59+00:00

If I have a function that returns a temporal table, how do I set

  • 0

If I have a function that returns a temporal table, how do I set a var in SQL Server that saves it?

If the result of the function is something like:

temp table
    item1 item2...itemn
        1     2...    n

Is this valid?

SELECT @table = * FROM dbo.SOME_FUNCTION()

??

If this is possible, could you make an example, of how to use the @table var for knowing values?

If not possible, how can I access the temp table that the function returns??

  • 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-20T00:09:59+00:00Added an answer on May 20, 2026 at 12:09 am

    If the function is returning a table, you should be able to have:

    INSERT INTO @table (Col1, Col2) SELECT * FROM dbo.SOME_FUNCTION()
    

    You’d need to specify the columns you’re going to be using for either the INSERT or SELECT portion of the statement.

    UPDATE:

    Here’s something I’ve come up with so you can find out the columns. The first part is enabling your server so it can return and use stored procs as you would a normal table (check with your DBA or whoever runs the server that they’re ok with these options being turned on). You select your resultset into a temp table, then run the sp_columns stored proc in tempdb and insert that into another temp table (which you then drop). That way, you at least know what columns you’ve got, and can possibly use that to make it easier to work with dynamic column names perhaps.

    sp_configure 'Show Advanced Options', 1
    GO
    
    RECONFIGURE
    GO
    
    sp_configure 'Ad Hoc Distributed Queries', 1
    GO
    
    RECONFIGURE
    GO
    
    SELECT * INTO #ItemsTable FROM dbo.SOME_FUNCTION()
    
    SELECT * INTO #Columns FROM OPENROWSET('SQLNCLI', 'Server=(local);Trusted_Connection=yes;', 'exec tempdb..sp_columns ''#ItemsTable''')
    
    SELECT COLUMN_NAME FROM #Columns
    
    DROP TABLE #Columns
    

    ANOTHER UPDATE:

    If you want to get the list of columns for a table in the database, you could use this query:

    SELECT [name] FROM sys.columns WHERE object_id = (SELECT object_id FROM sys.tables WHERE [name] = 'TableName')
    

    However! If you’re going to be running this query and creating tables of varying sizes many times a day, I would suggest that you stick with temp tables. That way you won’t be writing unnecessarily to the database (except tempdb). If for some reason you NEED permanent tables created each time, then, I guess that’s fine too!

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

Sidebar

Related Questions

I have a function that returns a float from 0 to 255. I would
If I have a function that returns an object, but this return value is
Let's say you have a function that returns a date: Date myFunc(paramA, paramB){ //conditionally
Say I have a Python function that returns multiple values in a tuple: def
I'm mocking about with plt-scheme's ffi and I have a C-function that returns a
I have a web service which has a generic function that returns a dataset
I have a function inside a class that returns a reference to a member
I have a function called FindSpecificRowValue that takes in a datatable and returns the
I want to have a function that will return the reverse of a list
in delphi7 i have a function that i need to return a array as

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.