Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/09/2008, 17:41
Avatar de flaviovich
flaviovich
 
Fecha de Ingreso: agosto-2005
Ubicación: Lima, Peru
Mensajes: 2.951
Antigüedad: 18 años, 9 meses
Puntos: 39
Respuesta: ¿Puedo crear tabla temporal con campos flexibles?

Claro que se puede. Yo administro un sistema que hace lo mismo.
El usuario tiene la opcion de crear estructuras, las cuales llena desde diferentes medios, el mas usado, Excel.
Pienso que no necesitas la segunda tabla, solo una donde guardes la estructura de cada tabla. En base a esta estructura formaras el query que te permitira crear la tabla.
Te paso parte del script donde se crea dinamicamente una tabla:
Cita:
declare cur_defstructtable cursor for
select dat_gr_campo
,dat_gr_tipo_campo
,dat_gr_largo_campo
,dat_gr_orden
,dat_gr_es_rut
,dat_gr_es_nombre
from tb_estructura_grupo
where tgrupo_codigo = @tgrupo_codigo
order by dat_gr_orden
for read only
-- nota : abrimos el cursor para formar la estructura
open cur_defstructtable
fetch next from cur_defstructtable into @cur_dat_gr_campo
,@cur_dat_gr_tipo_campo
,@cur_dat_gr_largo_campo
,@cur_dat_gr_orden
,@cur_dat_gr_es_rut
,@cur_dat_gr_es_nombre
while @@fetch_status = 0
begin
if @cur_dat_gr_es_rut = 's'
begin
select @positionofid = @cur_dat_gr_orden
select @positionofid = @cur_dat_gr_orden
select @fieldkeyname = @cur_dat_gr_campo
end
select @counterrow = @counterrow + 1
select @strsqlstruct = @strsqlstruct + ' [' + @cur_dat_gr_campo + ']'
select @strsqlstruct = @strsqlstruct + ' ' + @cur_dat_gr_tipo_campo
if @cur_dat_gr_largo_campo is not null select @strsqlstruct = @strsqlstruct + '(' + convert(varchar,@cur_dat_gr_largo_campo) + ')'
if @counterrow != @totalrowstruct select @strsqlstruct = @strsqlstruct + ',' + char(13)
else select @strsqlstruct = @strsqlstruct + char(13)
fetch next from cur_defstructtable into @cur_dat_gr_campo
,@cur_dat_gr_tipo_campo
,@cur_dat_gr_largo_campo
,@cur_dat_gr_orden
,@cur_dat_gr_es_rut
,@cur_dat_gr_es_nombre
end
close cur_defstructtable
Espero que te ayude.
Suerte!
__________________
No repitamos temas, usemos el Motor de busquedas
Plantea bien tu problema: Ayúdanos a ayudarte.