if (exists (select * from sys.objects where name = 'up_test')) drop proc up_test
go
Create PROC [dbo].[up_test]
as
declare @SQL nvarchar(max), @SQL1 nvarchar(4000), @SQL2 nvarchar(4000), @SQL3 nvarchar(4000),
@SQL4 nvarchar(4000);
set @SQL1 = N'SQl语句1' ; -- 长度不能超过4000;
set @SQL2 ='SQL语句2'; -- 长度不能超过4000;
set @SQL3 ='SQL语句3'; -- 长度不能超过4000;
set @SQL4 ='SQL语句4'; -- 长度不能超过4000;
set @SQL = concat(@SQL1, @SQL2, @SQL3, @SQL4);
exec SP_EXECUTESQL @SQL;
--print len(@sql);
--print @SQL;
--print @sql1;
--print @sql2;
--print @sql3;
--print @sql4;
GO
关于SP_EXECUTESQL 更详尽用法 参见
https://www.cnblogs.com/lonelyxmas/p/7975445.html