我正在使用 sql server 2000,我需要从服务器中的所有数据库中读取所有数据,因为那时我将使用一些数据,我该如何进行此查询?我已经尝试过这段代码,但不能按我的意愿工作。
ALTER PROCEDURE TMP_INGRESO_MASIVO_DAT_CLIENTES AS
declare @Fila as int
declare @Script_Dinamico as varchar(8000)
declare @Script_Dinamico1 as varchar(8000)
declare @Nro_Registros as int
Select Distinct cod_empresa,Nombre_Base Into #Tmp_Bases1 From Estadistica_Cobranza.Dbo.Sis_Conexion_pagos Where Cod_Estado = 1 and Proc_Automaticos= 1--capturo nombre BD
Select Distinct Identity(Int,1,1) As Fila, cod_empresa , Nombre_Base As Name Into #Tmp_Bases From #Tmp_Bases1
Drop table #Tmp_Bases1
Select @Fila = 1
Select @Script_Dinamico = ''
Select @Script_Dinamico1 = ''
Select @Nro_Registros = (Select Count (*) From #Tmp_Bases ) + 1--cantidad de filas +1
While @Fila < = @Nro_Registros
Begin
Print(@Script_Dinamico)
Select @Script_Dinamico = 'INSERT INTO buc.dbo.tmp_DAT_CLIENTES '
Select @Script_Dinamico = @Script_Dinamico +'(COD_EMPRESA,'
Select @Script_Dinamico = @Script_Dinamico +'COD_SUCURSALEMPRESA,'
Select @Script_Dinamico = @Script_Dinamico +'RUT_CLIENTE,'
Select @Script_Dinamico = @Script_Dinamico +'RAZON_SOCIAL, '
Select @Script_Dinamico = @Script_Dinamico +'FECHA_CARGA,'
Select @Script_Dinamico = @Script_Dinamico +'FECHA_MODIFICACION'
Select @Script_Dinamico = @Script_Dinamico +')'
Select @Script_Dinamico = @Script_Dinamico +'Select '
Select @Script_Dinamico = @Script_Dinamico +'COD_EMPRESA, '
Select @Script_Dinamico = @Script_Dinamico +'COD_SUCURSALEMPRESA, '
Select @Script_Dinamico = @Script_Dinamico +'RUT_CLIENTE, '
Select @Script_Dinamico = @Script_Dinamico +'RAZON_SOCIAL, '
Select @Script_Dinamico = @Script_Dinamico +'FECHA_CARGA, '
Select @Script_Dinamico = @Script_Dinamico +'FECHA_MODIFICACION'
Select @Script_Dinamico = @Script_Dinamico + ' from ' + (Select Name From #tmp_bases Where Fila = @Fila) +'.Dbo.DAT_CLIENTES '
Select @Script_Dinamico = @Script_Dinamico + 'Where ' + (Select Name From #tmp_bases Where Fila = @Fila) +'.Dbo.DAT_CLIENTES.cod_empresa = '+ convert(varchar,(Select cod_empresa From #tmp_bases Where Fila = @Fila))
Select @Script_Dinamico = @Script_Dinamico +'and '+ (Select Name From #tmp_bases Where Fila = @Fila) +'.Dbo.DAT_CLIENTES.rut_cliente not in (select RUT_CLIENTE from tmp_dat_clientes'
Select @Script_Dinamico = @Script_Dinamico+' where '+ (Select Name From #tmp_bases Where Fila = @Fila) +'.Dbo.DAT_CLIENTES.rut_cliente = buc.dbo.tmp_DAT_CLIENTES.RUT_CLIENTE )'
Print ( @Script_Dinamico)
Exec (@Script_Dinamico )
Select @Fila = @Fila +1
Select @Script_Dinamico = ''
Select @Script_Dinamico1 = ''
End
Drop Table #Tmp_Bases
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO