Sql server 2008 程序之间共享的临时表
我有一个程序,我们称之为Sql server 2008 程序之间共享的临时表,sql-server-2008,Sql Server 2008,我有一个程序,我们称之为 caller 创建临时表的过程 #temp1 exec另一个过程调用 callee 在#temp1表中插入一些值以便调用者过程可以使用的过程。现在的问题是,我的被调用者过程只能通过调用者或其他创建#temp1表然后执行被调用者的过程来调用。是否有类似于引入“If”条件检查的方法,如果调用者调用了被调用者,则只执行语句 'insert #temp1 ....' 另一个明智的选择是避免 谢谢为了知道谁调用了过程“被调用方”,您可以实现逻辑-将参数添加到默认值为N
caller
创建临时表的过程
#temp1
exec另一个过程调用
callee
在#temp1表中插入一些值以便调用者过程可以使用的过程。现在的问题是,我的被调用者过程只能通过调用者或其他创建#temp1表然后执行被调用者的过程来调用。是否有类似于引入“If”条件检查的方法,如果调用者调用了被调用者,则只执行语句
'insert #temp1 ....'
另一个明智的选择是避免
谢谢为了知道谁调用了过程“被调用方”,您可以实现逻辑-将参数添加到默认值为NULL的“被调用方”(例如),然后通过添加值为1的参数(例如),仅更改“调用方”过程。在“被调用方”过程中,检查此参数的值,如果它不同于NULL,则使用临时表 代码示例:
create procedure [callee]
(
@CalledByCaller bit = NULL
)
as
set nocount on
If @CalledByCaller =1
begin
SELECT '3'
--work with temp table
end
SELECT '2'
go
create procedure [caller]
as
set nocount on
exec [callee] @CalledByCaller =1
go
您可以实现逻辑以了解谁调用了过程“callee”-将param添加到默认值为NULL的“callee”(例如),然后通过添加值为1的此param(例如)仅更改“caller”过程。在“被调用方”过程中,检查此参数的值,如果它不同于NULL,则使用临时表 代码示例:
create procedure [callee]
(
@CalledByCaller bit = NULL
)
as
set nocount on
If @CalledByCaller =1
begin
SELECT '3'
--work with temp table
end
SELECT '2'
go
create procedure [caller]
as
set nocount on
exec [callee] @CalledByCaller =1
go
< > >强> >被调用方将总是产生一个结果集,它是应该被插入到
CREATE procedure caller
as
--Various things
create table #temp1 (column1,column2)
--Other things
insert into #temp1 (column1,column2) exec callee
--Work with #temp1
< > >强> >被调用方将总是产生一个结果集,它是应该被插入到
CREATE procedure caller
as
--Various things
create table #temp1 (column1,column2)
--Other things
insert into #temp1 (column1,column2) exec callee
--Work with #temp1
无法使用insert exec,因为SQL不允许我使用嵌套insertexec@LivingThing-如果您想做的事情(嵌套插入…exec)本质上无法使用insert exec,则有一些变通方法,因为SQL不允许我使用嵌套插入exec@LivingThing-如果是的话,基本上有解决办法,要执行的操作(嵌套插入…exec)