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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:55:16+00:00 2026-05-16T16:55:16+00:00

I have a stored procedure that contains dynamic sql to return a result set.

  • 0

I have a stored procedure that contains dynamic sql to return a result set. The query runs fine, but I can’t use it via Linq to sql. It appears that the Data Class designer deems that the query only contains one column (Location) rather than the correct number.

I’m guessing its because the dynamic sql means that the columns are not available at design time. The query is this:

set @query = 'select ' + char(13) +
  'case when a.location is not null then upper(left(a.location, 1)) + right(a.location, len(a.location) - 1) else ''All'' end as Location' + char(13) + @strsql +
  'group by ' + char(13) +
  'rollup(location)' + char(13)

where @strsql is a string containing the rest of the query that references the rest of the columns.

Does anyone know of a way to overcome this limitation (aside from not using dynamic sql of course)?

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-05-16T16:55:17+00:00Added an answer on May 16, 2026 at 4:55 pm

    Temporarily replace the sql in your stored procedure with a non-dynamic statement, which has the proper number of columns. Add it to you DBML file & save (regenerating the C# code). Replace your original SQL into the stored proc.

    Unless you delete & re-add the stored proc to the DBML file, VisualStudio should never look at the stored procedure itself again.

    /*
    set @query = 'select ' + char(13) + 'case when a.location is not null then 
        upper(left(a.location, 1)) + right(a.location, len(a.location) - 1) 
        else ''All'' end as Location' + char(13) + @strsql + 'group by ' 
        + char(13) + 'rollup(location)' + char(13)  
     */
     select 'a' as Location, 'b' as othercol, 'c' as col3 
    

    This of course assumes that the number of columns in strsql is fixed, with consisient names. IF not, then you are hitting into a limitation of C#, not Linq.

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

Sidebar

Related Questions

I have a stored procedure that has this line: SET @SQL = 'SELECT path,title,tags
I have a SqlCommand which runs a stored procedure that contains two integer output
How can I write a stored procedure that contains a dynamically built SQL statement
I have a stored procedure that logs some data, how can I call this
I have MS SQL Server stored procedure that returns XML (it uses SELECT with
I have an stored procedure that works on an table that contains xml field,
I have a SQLServer2008 R2 Stored Procedure that contains an algorithm for parsing out
i have a stored procedure that i tested directly and it works, but when
I'm working on a stored procedure. I have a table called #CashFlow that contains
Background I have a table set up in a SQL Server environment that contains

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.