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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:37:34+00:00 2026-05-30T12:37:34+00:00

In working on passing a table type around, I’m running into a strange issue

  • 0

In working on passing a table type around, I’m running into a strange issue that I’m hoping is something simple that I can get help with. My table type looks like this:

CREATE TYPE [dbo].[StoreTableType] AS TABLE(
[StoreGUID] [uniqueidentifier] NULL
 )

I have a stored proc that I pass this to that contains a group by query to show some totals by market. But here’s where it gets interesting… if I run the query in the SQLEM, it works, but if it calls the stored proc, it returns nothing. Here’s what I run to get a result:

declare @p3 dbo.StoreTableType
insert into @p3 values('121A267F-F994-4B01-8318-9E307AF9415B')
insert into @p3 values('B2BB61CE-5ED8-4C91-ADB7-DA903B6D506A')
insert into @p3 values('5818BA65-A1B5-432E-BF76-68EF51635A39')

select * from survey where storeguid in (select StoreGUID from @p3)

select m.[Name] as Market, count(svy.SurveyGUID) as Total
from survey svy inner join store s on svy.StoreGUID = s.StoreGUID
inner join Market m on s.MarketID = m.MarketID
where s.StoreGUID in (select StoreGUID from @p3)
group by m.[Name]

This will give me:

enter image description here

Now, if I run the statement from my code, SQL Profiler shows me that it generates the following:

 declare @p3 dbo.StoreTableType
 insert into @p3 values('121A267F-F994-4B01-8318-9E307AF9415B')
 insert into @p3 values('B2BB61CE-5ED8-4C91-ADB7-DA903B6D506A')
 insert into @p3 values('5818BA65-A1B5-432E-BF76-68EF51635A39')

 exec sp_executesql N'snus_MarketTotals',N'@StoreGUIDs [StoreTableType]      READONLY',@StoreGUIDs=@p3

However, when I run this, I get:

enter image description here

The group by query in the proc is the same as the one I tested in SQLEM. Anyone have any ideas? I’m about ready to bail out on the table type… but wanted to see if I’m just overlooking something.

UPDATE: Here’s the code that makes the call.

        // EF <hates> table type parameters... so... gonna put some SQL in here.
        SqlConnection conn = new SqlConnection(connectionString);
        DataSet ds = new DataSet(datasetName);

        using (SqlCommand cmd = new SqlCommand(spName, conn))
        {
            SqlParameter param = new SqlParameter("@StoreGUIDs", SqlDbType.Structured);
            param.Value = storeGuids;
            param.TypeName = "StoreTableType";
            cmd.Parameters.Add(param);

            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            adapter.Fill(ds);

        }

        // get some xml
        return(ds.GetXml());

And for the proc:

CREATE PROCEDURE [dbo].[MarketTotals]
(
    @StoreGUIDs StoreTableType readonly
)
AS
begin

-- market totals
select m.[Name] as Market, count(svy.SurveyGUID) as Total
from survey svy inner join store s on svy.StoreGUID = s.StoreGUID
    inner join Market m on s.MarketID = m.MarketID
where s.StoreGUID in (select StoreGUID from @StoreGUIDs)
group by m.[Name]
  • 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-30T12:37:36+00:00Added an answer on May 30, 2026 at 12:37 pm

    I suspect that you are getting sp_executesql because you’ve declared your CommandType as something other than StoredProcedure. What you are seeing in Profiler does not seem right.

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

Sidebar

Related Questions

I'm working with legacy Java code which returns java.lang.object. I'm passing it into a
I'm looking for good/working/simple to use PHP code for parsing raw email into parts.
I am working on my first MVC application and am running into a bit
I'm working on writing a simple database that uses Google Fusion Tables to store
I'm working on desktop application (Extract Transform Load type of app) that requires uploading
I'm passing some parameters to a CR report programatically and it was working fine,
I am working on a project, and had all of my tests passing on
So my code isn't working... test.c:27: warning: passing argument 1 of ‘search’ from incompatible
I have recently started working on my master thesis in C that I haven't
hi :) I have a similarly issue like in Working with the same NSManagedObjectContext

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.