Wednesday, 28 August 2013

T-SQL example to insert result set returned from remote linked server procedure call to a temporary table

declare @parameter1 int, @parameter2 date
select @parameter1=123, @parameter2='2013-08-28'
IF (object_id('tempdb..#TempTable')) is not null
BEGIN
drop table  #TempTable
END
CREATE TABLE #TempTable(col1 int, col2 varchar(50), primary key clustered(col1))
INSERT INTO #TempTable
EXECUTE [LinkedServerName].[DatabaseName].[SchemaName].[usp_StoredProcedure] @parameter1=@parameter1,  @parameter2=@parameter2
SELECT * FROM #TempTable

No comments:

Post a Comment