Pasando a explicar y despues de 2 dias de estar peleando con una consulta desaforadamente dinamica y mortal...puedo ahora si darles mis resultados:
1. La consulta ni siquiera terminaba cuando era ejecutada por el codigo de VB
2. El mejor performance, lo daba una consulta dinamica desde el stored procedure, el problema era el mantenimiento que se le tiene que dar y las lines interminables que se adicionan cuando se hace una consulta de este tipo
3. Un performance "aceptable" y el ultimo approach fue generar la consulta desde ASP y ejecutarla en el stored procedure, con esto el mantenimiento de dicha consulta no se complica tanto
4. Por alguna extrana razon que desconozco, la consulta generaba datos erroneos cuando un SELECT IN(), no devolvia resultados, por lo tanto tuve que recurrir a condicionar este resultado con T-SQL
Mi consulta dinamica y ademas recursiva

:
Código:
IF EXISTS(SELECT DISTINCT j.page_id FROM xref_iGroup_record i INNER JOIN tbl_page j ON i.record_id = j.page_template_id INNER JOIN live_revisions_view k ON j.page_id = k.original_content_id INNER JOIN tbl_template2 l ON k.revision_id = l.template2_id WHERE j.page_id = k.original_content_id AND k.type_id = 1 AND ((l.template2_start_date = '1/1/1900') OR l.template2_start_date < getDate()) AND(( l.template2_end_date = '1/1/1900') OR l.template2_end_date > getDate()) AND j.page_display_bit = '1' AND j.page_parent_id = 1 AND i.table_id = 25 AND i.iGroup_id IN(17) )BEGIN SELECT a.page_id, a.page_template_id, CASE a.page_table_id WHEN 25 THEN (SELECT template2_name FROM tbl_template2 WHERE template2_id = a.page_template_id) WHEN 0 THEN (SELECT template1_name FROM tbl_template1 WHERE template1_id = a.page_template_id) END AS page_name FROM tbl_page a INNER JOIN live_revisions_view b ON a.page_id = b.original_content_id LEFT JOIN tbl_template2 c ON b.revision_id = c.template2_id WHERE a.page_id = b.original_content_id AND b.type_id = 1 AND ((c.template2_start_date = '1/1/1900') OR c.template2_start_date < GetDate()) AND ((c.template2_end_date = '1/1/1900') OR c.template2_end_date > GetDate()) AND a.page_display_bit = '1' AND a.page_template_id NOT IN(SELECT record_id FROM xref_iGroup_record WHERE table_id = 25 AND content_type = 1) AND page_parent_id = 1 OR a.page_id IN(SELECT DISTINCT j.page_id FROM xref_iGroup_record i INNER JOIN tbl_page j ON i.record_id = j.page_template_id INNER JOIN live_revisions_view k ON j.page_id = k.original_content_id INNER JOIN tbl_template2 l ON k.revision_id = l.template2_id WHERE j.page_id = k.original_content_id AND k.type_id = 1 AND ((l.template2_start_date = '1/1/1900') OR l.template2_start_date < getDate()) AND(( l.template2_end_date = '1/1/1900') OR l.template2_end_date > getDate()) AND j.page_display_bit = '1' AND j.page_parent_id = 1 AND i.table_id = 25 AND i.iGroup_id IN(17) ) END ELSE SELECT a.page_id, a.page_template_id, CASE a.page_table_id WHEN 25 THEN (SELECT template2_name FROM tbl_template2 WHERE template2_id = a.page_template_id) WHEN 0 THEN (SELECT template1_name FROM tbl_template1 WHERE template1_id = a.page_template_id) END AS page_name FROM tbl_page a INNER JOIN live_revisions_view b ON a.page_id = b.original_content_id LEFT JOIN tbl_template2 c ON b.revision_id = c.template2_id WHERE a.page_id = b.original_content_id AND b.type_id = 1 AND ((c.template2_start_date = '1/1/1900') OR c.template2_start_date < GetDate()) AND ((c.template2_end_date = '1/1/1900') OR c.template2_end_date > GetDate()) AND a.page_display_bit = '1' AND a.page_template_id NOT IN(SELECT record_id FROM xref_iGroup_record WHERE table_id = 25 AND content_type = 1) AND page_parent_id = 1 ORDER BY page_order
Y el simplisimo stored procedure:
Código:
CREATE PROCEDURE stp_SiteMap
@sqlStatement varchar(8000)
AS
EXEC(@sqlStatement)
GO
Salu2,