如何使用表加入存储过程 [英] How to Join Store procedure with a table
问题描述
您好我的商店程序从输入值返回一个表
但是我无法使用/加入此程序和另一个表中的值。
看看这个灾难代码并帮助我。谢谢
lame attempt#1
select T1。*,SP。* 来自 dbo.mytable as [T1]
内部 join
exec sp_iteration_control [T1.sub] as [SP]
on sp.sub = t1.sub
Lame尝试#2
声明 @ counter int
, @ sub varchar ( 12 )
while (@ Counter<(选择 COUNT(*)来自 dbo .mytable))
BEGIN
选择 @ sub = Sub 来自 dbo.mytable
exec dbo.sp_iteration_control @ sub
SET @ Counter + = 1
END
您可以调用SP并将结果输入临时表,然后将这些数据与您的记录集连接起来。
请参阅:将存储过程结果插入表 [ ^ ]
< blockquote>
引用:从dbo.mytable中选择T1。*,SP。*作为[T1]
内连接
exec sp _iteration_control [T1.sub] as [SP]
on sp.sub = t1.sub
这不是将存储过程加入表的方法。为了加入,我们需要将存储过程数据插入表中,我们需要连接
您无法调用存储过程并在另一个查询中使用结果。视图可以工作,但您不能拥有视图参数。如果您需要执行类似的操作并需要参数,则可以签出创建函数。
Hi my store procedure returns a table from a input value
but i am unable to use/join this procedure with values available in another table.
look at this catastrophe code and help me out. thank you
lame attempt #1
select T1.* , SP.* from dbo.mytable as [T1]
inner join
exec sp_iteration_control [T1.sub] as [SP]
on sp.sub=t1.sub
Lame attempt #2
declare @counter int
,@sub varchar(12)
While(@Counter<(select COUNT(*) from dbo.mytable))
BEGIN
select @sub=Sub from dbo.mytable
exec dbo.sp_iteration_control @sub
SET @Counter +=1
END
You can call SP and get result into temporary table, then join these data with your recordset.
Please, see: Insert Stored Procedure Results Into Table[^]
Quote:select T1.* , SP.* from dbo.mytable as [T1]
inner join
exec sp_iteration_control [T1.sub] as [SP]
on sp.sub=t1.sub
This is not the way to join the stored procedure to a table. In order to do join the we need to insert stored procedure data into a table and we need to to the join
You cannot call a stored procedure and use the results inside another query. A view would work, but you cannot have parameters with views. If you need to do something like this and need parameters, you can checkout creating a function.
这篇关于如何使用表加入存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!