Un stored procedure que llama a otro stored procedure en otro servidor SQL
Hola. Llevo casi una semana para conserguir esto que dice el titulo del mensaje y el problema era pasar una serie de parametros del primer stored al segundo con OPENROWSET. Al final he tenido que hacer el filtrado en el primer stored de la siguiente manera:
DECLARE @nBanco nvarchar(255)
DECLARE @nProvincia nvarchar(255)
DECLARE @nLocalidad nvarchar(255)
DECLARE @nDireccion nvarchar(255)
DECLARE @nCodigo nvarchar(5)
DECLARE @nNumero nvarchar(5)
DECLARE @opc nvarchar(256)
declare @csql nvarchar(4000)
SET @nBanco ='0'
SET @nProvincia ='0'
SET @nLocalidad ='0'
SET @nDireccion ='0'
SET @nCodigo ='0'
SET @nNumero ='3002'
declare @aux1 nvarchar(4000)
set @aux1=''
if @nBanco<>'0'
BEGIN
set @aux1 = ' NombreEntidad =''' + @nBanco + ''''
END
if @nProvincia<>'0'
BEGIN
set @aux1 = @aux1 + ' and Provincia =''' + @nProvincia + ''''
END
if @nLocalidad<>'0'
BEGIN
set @aux1 = @aux1 + ' and Localidad =''' + @nLocalidad + ''''
END
if @nDireccion<>'0'
BEGIN
set @aux1 = @aux1 + ' and direccion =''' + @nDireccion + ''''
END
if @nCodigo<>'0'
BEGIN
set @aux1 = @aux1 + ' and cpostal =''' + @nCodigo + ''''
END
if @nNumero<>'0'
BEGIN
set @aux1 = @aux1 + ' and sucursal =''' + @nNumero + ''''
END
IF (@aux1<>'')
BEGIN
set @aux1 = ' Where ' + @aux1
END
set @csql='SELECT * FROM OPENROWSET (''SQLOLEDB'',''ipservidor'';'usurario'';''clave'',''exec nombrebase.dbo.nombrestored'')' + @aux1
exec(@csql)
GO
DECLARE @nBanco nvarchar(255)
DECLARE @nProvincia nvarchar(255)
DECLARE @nLocalidad nvarchar(255)
DECLARE @nDireccion nvarchar(255)
DECLARE @nCodigo nvarchar(5)
DECLARE @nNumero nvarchar(5)
DECLARE @opc nvarchar(256)
declare @csql nvarchar(4000)
SET @nBanco ='0'
SET @nProvincia ='0'
SET @nLocalidad ='0'
SET @nDireccion ='0'
SET @nCodigo ='0'
SET @nNumero ='3002'
declare @aux1 nvarchar(4000)
set @aux1=''
if @nBanco<>'0'
BEGIN
set @aux1 = ' NombreEntidad =''' + @nBanco + ''''
END
if @nProvincia<>'0'
BEGIN
set @aux1 = @aux1 + ' and Provincia =''' + @nProvincia + ''''
END
if @nLocalidad<>'0'
BEGIN
set @aux1 = @aux1 + ' and Localidad =''' + @nLocalidad + ''''
END
if @nDireccion<>'0'
BEGIN
set @aux1 = @aux1 + ' and direccion =''' + @nDireccion + ''''
END
if @nCodigo<>'0'
BEGIN
set @aux1 = @aux1 + ' and cpostal =''' + @nCodigo + ''''
END
if @nNumero<>'0'
BEGIN
set @aux1 = @aux1 + ' and sucursal =''' + @nNumero + ''''
END
IF (@aux1<>'')
BEGIN
set @aux1 = ' Where ' + @aux1
END
set @csql='SELECT * FROM OPENROWSET (''SQLOLEDB'',''ipservidor'';'usurario'';''clave'',''exec nombrebase.dbo.nombrestored'')' + @aux1
exec(@csql)
GO
