I know this sounds like it should be tagged as Homework but i am really in need of help here.
This procedure
OPEN @Iterador
FETCH NEXT FROM @Iterador INTO @GrupoMedidas
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO @Resultado(GrupoMedidas
, TextoPregunta
, ANTERIOR
, ENERO
, FEBRERO
, MARZO
, ABRIL
, MAYO
, JUNIO
, JULIO
, AGOSTO
, SEPTIEMBRE
, OCTUBRE
, NOVIEMBRE
, DICIEMBRE)
SELECT @GrupoMedidas
, TextoPregunta
, ANTERIOR
, ENERO
, FEBRERO
, MARZO
, ABRIL
, MAYO
, JUNIO
, JULIO
, AGOSTO
, SEPTIEMBRE
, OCTUBRE
, NOVIEMBRE
, DICIEMBRE
FROM [dbo].[FRespuestasGrupo](@Anio, @GrupoMedidas)
FETCH NEXT FROM @Iterador INTO @GrupoMedidas
END
Is taking 38 seconds to run on a relatively small database. I've read that Cursors are absolute evil in the land or RDBMS systems and that they should be avoided as such for performance reasons but i can't -for the life of me- imagine a way to lose the cursor usage from this.
What this procedure is achieving right now (painfully slow tho) is to pair up a question-set (@GrupoMedidas) with each of it's questions so each row in the final table winds up like
Question-Set-Name|Question-Name-1|Answer-For-January|Answer-For-February...
Question-Set-Name|Question-Name-2|Answer-For-January|Answer-For-February...
(The table schema has been laid out in Spanish)
FRespuestasGrupo is the one responsible for listing all the questions for a given question set with the answer for each month in the year supplied as an argument.
All other procedures involved in this query have been stripped out of cursors already so this is my last hope right now.