SQL 在OPENQUERY中使用传入参数和临时表获取参数

IF object_id('tempdb..#itemtype_temporary') IS NOT NULL
 BEGIN
  DROP TABLE #itemtype_temporary
 END
CREATE TABLE #itemtype_temporary
(
 itemtype NVARCHAR (30)
)
DECLARE @part_no NVARCHAR(30)
DECLARE @sql NVARCHAR(300)
DECLARE @itemtype NVARCHAR(30)
SET @part_no='9H.A0G01.8TE'
SET @sql='INSERT INTO #itemtype_temporary (itemtype) SELECT * FROM OPENQUERY(EBS12D,''SELECT ITEMTYPE FROM APPS.XXIN_GSN_SN_FLAG_v WHERE ITEMNO='''''+@part_no+''''''')';
EXEC sp_executesql @sql

SELECT @itemtype=itemtype FROM #itemtype_temporary
DROP TABLE #itemtype_temporary
PRINT @itemtype

你可能感兴趣的:(sql,object,table,insert)