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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:46:19+00:00 2026-06-04T16:46:19+00:00

I’ve had a search round the internet and cannot find anything that directly matches

  • 0

I’ve had a search round the internet and cannot find anything that directly matches what I’m after….

I have a stored procedure that returns a fixed set of columns (let’s say ColumnA, ColumnB and ColumnC) and then additionally returns an indeterminate number / signature of additional columns (maybe ColumnD, ColumnE and ColumnF, or ColumnF, ColumnP, ColumnT and ColumnW).

The dynamic part of the query is determined by an Id param to the proc.

Unfortunately I am not in control of the schema and it has been poorly designed to have a very large number of unrelated columns added to the end (and they keep adding them), rather than having an additional table(s) to store this effectively.

As a result, I am unable to return a determinate set of columns at compile time, so LINQ to SQL cannot determine the return type of the stored procedure.

Do I have any other options, or ways I can get around this? Here’s an example of what I am doing below. Can I re-write this to work with LINQ to SQL? I am writing the application with C# and SQL Server 2008 if that helps.

Thanks.

CREATE PROCEDURE [Foo].[GetBar]
(
    @Id INT,
    @FooVar VARCHAR(50),
    @BarVar DATE
)

AS 
BEGIN

CREATE TABLE #TempTbl 
(     
    [ColumnName] VARCHAR(50)
)

INSERT #TempTbl EXEC [Foo].GetColumnNames @Id
DECLARE @ColumnNameList NVARCHAR(max) 
SET @ColumnNameList = '' 
SELECT @ColumnNameList = COALESCE(@ColumnNameList + '],[', '') + ColumnName FROM #TempTbl
DROP TABLE #TempTbl
SELECT @ColumnNameList = @ColumnNameList + ']'
SELECT @ColumnNameList = SUBSTRING(@ColumnNameList, 3, LEN(@ColumnNameList) )

DECLARE @FixedColumns VARCHAR(200)
DECLARE @SelectQuery NVARCHAR(max) 
DECLARE @WhereQuery VARCHAR (100)
DECLARE @FullQuery NVARCHAR(max) 
DECLARE @ParamaterDef nvarchar (100)
DECLARE @Foo VARCHAR(50)
DECLARE @Bar DATE

SET @FixedColumns = N'[ColumnA], [ColumnB], [ColumnC], '
SET @SelectQuery = N'SELECT ' + @FixedColumns + @ColumnNameList + N' FROM [Foo].[FooBar] '
SET @WhereQuery = N'WHERE [Foo] = @Foo AND [Bar] = @Bar'
SET @FullQuery = @SelectQuery + @WhereQuery   
SET @ParamaterDef = N'@Foo VARCHAR(50), @Bar DATE'

EXECUTE sp_executesql @FullQuery, @ParamaterDef, @Foo = @FooVar, @Bar = @BarVar 

END 
  • 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-04T16:46:21+00:00Added an answer on June 4, 2026 at 4:46 pm

    Can you not just use a SQL Data Adapter that fills a DataSet? You could then use LINQ to DataSet and perform all of your LINQ operations:

    DataTable yourDataTable = ds.Tables["TableName"];
    
    var query =
       from yourDataTable in yourDataTable.AsEnumerable()
       select new
       {
          NewField = yourDataTable.Field<int>("ColumnName"),
          NewField2 = yourDataTable.Field<string>("ColumnName2"),
       };
    

    MSDN (LINQ to DataSet)

    MSDN (Single table queries using LINQ to DataSet

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

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.