{"id":217649,"date":"2014-03-31T11:09:03","date_gmt":"2014-03-31T07:09:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=217649"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=217649","title":{"rendered":"<span class=\"post_title\">\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043c\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0420\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0432 \u0432\u0438\u0434\u0435 \u0442\u0430\u0431\u043b\u0438\u0446 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c\u0438 \u0432 SQL. \u041d\u0435 \u0431\u0435\u0440\u0443\u0441\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0442\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u0430\u043c\u044b\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435. \u042d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0442\u043e, \u0447\u0442\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0432 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435. \u0412\u0441\u0451 \u044d\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434 Microsoft SQL Server 2008 R2, \u043d\u043e, \u0434\u0443\u043c\u0430\u044e, \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438 \u043f\u043e\u0434 2005. <br \/>  \u0422\u0435\u043c, \u043a\u0442\u043e \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u0442\u0435\u043c\u043e\u0439 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0440\u043e\u043b\u0438\u0441\u0442\u0430\u0442\u044c \u043f\u043e\u0441\u0442 \u0434\u043e \u043f\u044f\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u0443\u0441\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439:  <\/p>\n<pre><code class=\"sql\">create procedure Proc1 as begin \tselect 1 p1, 'b' p2 end <\/code><\/pre>\n<p>  <\/p>\n<h4>1 \u041c\u0435\u0442\u043e\u0434<\/h4>\n<p>  \u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 (\u043c\u043e\u0435\u0439) \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>insert ... exec ...<\/code>  <\/p>\n<pre><code class=\"sql\">if object_id(N'tempdb..#t1',N'U') is not null drop table #t1 create table #t1(p1 int, p2 varchar(max)) insert #t1(p1, p2) exec Proc1 select * from #t1 <\/code><\/pre>\n<p>  <\/p>\n<h5>\u041f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b:<\/h5>\n<p>  <\/p>\n<ul>\n<li>\u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u043f\u043e\u043b\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f 3 \u0440\u0430\u0437\u0430 (\u044d\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 <code>select<\/code>, \u0432\u043d\u0435\u0448\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 <code>insert<\/code>). \u0418 \u0435\u0449\u0435 \u043f\u043e \u0434\u0432\u0430 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u043d\u043e\u0432\u043e\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435. (\u042f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439, \u0442.\u043a. \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0430\u0432\u043e\u043a \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u043c\u0435\u0441\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b, \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u0442\u0440\u0443\u0434\u043e\u0435\u043c\u043a\u0438\u043c)<\/li>\n<li>\u0418\u043c\u0435\u0435\u0442 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u2013 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443<\/li>\n<li>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c <code>exec Proc1<\/code> \u0431\u0435\u0437 <code>insert<\/code><\/li>\n<\/ul>\n<h4>2 \u041c\u0435\u0442\u043e\u0434<\/h4>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0417\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c insert \u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443:  <\/p>\n<pre><code class=\"sql\">create procedure Proc1 as begin \tinsert #t1(p1, p2)  \tselect 1 p1, 'b' p2 end <\/code><\/pre>\n<p>  \u041f\u043e \u0441\u0443\u0442\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0443 insert \u0432\u043d\u0443\u0442\u0440\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b.  <\/p>\n<pre><code class=\"sql\">if object_id(N'tempdb..#t1',N'U') is not null drop table #t1 create table #t1(p1 int, p2 varchar(max)) exec Proc1 select * from #t1 <\/code><\/pre>\n<p>  <\/p>\n<h5>\u041f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b:<\/h5>\n<p>  <\/p>\n<ul>\n<li>\u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u043f\u043e\u043b\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f 2-3 \u0440\u0430\u0437\u0430, \u0438 \u0435\u0449\u0435 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u043d\u043e\u0432\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/li>\n<li>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043b\u0438\u0431\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443, \u0432\u044b\u0432\u043e\u0434\u044f\u0449\u0443\u044e \u043f\u0440\u0438\u043d\u044f\u0442\u044b\u0435 \u043e\u0442 <code>Proc1<\/code> \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043b\u0438\u0431\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0438\u0445 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 <code>Proc1<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0443 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438:<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"sql\">alter procedure Proc1 as begin \tdeclare @show bit \tif object_id(N'tempdb..#t1',N'U') is null  \tbegin \t\tset @show = 1 \t\tcreate table #t1(p1 int, p2 varchar(max)) \tend  \tinsert #t1(p1, p2)  \tselect 1 p1, 'b' p2 \t \tif (@show = 1) \tbegin \t\tselect * from #t1 \tend end <\/code><\/pre>\n<p>  \u042f \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0442.\u043a. \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c\u0441\u044f \u043a \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u0442, \u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0441\u0441\u0438\u044f\u043c\u0438.<\/p>\n<h4>3 \u041c\u0435\u0442\u043e\u0434<\/h4>\n<p>  \u041f\u043e \u0441\u0443\u0442\u0438, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430. \u0427\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u0432 \u0445\u0440\u0430\u043d\u0438\u043c\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"sql\">create procedure Proc1 as begin \tinsert #t1(p1, p2)  \tselect 1 p1, 'b' p2 end go create procedure Proc1_AlterTable as begin \talter table #t1 add p1 int, p2 varchar(max) \talter table #t1 drop column delmy end go -- \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c: if object_id(N'tempdb..#t1',N'U') is not null drop table #t1 create table #t1(delmy int) exec Proc1_AlterTable exec Proc1 select * from #t1 <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0430 delmy \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0451 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u043c (\u0437\u0434\u0435\u0441\u044c \u0441 p1).<\/p>\n<h5>\u041f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b:<\/h5>\n<p>  <\/p>\n<ul>\n<li>\u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u043f\u043e\u043b\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f 2-3 \u0440\u0430\u0437\u0430, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u043e\u0435 \u043d\u043e\u0432\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/li>\n<li>\u0414\u043b\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/li>\n<li>\u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0438\u043d\u043e\u0433\u0434\u0430, \u043f\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>alter table #t1<\/code>, \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f <code>Proc1<\/code> (\u043d\u0435 <code>Proc1_AlterTable<\/code>!) \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0415\u0441\u043b\u0438 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0437\u043d\u0430\u0435\u0442, \u0441 \u0447\u0435\u043c \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e \u2014 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c:)<\/li>\n<\/ul>\n<h4>4 \u041c\u0435\u0442\u043e\u0434<\/h4>\n<p>  \u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e, \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0440\u0430\u0437\u0443 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.  <\/p>\n<pre><code class=\"sql\">create procedure Proc1 as begin \tinsert #t1(p1, p2)  \tselect 1 p1, 'b' p2 end go create function Proc1_AlterTable() returns table as return ( \tselect cast(null as int) p1, cast(null as varchar(max)) p2 \twhere 1=2 ) go -- \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c: if object_id(N'tempdb..#t1',N'U') is not null drop table #t1 select *  into #t1 from Proc1_AlterTable() exec Proc1 select * from #t1 <\/code><\/pre>\n<p>  <\/p>\n<h5>\u041f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b:<\/h5>\n<p>  <\/p>\n<ul>\n<li>\u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u043f\u043e\u043b\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f 2-3 \u0440\u0430\u0437\u0430, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u043e\u0435 \u043d\u043e\u0432\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/li>\n<li>\u0414\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/li>\n<li>\u0415\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439, \u0442.\u043a. \u0438\u0445 \u043c\u044b \u0443\u0436\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 <code>Proc1_AlterTable<\/code><\/li>\n<\/ul>\n<h4>5 \u041c\u0435\u0442\u043e\u0434<\/h4>\n<p>  \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b. \u041e\u043d \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443. \u041e\u0434\u043d\u0430\u043a\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438.<\/p>\n<p>  \u0414\u043b\u044f \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  1. \u0412 \u043d\u0430\u0447\u0430\u043b\u043e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438:  <\/p>\n<pre><code class=\"sql\">if object_id('tempdb..#ttInclusion', 'U') is null create table #ttInclusion(lvl int, i int) exec util.InclusionBegin <\/code><\/pre>\n<p>  2. \u0412\u0441\u0435 \u0432\u044b\u0432\u043e\u0434\u044f\u0449\u0438\u0435 select&#8217;\u044b \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0441 <code>#Output<\/code> (\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>into #Output<\/code>, <code>into #Output5<\/code>, <code>into #OutputMySelect<\/code>). \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430, \u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f<br \/>  3. \u0412 \u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443:  <\/p>\n<pre><code class=\"sql\">exec util.InclusionEnd --\u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 #Output, \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 util.InclusionBegin <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:  <\/p>\n<pre><code class=\"sql\">create procedure Proc1 as begin \tif object_id('tempdb..#ttInclusion', 'U') is null create table #ttInclusion(lvl int, i int) \texec util.InclusionBegin  \t\tselect 1 p1, 'b' p2 \tinto #Output1  \texec util.InclusionEnd --\u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 #Output, \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 util.InclusionBegin end <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"sql\">if object_id('tempdb..#ttInclusionParameters', 'U') is null create table #ttInclusionParameters(lvl int, pr int, val varchar(max)) exec util.InclusionRun'  select * from #InclusionOutput1  ', 1, '#InclusionOutput' exec Proc1 <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 SQL \u044d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0440\u043e\u0448\u043e, \u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439. \u0415\u0441\u043b\u0438 \u043a\u043e\u0434\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043b\u0438\u0431\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0435\u0433\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0438 \u0438\u0437 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e exec \u0432\u044b\u0437\u043e\u0432, \u043b\u0438\u0431\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043d\u043e\u0432\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0435\u0449\u0451 \u043e\u0434\u043d\u043e \u00ab\u043b\u0438\u0448\u043d\u0435\u0435\u00bb \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432 \u043a\u0430\u043a\u043e\u043c-\u043b\u0438\u0431\u043e \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435).<\/p>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u0438 <code>util.InclusionRun<\/code> \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f 3 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430:  <\/p>\n<ul>\n<li><code>@sql<\/code> \u2013 SQL-\u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b<\/li>\n<li><code>@notShowOutput<\/code> \u2013 \u0435\u0441\u043b\u0438 = 1, \u0442\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0442\u0430\u0431\u043b\u0438\u0446, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0441 <code>#Output<\/code><\/li>\n<li><code>@replaceableTableName<\/code> \u2013 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e = <code>'#Output'<\/code>) \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0432 \u0438\u043c\u0435\u043d\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432 <code>@sql<\/code>, \u0434\u043b\u044f \u0437\u0430\u043c\u0435\u043d\u044b \u0435\u0433\u043e \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e <code>#Output*<\/code> \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0442\u044c <code>#InclusionOutput<\/code>, \u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0434\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>#Output55<\/code> \u0438 <code>#Output0A<\/code>, \u0442\u043e \u0432 <code>@sql<\/code> \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a <code>#Output55<\/code> \u043a\u0430\u043a \u043a <code>#InclusionOutput1<\/code>, \u0430 \u043a <code>#Output0A<\/code> \u043a\u0430\u043a \u043a <code>#InclusionOutput2<\/code><\/li>\n<\/ul>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a <code>Proc1<\/code>, \u0431\u0435\u0437 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 <code>util.InclusionRun<\/code> \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0432\u0441\u0435\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u043b\u0430 \u0434\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<h5>\u041d\u044e\u0430\u043d\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/h5>\n<p>  <\/p>\n<ul>\n<li>\u041d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>return<\/code> \u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0435, \u0442.\u043a. \u043f\u0435\u0440\u0435\u0434 \u043d\u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0437\u0430\u043f\u0443\u0441\u043a <code>util.InclusionEnd<\/code><\/li>\n<li>\u0412\u044b\u0432\u043e\u0434\u044f\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 select&#8217;\u044b \u0438\u0437 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u0432\u044b\u0432\u043e\u0434\u044f\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0434\u0430\u0436\u0435 \u0442\u0435 #Output-\u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0434\u043e \u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u0430 (\u044d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0442.\u043a. \u0432\u044b\u0432\u043e\u0434 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 <code>util.InclusionEnd<\/code>)<\/li>\n<\/ul>\n<h5>\u041f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b:<\/h5>\n<p>  <\/p>\n<ul>\n<li>\u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u043f\u043e\u043b\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u043e\u0435 \u043d\u043e\u0432\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/li>\n<li>\u0414\u043b\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439<\/li>\n<li>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0438 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u044e\u0430\u043d\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/li>\n<li>\u0418\u0437-\u0437\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u0438 \u0447\u0430\u0441\u0442\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445 (\u044f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0440\u0435\u0436\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0430 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u044d\u0442\u0438\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043d\u0435\u0431\u0440\u0435\u0447\u044c)<\/li>\n<li>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0445 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c: \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0430\u0435\u0442 \u0434\u0432\u0430 exec-\u0432\u044b\u0437\u043e\u0432\u0430 \u0438 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432\u0441\u0435 <code>#Output<\/code>-\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u044b<\/li>\n<li>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0435\u0437 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/li>\n<\/ul>\n<h5>\u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/h5>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/b><\/p>\n<div class=\"spoiler_text\">\u041a\u043e\u0434:  <\/p>\n<pre><code class=\"sql\">if object_id('dbo.TestInclusion') is not null drop procedure dbo.TestInclusion go create procedure dbo.TestInclusion          @i int as begin         if object_id('tempdb..#ttInclusion', 'U') is null create table #ttInclusion(lvl int, i int)         exec util.InclusionBegin           if object_id('tempdb..#tmp2', 'U') is not null drop table #tmp2          select @i myI         into #tmp2                  if object_id('tempdb..#tmp3', 'U') is not null drop table #tmp3         select @i + 1 myI         into #tmp3          select *         into #Output0 --\u041d\u0430 \u0432\u044b\u0432\u043e\u0434 (\u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432 util.InclusionEnd)         from #tmp2         union all         select *         from #tmp3          select '\u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 TestInclusion' alt         into #OutputQwerty --\u041d\u0430 \u0432\u044b\u0432\u043e\u0434 (\u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432 util.InclusionEnd)                  exec util.InclusionEnd --\u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 #Output \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 util.InclusionBegin  end go set nocount on set ansi_warnings off if object_id('tempdb..#ttInclusionParameters', 'U') is not null drop table #ttInclusionParameters go select '\u0422\u0435\u0441\u0442 1: \u0437\u0430\u043f\u0443\u0441\u043a TestInclusion. \u041d\u0438\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u043e\u0439 myI \u0438 \u0434\u0432\u0443\u043c\u044f \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438: 2 \u0438 3. \u0418 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 1 \u0441\u0442\u0440\u043e\u043a\u043e\u0439: &quot;\u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 TestInclusion&quot;' exec dbo.TestInclusion 2 go select '\u0422\u0435\u0441\u0442 2: \u0442\u0435\u0441\u0442 TestInclusion. \u041d\u0438\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u043e\u0439 testSum \u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439: 5' if object_id('tempdb..#ttInclusionParameters', 'U') is null create table #ttInclusionParameters(lvl int, pr int, val varchar(max)) exec util.InclusionRun '          select sum(myI) testSum         from #InclusionOutput1          ', 1, '#InclusionOutput' exec dbo.TestInclusion 2 <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:  <\/p>\n<pre><code class=\"bash\">----------------------------------------------------------------------------------------------------------------------------------------------------------- \u0422\u0435\u0441\u0442 1: \u0437\u0430\u043f\u0443\u0441\u043a TestInclusion. \u041d\u0438\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u043e\u0439 myI \u0438 \u0434\u0432\u0443\u043c\u044f \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438: 2 \u0438 3. \u0418 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 1 \u0441\u0442\u0440\u043e\u043a\u043e\u0439: &quot;\u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 TestInclusion&quot;  myI ----------- 2 3  alt ----------------------- \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 TestInclusion   ------------------------------------------------------------------------------------------------------ \u0422\u0435\u0441\u0442 2: \u0442\u0435\u0441\u0442 TestInclusion. \u041d\u0438\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u043e\u0439 testSum \u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439: 5  testSum ----------- 5 <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>\u0421\u0430\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/h5>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">if not exists(select top 1 null from sys.schemas where name = 'util') begin \texec ('create schema util') end go alter procedure util.InclusionBegin as begin \/* \t\u0418\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f: \t1. \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \t1.1. \u0412 \u043d\u0430\u0447\u0430\u043b\u043e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438: if object_id('tempdb..#ttInclusion', 'U') is null create table #ttInclusion(lvl int, i int) exec util.InclusionBegin  \t1.1. \u0412\u0441\u0435 \u0432\u044b\u0432\u043e\u0434\u044f\u0449\u0438\u0435 select'\u044b \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0441 #Output (\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 into #Output, into #Output5, into #OutputMySelect) \t1.2. \u0412 \u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443: exec util.InclusionEnd --\u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 #Output, \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 util.InclusionBegin \t2. \u0412 \u043c\u0435\u0441\u0442\u0435, \u0433\u0434\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430, \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043e \u0435\u0451 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 (\u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u0435 #Output* \u0442\u0430\u0431\u043b\u0438\u0446\u044b): if object_id('tempdb..#ttInclusionParameters', 'U') is null create table #ttInclusionParameters(lvl int, pr int) exec util.InclusionRun('&lt;sql \u0441\u043a\u0440\u0438\u043f\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043f\u0435\u0440\u0435\u0434 \u0435\u0451 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435\u043c&gt;') \t\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043c. \u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 util.InclusionRun *\/ \tset nocount on \tset ansi_warnings off \tdeclare @lvl int \t \tif object_id('tempdb..#ttInclusionParameters', 'U') is not null \tbegin \t\tselect @lvl = max(lvl) \t\tfrom #ttInclusionParameters \t\t \t\t--\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c null \u0437\u0430\u0434\u0430\u043d\u0438\u0435, \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430\u0445 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c \t\tif (@lvl is not null) \t\tbegin \t\t\tinsert #ttInclusionParameters(lvl, pr) \t\t\tselect @lvl+1 lvl, null pr \t\tend \tend  \tif object_id('tempdb..#ttInclusion', 'U') is not null \tbegin \t\t--\u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0432\u0441\u0435 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b #Output, \u0447\u0442\u043e\u0431\u044b \u0432 util.InclusionEnd \u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u0445 \t\tinsert #ttInclusion(lvl, i) \t\tselect isnull(@lvl, 0), so.object_id i \t\tfrom tempdb.sys.objects so \t\twhere so.type = 'U' \t\t\tand so.name like '#[^#]%' \t\t\tand object_id('tempdb..' + so.name, 'U') is not null \t\t\tand not exists (select top 1 null from #ttInclusion where i = so.object_id) \tend \t end GO  go alter procedure util.InclusionEnd as begin \/* \t\u0418\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f: \t1. \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \t1.1. \u0412 \u043d\u0430\u0447\u0430\u043b\u043e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438: if object_id('tempdb..#ttInclusion', 'U') is null create table #ttInclusion(lvl int, i int) exec util.InclusionBegin  \t1.1. \u0412\u0441\u0435 \u0432\u044b\u0432\u043e\u0434\u044f\u0449\u0438\u0435 select'\u044b \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0441 #Output (\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 into #Output, into #Output5, into #OutputMySelect) \t1.2. \u0412 \u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443: exec util.InclusionEnd --\u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 #Output, \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 util.InclusionBegin \t2. \u0412 \u043c\u0435\u0441\u0442\u0435, \u0433\u0434\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430, \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043e \u0435\u0451 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 (\u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u0435 #Output* \u0442\u0430\u0431\u043b\u0438\u0446\u044b): if object_id('tempdb..#ttInclusionParameters', 'U') is null create table #ttInclusionParameters(lvl int, pr int) exec util.InclusionRun('&lt;sql \u0441\u043a\u0440\u0438\u043f\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043f\u0435\u0440\u0435\u0434 \u0435\u0451 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435\u043c&gt;') \t\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043c. \u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 util.InclusionRun *\/ \tset nocount on \tset ansi_warnings off \t---------------------------------------------------------------------------------------------------- \t--\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \tdeclare @lvl int \t\t, @p0 varchar(max) --(@sql) sql \u0441\u043a\u0440\u0438\u043f\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \t\t, @p1 varchar(max) --(@notShowOutput) \u0435\u0441\u043b\u0438 \u0440\u0430\u0432\u043d\u043e '1' \u0445\u043e\u0442\u044f \u0431\u044b \u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u0434\u0430\u043d\u0438\u0439, \u0442\u043e \u041d\u0415 \u0432\u044b\u0432\u043e\u0434\u0438\u043c #Output, \u0438\u043d\u0430\u0447\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u043c \u0438\u0445 \t\t, @p2 varchar(max) --(@replaceableTableName) \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u043f\u0440\u0435\u0444\u0435\u043a\u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \t \tif object_id('tempdb..#ttInclusionParameters', 'U') is not null \tbegin \t\t--\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \t\tselect\t@p1 = max(val) \t\tfrom #ttInclusionParameters \t\twhere pr = 1 \t\t \t\t--\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0448\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0435 (max(lvl) - \u044d\u0442\u043e \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441 null \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 util.InclusionBegin) \t\tselect @lvl = max(lvl) - 1 \t\tfrom #ttInclusionParameters \t\t \t\tif @lvl is not null \t\tbegin \t\t\t--\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \t\t\tselect\t@p0 = max(case when pr = 0 then val end) \t\t\t\t,\t@p2 = max(case when pr = 2 then val end) \t\t\tfrom #ttInclusionParameters \t\t\twhere lvl = @lvl  \t\t\thaving max(pr) is not null \t\t\t \t\t\t--\u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u043a\u0440\u0438\u043f\u0442, \u0430 \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442, \u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e null-\u0437\u0430\u0434\u0430\u043d\u0438\u0435  \t\t\tdelete #ttInclusionParameters \t\t\twhere lvl &gt;= @lvl and (lvl &gt; @lvl or @p0 is not null) \t\tend \tend \t \t---------------------------------------------------------------------------------------------------- \t--\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b #Output \tif object_id('tempdb..#InclusionOutputs', 'U') is not null drop table #InclusionOutputs \tcreate table #InclusionOutputs(i int, tableName varchar(max), num int) \t \tif object_id('tempdb..#ttInclusion', 'U') is not null \tbegin \t\tinsert #InclusionOutputs(i, tableName, num) \t\tselect so.object_id i, left(so.name, charindex('_', so.name)-1) tableName, row_number() over (order by so.create_date) num \t\tfrom tempdb.sys.objects so \t\twhere so.type = 'U' \t\t\tand so.name like '#[^#]%' \t\t\tand object_id('tempdb..' + so.name, 'U') is not null \t\t\tand so.name like '#Output%' \t\t\tand not exists (select top 1 null from #ttInclusion where i = so.object_id and lvl &lt;= isnull(@lvl, lvl)) \t\t \t\t--\u043e\u0447\u0438\u0449\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u043e\u043c\u0443 \u0443\u0440\u043e\u0432\u043d\u044e \t\tdelete #ttInclusion  \t\twhere lvl &lt;= @lvl \tend \telse \tbegin \t\tinsert #InclusionOutputs(i, tableName, num) \t\tselect so.object_id i, left(so.name, charindex('_', so.name)-1) tableName, row_number() over (order by so.create_date) num \t\tfrom tempdb.sys.objects so \t\twhere so.type = 'U' \t\t\tand so.name like '#[^#]%' \t\t\tand object_id('tempdb..' + so.name, 'U') is not null \t\t\tand so.name like '#Output%' \tend \t \t---------------------------------------------------------------------------------------------------- \t--\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0439 (\u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435 \u0431\u044b\u043b\u043e - \u0432\u044b\u0432\u043e\u0434 \u0432\u0441\u0435\u0445 #Output) \tdeclare @srcsql varchar(max) \t \t--\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0432 util.InclusionRun \tif (@p0 is not null and @p0 &lt;&gt; '') \tbegin \t\t--\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u044b @replaceableTableName \t\tif (@p2 is not null and @p2 &lt;&gt; '') \t\tbegin \t\t\tselect @p0 = replace(@p0, @p2 + cast(num as varchar(10)), replace(tableName, '#', '#&lt;tokenAfterReplace&gt;')) \t\t\tfrom #InclusionOutputs \t\t\torder by num desc \t\t\t \t\t\tselect @p0 = replace(@p0, '&lt;tokenAfterReplace&gt;', '') \t\tend \t\t \t\t--\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0441\u043a\u0440\u0438\u043f\u0442 \t\tselect @srcsql = isnull(@srcsql + ' ' + char(13), '') \t\t\t+ @p0 + ' ' + char(13) \tend \t \t--\u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 #Output \u0442\u0430\u0431\u043b\u0438\u0446\u044b \tif (@p1 is null or @p1 &lt;&gt; '1') --\u0435\u0441\u043b\u0438 \u0440\u0430\u0432\u043d\u043e 1, \u0442\u043e \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c! \tbegin \t\t--\u043e\u0442\u0441\u0442\u0443\u043f \u043e\u0442 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \t\tselect @srcsql = isnull(@srcsql + ' ' + char(13), '')  \t\t--\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0441\u043a\u0440\u0438\u043f\u0442 \t\tselect @srcsql = isnull(@srcsql + ' ', '') + \t\t\t'select * from ' + tableName \t\tfrom #InclusionOutputs \t\torder by num asc \tend \t \tif (@srcsql is not null) \tbegin \t\texec (@srcsql) \tend \t end go alter procedure util.InclusionRun  \t@sql varchar(max), --sql \u0441\u043a\u0440\u0438\u043f\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b (\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 util.InclusionEnd) \t@notShowOutput bit, --\u0435\u0441\u043b\u0438 = 1, \u0442\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0441 #Output \t@replaceableTableName varchar(100) = '#Output' -- \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0432 \u0438\u043c\u0435\u043d\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432 @sql, \u0434\u043b\u044f \u0437\u0430\u043c\u0435\u043d\u044b \u0435\u0433\u043e \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e #Output* \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435.  \t\t-- \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0442\u044c #InclusionOutput, \u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0434\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b #Output55 \u0438 #Output0A,  \t\t-- \u0442\u043e \u0432 @sql \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a #Output55 \u043a\u0430\u043a \u043a #InclusionOutput1, \u0430 \u043a #Output0A \u043a\u0430\u043a \u043a #InclusionOutput2\t as begin \tset nocount on \tset ansi_warnings off  \tif object_id('tempdb..#ttInclusionParameters', 'U') is null  \tbegin \t\tprint '\u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 util.InclusionRun \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430, \u0442.\u043a. \u0434\u043b\u044f \u043d\u0435\u0451 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 #ttInclusionParameters!  ' \t\treturn \tend \t \tdeclare @lvl int \tselect @lvl = isnull(max(lvl), 0) + 1 \tfrom #ttInclusionParameters \t \tinsert #ttInclusionParameters(lvl, pr, val) \tselect @lvl, 0, @sql \tunion all \tselect @lvl, 1, '1'\twhere @notShowOutput = 1 \tunion all \tselect @lvl, 2, @replaceableTableName \t end  <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4>\u0414\u0440\u0443\u0433\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b<\/h4>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (<code>OUTPUT<\/code>) \u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043a\u0443\u0440\u0441\u043e\u0440 \u0438\u043b\u0438 XML.<br \/>  \u041d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 <a href=\"http:\/\/technet.microsoft.com\/ru-ru\/library\/ms188655.aspx\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a>.<br \/>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0443\u0440\u0441\u043e\u0440 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u044f \u043d\u0435 \u0432\u0438\u0436\u0443 \u0441\u043c\u044b\u0441\u043b\u0430, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u0443\u0440\u0441\u043e\u0440. \u0410 \u0432\u043e\u0442 XML \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c. <a href=\"http:\/\/habrahabr.ru\/post\/96145\/\">\u0417\u0434\u0435\u0441\u044c<\/a> \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<br \/>  \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/217649\/\"> http:\/\/habrahabr.ru\/post\/217649\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0420\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0432 \u0432\u0438\u0434\u0435 \u0442\u0430\u0431\u043b\u0438\u0446 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c\u0438 \u0432 SQL. \u041d\u0435 \u0431\u0435\u0440\u0443\u0441\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0442\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u0430\u043c\u044b\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435. \u042d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0442\u043e, \u0447\u0442\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0432 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435. \u0412\u0441\u0451 \u044d\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434 Microsoft SQL Server 2008 R2, \u043d\u043e, \u0434\u0443\u043c\u0430\u044e, \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438 \u043f\u043e\u0434 2005. <br \/>  \u0422\u0435\u043c, \u043a\u0442\u043e \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u0442\u0435\u043c\u043e\u0439 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0440\u043e\u043b\u0438\u0441\u0442\u0430\u0442\u044c \u043f\u043e\u0441\u0442 \u0434\u043e \u043f\u044f\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-217649","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217649","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=217649"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217649\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}