关于动态执行SQL的问题
我想写一个存储过程,通过输入数据库名,数据库管理员名,然后判断两个表之间的增量.假设C_TERMID为主键.存储过程如下:
ALTER PROCEDURE [dbo].[up_increment_extract]
-- Add the parameters for the stored procedure here
@databasename varchar(50),
@databaseAdministrator varchar(50),
@message char(1) output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
EXEC( 'SELECT * INTO TML_INFO FROM '+@databasename+ '. '+@databaseAdministrator+ '. '+ 'TML_INFO '+ 'where C_TERMID in (select C_TERMID from TML_INFO where C_TERMID not in (select c_termid from '+@databasename+ '. ' +@databaseAdministrator+ '. ' + 'TML_INFO)) ');
SET @message=0;
但运行提示in附近有语法错误,不知错在何处,请高手过来解决,谢谢!
------解决方案--------------------where 前加一空格
------解决方案--------------------begin去掉
------解决方案--------------------1楼和2楼正解