当前位置: 代码迷 >> SQL >> SQL SERVER 动态、跨库话语
  详细解决方案

SQL SERVER 动态、跨库话语

热度:81   发布时间:2016-05-05 14:35:30.0
SQL SERVER 动态、跨库语句

execute sp_executesql
????????? N'select * from pubs.dbo.employee where job_lvl = @level',
????????? [email protected] tinyint',
????????? @level = 35

GO

?

declare @num_a int,???
????????? @num_b int,?????
????????? @sqls nvarchar(4000)


set @sqls='select @a=count(*),@b=count(*) from t_user '

exec sp_executesql @sqls,[email protected] int output,@b int output',@num_a output,@num_b output
select @num_a,@num_b

?

GO

?

-------------------------------------

?

EXEC sp_addlinkedserver 'OracleSvr',
?? 'Oracle 7.3',
?? 'MSDAORA',
?? 'ORCLDB'
GO


SELECT *
FROM OPENQUERY(OracleSvr, 'SELECT name, id FROM joe.titles')
GO

?

-------------------------------------

?

USE pubs
GO
SELECT a.*
FROM OPENROWSET('SQLOLEDB','seattle1';'sa';'MyPass',
?? 'SELECT * FROM pubs.dbo.authors ORDER BY au_lname, au_fname') AS a
GO

?

USE pubs
GO
SELECT a.*
FROM OPENROWSET('MSDASQL',
?? 'DRIVER={SQL Server};SERVER=seattle1;UID=sa;PWD=MyPass',
?? pubs.dbo.authors) AS a
ORDER BY a.au_lname, a.au_fname
GO

?

?

  相关解决方案