存储过程临时表让我疯狂了解更多 [英] stored procedure temporary table making me crazy to know more about it

查看:72
本文介绍了存储过程临时表让我疯狂了解更多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1 ============================================== =====================

--i还没有创建#facility表

- 但是如果我执行以下声明

选择facility_id,将Facility_Name导入#facility,来自tbl_facility,其中hub = 1



它成功插入....



2 ================================= =========================================

- - 但如果我喜欢这个 - 我不是在创建#facility表





从tbl_facility中选择facility_id,Facility_Name,其中hub = 1

union all

从tbl_facility中选择facility_id,facility_name,其中facility_id = 145

到#facility4



- 给我错误

- 关键字'into'附近的语法不正确。



3 == ================================================== =================



- 如果我喜欢这样 - 我不是在创建#facility表





从tbl_facility选择facility_id,Facility_Name到#facility5,其中hub = 1

union all

从tbl_facility中选择facility_id,facility_name到#facility5,其中facility_id = 145



数据库中已经有一个名为'#facility5'的对象。



- 我将它更改为#facility6 ..同样错误....

i正在思考它......为什么会出现这个错误......如果第1步工作正常,,,

然后步骤2或3也应该正常工作,,,,

1===================================================================
--i have not created the #facility table
--but if i execute the below statement
select facility_id,Facility_Name into #facility from tbl_facility where hub=1

it successfully inserts....

2==========================================================================
---but if i do like this--i am not creating #facility table


select facility_id,Facility_Name from tbl_facility where hub=1
union all
select facility_id,facility_name from tbl_facility where facility_id=145
into #facility4

--it gives me error
--Incorrect syntax near the keyword 'into'.

3=====================================================================

--and if i do like this--i am not creating #facility table


select facility_id,Facility_Name into #facility5 from tbl_facility where hub=1
union all
select facility_id,facility_name into #facility5 from tbl_facility where facility_id=145

There is already an object named '#facility5' in the database.

--i changed it to #facility6 ..same error....
i am pondering over it....why this error is coming...if step 1 works fine,,,
then step 2 or 3 should also work fine,,,,

推荐答案

试试



Try

select facility_id,Facility_Name into #facility5 from tbl_facility where hub=1
union all
select facility_id,facility_name from tbl_facility where facility_id=145


这篇关于存储过程临时表让我疯狂了解更多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆