-- 建测试存储过程
create proc sp1214
(@x int)
with recompile
as
begin
if @x=1
select 1 s union all select 2 option(recompile)
else
select 1 s,11 s2 union all select 2,22 option(recompile)
end -- 测试2种参数的执行
exec sp1214 1
--> 返回1列exec sp1214 2
--> 返回2列select *
from
OPENROWSET(
'SQLOLEDB','SERVER=(local);uid=sa;pwd=123456;Database=DBAP', 'exec sp1214 1')s
-----------
1
2
select *
from
OPENROWSET(
'SQLOLEDB','SERVER=(local);uid=sa;pwd=123456;Database=DBAP', 'exec sp1214 2')Msg 7353, Level 16, State 1, Line 1
The OLE DB provider "SQLNCLI10" for linked server "(null)" supplied inconsistent metadata.
An extra column was supplied during execution that was not found at compile time.
之所以用OPENROWSET,是因为想把2种执行结果自动存为临时表,
即 select * into #t from openrowset(...)能实现相同目的的方法也行.
insert into #tb exec sp1214 1