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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:04:56+00:00 2026-06-18T06:04:56+00:00

My question: Is it possible in SQL Server 2008 to define temporal table in

  • 0

My question: Is it possible in SQL Server 2008 to define temporal table in stored procedure and pass it as variable to user defined function?

I need to do the following:

  1. I have procedure dbo.GetMsgCntData.

  2. This procedure is making some calculations and as a result of this procedure I have data into temporary table that is defined in this procedure (GetMsgCntData):

    -- table defined in dbo.GetMsgCntData
    DECLARE @tmpTable TABLE (
        ID BIGINT,
        FirstName VARCHAR(50),
        LastName VARCHAR(50),
        UserType varchar(50),
        SenderID bigint,
        IsArchive bit
    )
    
  3. So, @tmpTable contains some data.
    I need to run user defined function GetCnt(@status, @MsgTempTable), but I need getCnt function to access @tmpTable data. Basically I need something like this:

    -- to be written at the end of dbo.GetMsgCntData
    SELECT cnt(*) total,
        dbo.GetCnt('open', @tmpTable) as opened,
        dbo.GetCnt('closed', @tmpTable) as closed
    FROM @tmpTable
    -- where @tmpTable is temporal table
    
  4. I tried to define @table in GetCnt as user defined type.

    CREATE TYPE dbo.tmp_Messages AS TABLE (
        ID BIGINT,
        FirstName VARCHAR(50),
        LastName VARCHAR(50),
        UserType varchar(50),
        SenderID bigint,
        IsArchive bit
    )
    
    CREATE FUNCTION FUNCTION [dbo].[GetCnt] (
        @Status nvarchar(10),
        @MsgTempTable dbo.tmp_Messages READONLY
    )
    ....
    

but this gives me error message:

Operand type clash: table is incompatible with tmp_Messages

I think that my idea is simply incorrect.

  • 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-18T06:04:57+00:00Added an answer on June 18, 2026 at 6:04 am

    Temporary table is not compatible with user-defined type.
    You should declare your temporary table as user-defined type:

    CREATE TYPE dbo.tmp_Messages AS TABLE 
    (
     ID BIGINT,
     FirstName VARCHAR(50),
     LastName VARCHAR(50),
     UserType varchar(50),
     SenderID bigint,
     IsArchive bit
     )
     GO
     --function declaration 
    
            CREATE FUNCTION [dbo].[GetCnt] (
                @Status nvarchar(10),
                @MsgTempTable dbo.tmp_Messages READONLY
            )...
            -- table defined in dbo.GetMsgCntData
            DECLARE @tmpTable dbo.tmp_Messages;
            INSERT INTO @tmpTable(---some actions
    
    SELECT cnt(*) total,
        dbo.GetCnt('open', @tmpTable) as opened,
        dbo.GetCnt('closed', @tmpTable) as closed
    FROM @tmpTable
    

    Please read a good article about table-valued parameters: http://beyondrelational.com

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

Sidebar

Related Questions

In a stored procedure (using SQL Server 2008 R2 SP2) is it possible to
Possible Duplicate: Language Translation for Tables I'm creating a table in sql server 2008.
Possible Duplicates: SQL Multiple Parameter Values SQL Server (2008) Pass ArrayList or String to
As pointed out in this question when using filestream with sql server 2008 the
Hello guys here with another question, regarding sql server 2008 r2 this time about
I am working with a big table (~100.000.000 rows) in SQL Server 2008. Frequently,
Possible Duplicate: SQL Server Clustered Index - Order of Index Question I understand that
Background Microsoft SQL Server 2008 R2 Table with ~100k records per day Most queries
I am using SSIS (SQL Server 2008) to lookup values from a table. I
I am using SQL Server 2008. A while back, I asked the question should

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.