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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:30:01+00:00 2026-05-27T09:30:01+00:00

Here is the problem. I have a stored procedure that transforms normalized data into

  • 0

Here is the problem.

I have a stored procedure that transforms normalized data into a standard dataset.

I need to report on some data which consists of a view, and two data sets from the stored procedure with different parameters being submitted to the stored procedure which returns different columns.

Example

If My view Contains something like:

ID  Title   Status  Date
1   How To Party Like a rockstar    Approved    7/15/1989
2   Too much of a good thing    Approved    7/25/2001
3   Needs More Cowbell  Denied  11/11/2011
4   Here Today Gone Tommorrow   Approved    8/13/1969
5   The way She moves   Approved    12/13/2011

And the procedure run with one paramater returns:

ID  Do you like the ice Cream?  How much would you pay for the ice cream?
1   Yes 2
2   Yes 5
3   Yes 7
4   No  2
5   No  3

And the same procedure run with a different parameter returns:

ID  Total Number of Bell Peppers    Total Number of Apples  Total Number of Oranges
1   7   6   6
2   6   8   8
3   32  7   5
4   7   3   1
5   12  1   1

Assuming that the ID column is a key that can be used to join the data sets, how would i go about getting:

ID  Title   Status  Date    Do you like the ice Cream?  How much would you pay for the ice cream?   Total Number of Bell Peppers    Total Number of Apples  Total Number of Oranges
1   How To Party Like a rockstar    Approved    7/15/1989   Yes 2   7   6   6
2   Too much of a good thing    Approved    7/25/2001   Yes 5   6   8   8
3   Needs More Cowbell  Denied  11/11/2011  Yes 7   32  7   5
4   Here Today Gone Tommorrow   Approved    8/13/1969   No  2   7   3   1
5   The way She moves   Approved    12/13/2011  No  3   12  1   1

Keeping in mind that the stored procedures cannot be done with inline sql due to the nature of the normalization and the transformation of the normalization, and I do not believe that they can be done as a table variable udf due to the fact that the stored procedure returns a variable number of columns depending on the parameter that is passed to it when it is run (if someone can prove me wrong on this and point me in the direction of a dynamic column table-valued udf i would be very appreciative)

If i can someway bring the view and the two stored procedures into one stored procedure and return the dataset in that fashion, that would be my ultimate goal.

I also need to mention that Ad Hoc Distributed Queries cannot be turned on on this server (not my decision)

Resolution

With a little help from Stuart Ainsworth’s answer I was able to work it out. My initial problem with the whole thing was that the columns were dynamic for each of the crosstab tables. so as a part of that I had created a function that returned the columns as a comma deliminated string…

        DECLARE
            @PivotColumns VARCHAR(MAX)

        SET @PivotColumns = dbo.fnGetFormPivotColumns(9)

Where the 9 in this case is the parameter which lets me know which item i’m building for. From there it was just a repeat of the functionality in the base sp to build the temp tables dynamically so I came up with this:

IF object_id('tempdb..#temp_DEP') IS NOT NULL
    DROP TABLE #temp_DEP


CREATE TABLE #temp_DEP (APPLICATION_ID int)
EXEC ('ALTER TABLE #temp_DEP ADD ' + @PivotColumns)

INSERT INTO #temp_DEP
    EXEC GetFormCrossTab 9 

A simple SELECT * FROM #temp_DEP shows that I’m getting exactly what I want.

All I have to do is repeat the process for the other parameter and I get my two data sets within the same stored procedure.

  • 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-27T09:30:02+00:00Added an answer on May 27, 2026 at 9:30 am

    You could build a stored procedure and use an IF statement to satisfy each of your parameters, eg:

    CREATE PROC someproc @parameter AS
    
    CREATE TABLE #scratch1 (columns)...
    CREATE TABLE #scratch2 (columns)...
    
    IF @parameter = 1
    BEGIN 
    INSERT INTO #scratch1 
    exec oldproc @parameter
    END
    
    IF @parameter = 2
    BEGIN 
    INSERT INTO #scratch1 
    exec oldproc @parameter
    END
    
    
    SELECT *
    FROM view v
    LEFT JOIN #scratch1 s1 ON v.ID =s1.ID
    ...etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi Stackoverflow super stars... Here's my problem. I have a stored procedure that outputs
I have a stored procedure that returns a value, not a dataset, and I
I have a stored procedure called sp_BulkInsert that inserts one .csv file into my
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
Here's my problem: I have a virtual method defined in a .h file that
Here I am facing a problem that I want to pass a dataset to
I have a client application that scrapes data into a raw table. This client
I have a report that needs to get data from two logical areas of
I have tried solving this problem by posting other related questions here that focused
I have inherited a very old database that needs some data to be updated.

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.