Em Andamento

Dynamic SQL for Sub Question Query


I need a stored procedure that takes the following parameters...


CREATE PROCEDURE id3_MultipartQuestion_Select

@Main_Question_ID int,

@Sub_Question_IDs varchar(500),

@Submission_Guid varchar(50),

@This_Step int,

@Request_Locale varchar(5)


...and when it is called, the stored procedure executes the query below. The query has a "main question" subquery which is named Q0 and then has "sub question" queries named Q1 and A1, Q2 and A2, Q3 and A3. However, I need it to be dynamically written so that the number of sub questions will vary depending on the parameter passed. As you can see, the sub-queries all follow the same pattern, so hopefully this is not a difficult task.

To be clear, the query below is what should be executed if @Sub_Question_IDs='22,12,20'. If @Sub_Question_IDs='24,10,15,18' then there would be Q0, Q1 and A1, Q2 and A2, Q3 and A3, and two additional joins named Q4 and A4. And if @Sub_Question_IDs='24' then there would simply be Q0, Q1 and A1


Habilidades: SQL

Ver mais: sub all, named query, all sub, sub, sql question, queries sql, difficult task, stored procedure create sql, sql questions, create question, query project server sql, sql dynamic data exchange, sql procedure, query zip mile sql, pattern questions, parameters stored procedure sql, dynamic questions, sql stored procedure

Acerca do Empregador:
( 7 comentários ) New York, United States

ID do Projeto: #5106168

Premiar a:


Hired by the Employer

$60 USD em 4 dias
(106 Avaliações)