Create a linked server. You cannot do this in the context of a stored procedure. You can however setup the login credentials in a stored procedure. In the example below it assumes that the linked server was named OTHERSERVER. This would allow you to pass a user name and password for the new connection and call a stored procedure.
create procedure NewTestProc (
@I int,
@userName sysname,
@password sysname
)
as
begin
declare @locallogin sysname
set @locallogin = SUSER_NAME()
EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname=N'OTHERSERVER', @useself=N'False',
@locallogin=@locallogin,@rmtuser=@userName,
@rmtpassword=@password
EXEC OTHERSERVER.DestinationDatabase.dbo.StoredProcInOtherDatabase
@OtherParameter = @i
EXEC master.dbo.sp_droplinkedsrvlogin
@rmtsrvname=N'OTHERSERVER',@locallogin=@locallogin
end
To call a stored procedure you would also have to enable RPC for the linked server
EXEC master.dbo.sp_serveroption @server=N'OTHERSERVER',
@optname=N'rpc', @optvalue=N'true'