SQL查询如下:
DECLARE @Sql VARCHAR (8000)
SET @Sql='XXXXXX'
IF OBJECT_ID('tempdb..#Orders') IS NOT NULL DROP TABLE #Orders
EXEC('SELECT * INTO #Orders FROM OPENQUERY(TMM10, ''' +@Sql+ ''')')
--Until now everything seems OK
SELECT * FROM #Order
此语句在插入临时表之前运行良好。结果显示“已插入49134行”。但是,错误显示“无效的对象名称#Order”,它确实存在于Tempdb中。
答案 0 :(得分:0)
范围问题;我修改了你的测试,以展示解决方法。
DECLARE @Sql VARCHAR (8000)
SET @Sql='XXXXXX'
IF OBJECT_ID('tempdb..#Orders') IS NOT NULL DROP TABLE #Orders
CREATE TABLE #Orders (ID INT)
INSERT INTO #Orders
( ID )
EXEC('SELECT 1')
--Until now everything seems OK
SELECT * FROM #Orders