--用windows身份验证登陆
--如果不是windows请自己改连接字符串
--这句 ''DRIVER={SQL Server};SERVER=.;Integrated Security=SSPI''
--改成 ''DRIVER={SQL Server};SERVER=seattle1;UID=sa;PWD=MyPass''
use pubs
go
--------------------------
--创建要从中查询的存储过程
create proc SelectAuthors
@au_lname varchar(20)
,@au_fname varchar(30)
as
select * from authors where au_lname=@au_lname or au_fname=@au_fname
go
--创建通用存储过程,用于执行返回的记录集
create proc GetProcTable
@DataBaseName varchar(100)
,@ProcName varchar(100)
,@para varchar(200)
as
declare @sql varchar(8000)
set @para=replace(@para,'''','''''')
set @sql='select * from openrowset(''MSDASQL'',''DRIVER={SQL Server};SERVER=.;Integrated Security=SSPI'',''exec ' + @DataBaseName +'.dbo.'+ @ProcName +' '+ @para + ''') as a'
print @sql
exec (@sql)
go
--执行
GetProcTable 'pubs','selectauthors','''White'',''Cheryl'''