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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:52:31+00:00 2026-05-26T04:52:31+00:00

I have a stored procedure which gets pivot fields as a parameter (say @P

  • 0

I have a stored procedure which gets pivot fields as a parameter (say @P) which splits by ,
and am pivoting for a table based on fields which the the @P includes them , i wanna map the stored procedure in EF . But don’t know how to create a complex type with dynamic number of fields based on result of stored procedure.
I have something like the fallowing:

CREATE PROC pr 
@p AS NVARCHAR(500)='[250], [251], [256], [257], [260]'
AS 
DECLARE @qy NVARCHAR(500)


SET @qy='SELECT VendorID, '+dbo.SetAliasForPivotingCols(@p)+'
        FROM 
        (SELECT PurchaseOrderID, EmployeeID, VendorID
        FROM Purchasing.PurchaseOrderHeader) p
        PIVOT
        (
        COUNT (PurchaseOrderID)
        FOR EmployeeID IN
        ( '+@p+' )
        ) AS pvt
        ORDER BY pvt.VendorID;
EXEC sp_executesql @qy

To attach alias after pivoted fields (imagine im not doing this if its complex) :

CREATE FUNCTION [dbo].[SetAliasForPivotingCols](@RequestedRscsId NVARCHAR(500))RETURNS `NVARCHAR(2000)`
BEGIN
SET @RequestedRscsId=','+@RequestedRscsId
DECLARE @ReturnValue NVARCHAR(2000)=''
DECLARE @CloseBraceIndex INT
DECLARE @Alias NVARCHAR(10)
WHILE LEN(@RequestedRscsId)>1
BEGIN
    SET @CloseBraceIndex=PATINDEX('%]%',@RequestedRscsId)
    SET @Alias=SUBSTRING(@RequestedRscsId,2,@CloseBraceIndex-1)
    SET @RequestedRscsId   =SUBSTRING(@RequestedRscsId,@CloseBraceIndex+1,LEN(@RequestedRscsId)-@CloseBraceIndex+1)
    SET @ReturnValue+=',SUM('+@Alias+')'+' AS '+SUBSTRING(@Alias,1,LEN(@Alias))
END
RETURN SUBSTRING(@ReturnValue,2,LEN(@ReturnValue))
END

any suggestion?

thank you.

  • 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-26T04:52:31+00:00Added an answer on May 26, 2026 at 4:52 am

    It is not possible. You must consume such stored procedure with classic ADO.NET.

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

Sidebar

Related Questions

I have a 200 line long stored procedure, which gets a parameter 'prmtr', What
I have a stored procedure which takes an XML parameter and inserts the data
I am using mysql 5.0. I have a stored procedure which gets all the
I have a gridview which uses a stored procedure with session[UserName] as a parameter
I have a stored procedure which filters based on the result of the DATEADD
I have a Stored procedure which schedules a job. This Job takes a lot
I have a stored procedure which executes a select statement. I would like my
I have a stored procedure which returns a ref cursor as follows: CREATE OR
I have a stored procedure which basically does something like select top 1 expiryDate,
I have a stored procedure which is doing a lot of delete. Hundreds of

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.