在我的存储过程中,我使用 SELECT INTO 语句创建了一个临时表,当我想在Cursor中使用我的临时表时,它说'invalid object name
'
DECLARE @sql_temp_table NVARCHAR(MAX)
SELECT @sql_temp_table = 'SELECT ''PORT_ALM'' AS tbl_a, col_name AS tbl_b, ''A_'' + col_name AS tbl_c INTO #temp_a FROM ' + @lkup_port_logic + ' WHERE ALM_FLG = ''Y''' + CHAR(13) +
'UNION' + CHAR(13) +
'SELECT ''PORT_FTP'' AS tbl_a, col_name AS tbl_b, ''F_'' + col_name AS tbl_c FROM #temp_a WHERE FTP_FLG = ''Y''' + CHAR(13) +
'UNION' + CHAR(13) +
'SELECT ''PORT_LCR'' AS tbl_a, col_name AS tbl_b, ''L_'' + col_name AS tbl_c FROM #temp_a WHERE LCR_FLG = ''Y''' + CHAR(13) +
''
EXEC sp_executesql @sql_temp_table
DECLARE @sql_add_col NVARCHAR(MAX)
DECLARE @sql_sel_stmt NVARCHAR(MAX)
DECLARE SECONDCURSOR CURSOR FOR
SELECT * FROM #temp_a
运行以下声明:
DECLARE SECONDCURSOR CURSOR FOR SELECT * FROM #temp_a
#temp_a
被标记为无效对象名称