Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

MS SQL Server join on Table and strored procedure results

I have a very good solution from another expert that does a dynamic sql and returns a variable number of columns based on other input.

I placed that solution in a storedprocedure

Is there a way to do a select on a table with a join to the output from the stored procedure

If I knew the columns I could create table #temp
and insert into it with an exe on the procedure

But the variable length nature of the response precludes that
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Larry Brister

ASKER

And its not possible to crate a #temp table using these columns and setting each to a varchar(100) type?

DECLARE @cols VARCHAR(MAX);

SELECT   @cols = ISNULL(@cols + ',', '') + '[' + QuestionType + ']'
FROM     vwPromotionSurveyIndividualAnswersWithID
GROUP BY QuestionType;
Sure, but due to the scope, you need to create it before you call the procedure.. so it won't work.
Well just for grins
How would I create that table?

I will be awarding points shortly
By creating a "temporary table", thus creating a normal table in tempdb using the same dynamic approach for the columns as for creating your pivot.
Thanks