{"id":275803,"date":"2016-03-10T02:21:02","date_gmt":"2016-03-09T23:21:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=275803"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=275803","title":{"rendered":"\u0414\u0432\u0438\u0436\u043e\u043a \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043e\u0442\u0447\u0451\u0442\u043e\u0432 \u043d\u0430 SQL. \u0427\u0435\u0440\u043d\u043e\u0432\u0438\u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044f"},"content":{"rendered":"<br \/>\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 ( <a href=\"https:\/\/habrahabr.ru\/post\/278595\/\">\u0414\u0432\u0438\u0436\u043e\u043a \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043e\u0442\u0447\u0451\u0442\u043e\u0432 \u043d\u0430 SQL. \u0418\u0434\u0435\u044f<\/a> ) \u044f \u043f\u043e\u0434\u0435\u043b\u0438\u043b\u0441\u044f \u0438\u0434\u0435\u0435\u0439. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0435\u043b\u044e\u0441\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c ( \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a\u043e\u043c ). \u042d\u0442\u043e\u0442 \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a \u2014 \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 \u00ab\u0441\u0435\u0440\u044c\u0435\u0437\u043d\u043e\u0439\u00bb \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <b>T-SQL<\/b>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0435\u0433\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u0430 \u043e\u0431\u0440\u0430\u0437\u0435\u0446 \u00ab\u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e\u00bb \u043a\u043e\u0434\u0430.<br \/>  \u0421\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e\u0435 \u0432 \u044d\u0442\u043e\u043c \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a\u0435 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u0443\u043b \u0432 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u0412\u0442\u043e\u0440\u043e\u0435 \u043f\u043e \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u041a\u043e\u0433\u0434\u0430 \u044f \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u043b \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u2014 \u044f \u043e\u0436\u0438\u0434\u0430\u043b \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0435\u0439, \u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0441\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e. \u041c\u043d\u043e\u0433\u043e \u043f\u0438\u0441\u0430\u043d\u0438\u043d\u044b \u0438 \u0432\u0441\u0435\u0433\u043e \u043f\u0430\u0440\u0430 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0438 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c. \u041f\u0435\u0440\u0432\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044d\u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u043e\u043c\u0435\u0440\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0432\u044b\u0434\u0430\u0447\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0412\u0442\u043e\u0440\u043e\u0439 \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f. <br \/>  \u0413\u043b\u0430\u0437\u0430 \u0431\u043e\u044f\u0442\u044c\u0441\u044f \u2014 \u0440\u0443\u043a\u0438 \u0434\u0435\u043b\u0430\u044e\u0442!<br \/>  \u042f \u043d\u0430\u0447\u043d\u0443 \u0441\u0440\u0430\u0437\u0443 \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e, \u0434\u043b\u044f \u0442\u0435\u0445 \u043a\u043e\u043c\u0443 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043b\u043e \u2014 \u043d\u0438\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u043a\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440 \u043b\u043e\u0433\u0438\u043a\u0438. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c.<\/p>\n<h4>\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u0443\u043b<\/h4>\n<h5>\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u041a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438 \u0438 \u0420\u0430\u0437\u0434\u0435\u043b\u0430\u043c\u0438<\/h5>\n<p>  \u0415\u0441\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 ( \u0448\u0430\u043f\u043a\u0438 \u0438\u043b\u0438 \u043f\u043e\u0434\u0432\u0430\u043b\u0430 ). \u042d\u0442\u0430 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0430 \u0440\u0430\u0437\u0434\u0435\u043b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a \u0440\u0430\u0437\u043e\u043c.<br \/>  \u0424\u043e\u0440\u043c\u0443\u043b\u044b \u0434\u043b\u044f \u0448\u0430\u043f\u043a\u0438 \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u043d\u0430\u0434\u043e \u00ab\u0432\u043a\u043b\u0435\u0438\u0442\u044c\u00bb \u0432 \u00ab\u043f\u043e\u0441\u0430\u0434\u043e\u0447\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e\u00bb \u0448\u0430\u0431\u043b\u043e\u043d\u0430.<br \/>  \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u043d\u0430\u0434\u043e \u00ab\u0437\u0430\u0431\u0438\u043d\u0434\u0438\u0442\u044c\u00bb ( \u0441\u0432\u044f\u0437\u0430\u0442\u044c ) \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044d\u0442\u0430 \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u0431\u044b\u043b\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0430.<br \/>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0438 \u0448\u0430\u043f\u043a\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b \u0440\u0430\u0437\u043d\u044b\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u044b.<\/p>\n<h5>\u0428\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u0420\u0430\u0437\u0434\u0435\u043b\u0430<\/h5>\n<p>  <\/p>\n<pre><code class=\"sql\">SET @sql_text =  N' SELECT  @result = ' + @formula  + N' FROM table ' <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e:  <\/p>\n<ul>\n<li>\u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043b\u0438 \u0444\u043e\u0440\u043c\u0443\u043b\u0443;<\/li>\n<li>\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d;<\/li>\n<li>\u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 ( <b>report_region_instances<\/b> );<\/li>\n<li>\u043a\u043e\u043d\u0435\u0446 \u2014 \u0448\u0430\u043f\u043a\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0430;<\/li>\n<\/ul>\n<h5>\u0428\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u041a\u043e\u043b\u043e\u043d\u043a\u0438<\/h5>\n<p>  \u0421 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438 \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0439. \u0415\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0448\u0430\u043f\u043a\u0438 \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0442\u043e \u0435\u0441\u0442\u044c \u044d\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0440\u043e\u043a.<br \/>  \u0427\u0442\u043e \u0431\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u043e\u0442\u0447\u0451\u0442\u0430 \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 ( \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <b>report_cell_instances<\/b> ), \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u0440\u043e\u043d\u0443\u043c\u0435\u0440\u043e\u0432\u0430\u0442\u044c.<br \/>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0435\u0434\u0438\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0442\u044c \u2014 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0444\u0440\u0430\u0437\u0443 &quot;<b>ORDER BY<\/b>&quot;, \u0432 &quot;<b>SELECT<\/b>&quot; \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c &quot; <b>ROW_NUMBER() OVER( ORDER BY )<\/b>&quot;.<br \/>  \u0428\u0430\u0431\u043b\u043e\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430:   <\/p>\n<pre><code class=\"sql\">SET @sql_text =  N' SELECT      ROW_NUMBER() OVER( ORDER BY key_column) ,'  + @formula   + N' FROM table ORDER BY key_column' <\/code><\/pre>\n<p>  \u041d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044d\u0442\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u2014 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043d\u0430\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<h4>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430.<\/h4>\n<p>  \u0421 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0430 ( \u0448\u0430\u043f\u043a\u0438 \u0438\u043b\u0438 \u043f\u043e\u0434\u0432\u0430\u043b\u0430 ) \u043d\u0435\u0442 \u043d\u0438 \u043a\u0430\u043a\u0438\u0445 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0435\u0439 \u2014 \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u044b\u0439 &quot;<b>INSERT<\/b>&quot; \u0447\u0435\u0433\u043e \u043d\u0430\u0434\u043e \u043a\u0443\u0434\u0430 \u043d\u0430\u0434\u043e ( \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <b>report_region_instances<\/b> ).<br \/>  \u0421 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0442\u043e\u0436\u0435 \u043d\u0438 \u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e, \u043d\u0430\u0434\u043e \u043d\u0430\u0448 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c &quot;<b>INSERT<\/b>&quot;.<br \/>  \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430. \u0415\u0441\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0430\u0432\u0442\u043e\u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043d\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 ( \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <b>IDENTITY<\/b> ), \u043d\u043e \u044f \u043b\u044e\u0431\u043b\u044e \u0438\u043c\u0435\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0437\u0430 \u0442\u0435\u043c \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043c\u043e\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u2014 &quot;<b>SEQUENCE<\/b>&quot; \u2014 \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e \u043a\u0430\u0436\u0434\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0432 \u0440\u0443\u0447\u043d\u0443\u044e.<br \/>  \u0428\u0430\u0431\u043b\u043e\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430:   <\/p>\n<pre><code class=\"sql\">SET @sql_text =  N' INSERT INTO report_cell_instances  ( id , row_order , value ) SELECT (NEXT VALUE FOR [dbo].[report_cell_instances_sequence] OVER( '  + @C_ORDER_BY  + N' ) ) AS Record_Id , ROW_NUMBER() OVER( '  + @C_ORDER_BY  + N' ) AS Row_Order , ' + @formula + N' AS Formula_Result FROM table' + @C_ORDER_BY <\/code><\/pre>\n<h4>\u0414\u043e\u0441\u043a\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h4>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u0432 \u0444\u043e\u0440\u043c\u0435 <b>T-SQL<\/b> \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0445\u0440\u0430\u043d\u0438\u043c\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430, \u0441\u043e\u0441\u0442\u0430\u0432 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e\u0434 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u2014 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0437\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u0430. \u0423 \u043c\u0435\u043d\u044f \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u044d\u0442\u043e:   <\/p>\n<ol>\n<li> \u043a\u043b\u0438\u0435\u043d\u0442 \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b consumer_reference<\/li>\n<li> \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0430\u043d\u0446\u0438\u0438 \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b meteo_stations_reference, <\/li>\n<li> \u043f\u0435\u0440\u0438\u043e\u0434 \u0434\u0430\u0442 \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0434\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0434\u0430\u0442\u044b \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b meteo_measurements \u0434\u043b\u044f \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u043d\u0446\u0438\u0438<\/li>\n<\/ol>\n<p>  \u0414\u0440\u0443\u0433\u0438\u0435 \u0432\u0435\u0449\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438 \u0441\u0434\u0435\u043b\u0430\u043d\u044b \u0432 \u0441\u0442\u0438\u043b\u0435 \u00abhard code\u00bb aka \u00abmagic number\u00bb, \u0441\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u044d\u0442\u043e \u0438\u0437\u0434\u0435\u0440\u0436\u043a\u0430\u043c\u0438 \u00ab\u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a\u0430\u00bb.<br \/>  \u041a\u043e\u0434 \u044f \u043f\u0438\u0441\u0430\u043b \u0432 <b>dbForge Studio<\/b>, \u0443 \u044d\u0442\u043e\u0433\u043e IDE \u0441\u0430\u043c\u044b\u0439 \u043b\u0443\u0447\u0448\u0438\u0439 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 ( \u044d\u0442\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u043b\u044e\u0441 \u044d\u0442\u043e\u0433\u043e IDE ), \u043d\u043e \u0443 \u043c\u0435\u043d\u044f \u043e\u043d \u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0432 \u0440\u0443\u0447\u043d\u0443\u044e, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0430\u043c \u0433\u0434\u0435 \u044f \u043f\u0440\u043e \u043d\u0435\u0433\u043e \u043f\u043e\u043c\u043d\u0438\u043b.<br \/>  \u041f\u043e \u043f\u0440\u0438\u0432\u044b\u0447\u043a\u0435 \u043a <b>C#<\/b> \u0438 <b>PL\/SQ<\/b>L \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u043a\u043e\u043c &quot;;&quot;.<br \/>  \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043a \u043a\u043e\u0434\u0443 ( \u0441\u043e\u0432\u0441\u0435\u043c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0435 \u0432\u0435\u0449\u0438 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f, \u0438\u0437\u0432\u0438\u043d\u0438\u0442\u0435 \u044f \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u043d\u0443\u0434\u0435\u043d ):  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0441\u043a\u0440\u0438\u043f\u0442 \u0441 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">BEGIN \/* \u0421\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u0440\u0438 \u043d\u0443\u043c\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a \u0438 \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0430 *\/   DECLARE @C_ORDER_BY NVARCHAR(MAX) = ' ORDER BY mm.meteo_station_id , mm.read_timestamp ' ; \/* \u0428\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 *\/   DECLARE @C_COLUMN_FORMULA_INSERT NVARCHAR(MAX) =  N' INSERT INTO report_cell_instances    (id    ,instance_id    ,consumer_id    ,column_id    ,row_order    ,value) '; \/* \u0428\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u044b, \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 report_cell_instances *\/   DECLARE @C_COLUMN_FORMULA_SELECT NVARCHAR(MAX) =    N' SELECT        (NEXT VALUE FOR [dbo].[report_cell_instances_sequence] OVER( '  + @C_ORDER_BY  + N' ) ) AS RecordId ,              @Instance_Id AS InstanceId ,       @Consumer_Id AS ConsumerId ,        @Column_Id AS ColumnId ,       ROW_NUMBER() OVER( '  + @C_ORDER_BY + N' ) AS Row_Order , '; \/* \u0417\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 *\/   DECLARE @C_COLUMN_FORMULA_FROM NVARCHAR(MAX) =    N' FROM        meteo_measurements mm     WHERE        mm.meteo_station_id = @Station_Id        AND mm.read_timestamp BETWEEN @FromDate AND @ThruDate        ' + @C_ORDER_BY   ; \/* \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 @Station_Id - \u0441\u0442\u0430\u043d\u0446\u0438\u044f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445 @FromDate - \u0431\u0440\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043e\u0442 \u0434\u0430\u0442\u044b @ThruDate - \u0431\u0440\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u043e \u0434\u0430\u0442\u0443 @Column_Id - \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 \u0434\u043b\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f @Instance_Id - \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043e\u0442\u0447\u0451\u0442\u0430 @Consumer_Id - \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 *\/   DECLARE @ColumnFormulaParams NVARCHAR(MAX);    SET @ColumnFormulaParams =      N' @Station_Id bigint , ' +      N' @FromDate datetimeoffset(7) , ' +     N' @ThruDate datetimeoffset(7) , ' +     N' @Column_Id INT , ' +     N' @Instance_Id INT , ' +     N' @Consumer_Id INT '   ; \/* \u0421\u0442\u0430\u043d\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d \u043e\u0442\u0447\u0451\u0442, \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0430\u044f \u0438\u0437 \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f *\/   DECLARE @Station BIGINT ;   SELECT TOP 1 @Station = sr.id FROM meteo_stations_reference sr ORDER BY NEWID(); \/* \u0412\u044b\u0432\u043e\u0434 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c, \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u0432\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u044b &quot;PRINT&quot; \u0441\u043b\u0443\u0436\u0430\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 *\/   PRINT N' @Staton  = ' + CAST ( @Station AS NVARCHAR ) ; \/* \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043e\u0442\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0447\u0451\u0442\u0430, @From - \u043e\u0442 \u0434\u0430\u0442\u044b @Thru  - \u043f\u043e \u0434\u0430\u0442\u0443 *\/   DECLARE @From DATETIMEOFFSET(7) ;   DECLARE @Thru DATETIMEOFFSET(7) ; \/* \u0431\u0435\u0440\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0434\u0430\u0442\u044b *\/   SELECT TOP 1 @From = mm.read_timestamp FROM meteo_measurements mm ORDER BY NEWID();   SELECT TOP 1 @Thru = mm.read_timestamp FROM meteo_measurements mm ORDER BY NEWID(); \/* \u0434\u0430\u0442\u044b &quot;\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c&quot; \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f *\/   DECLARE @SwapVariable DATETIMEOFFSET(7) ;   IF ( @From &gt; @Thru )     BEGIN       SET @SwapVariable = @Thru;       SET @Thru = @From ;       SET @From = @SwapVariable ;     END;    PRINT N' @From = ' + CAST ( @From  AS NVARCHAR )+ N' @Thru = ' + CAST ( @Thru  AS NVARCHAR ); \/* \u043a\u043b\u044e\u0447 \u0437\u0430\u043f\u0438\u0441\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043e\u0442\u0447\u0451\u0442\u0430, \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0438\u0437 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 *\/   DECLARE @Instance INT ;   SET @Instance = NEXT VALUE FOR [dbo].[report_instances_sequence] ; \/* \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043e\u0442\u0447\u0451\u0442\u0430, \u0441 \u043a\u043b\u044e\u0447\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f 1 - &quot;\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f&quot; *\/   INSERT INTO report_instances      ( id , name , description , state_id )   VALUES      (@Instance,CAST(@Instance AS NVARCHAR ),' DEBUG ', 1 )   ; \/* \u041a\u043b\u0438\u0435\u043d\u0442, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c *\/   DECLARE @ConsumerId INT ;   SELECT TOP 1 @ConsumerId = cr.id FROM consumer_reference cr ORDER BY NEWID();   PRINT N' @ConsumerId  = ' + CAST ( @ConsumerId AS NVARCHAR ) ; \/* \u041f\u0435\u0440\u0435\u0431\u043e\u0440 \u0438 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 T-SQL \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043a\u0443\u0440\u0441\u043e\u0440\u043e\u0432 ( \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043f\u0440\u0430\u0432\u044b\u043c ). \u041a\u0443\u0440\u0441\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438. \u0427\u0442\u043e \u0431\u044b \u043d\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u044b\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u0443\u0440\u0441\u043e\u0440\u043e\u0432 \u0432 T-SQL \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e. T-SQL \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 ( \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043f\u0440\u0430\u0432\u044b\u043c ), \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u0435\u043c\u0443 \u0441\u043b\u0443\u0436\u0438\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446, \u043b\u0438\u0431\u043e \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043d\u0430 \u0434\u0438\u0441\u043a \u0438 \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0430\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0430 \u043a\u043e\u0434\u0430. \u0422\u0430\u0431\u043b\u0438\u0447\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u043b\u043e\u043a\u0430 \u043a\u043e\u0434\u0430 \u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0430. \u041c\u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0431\u0435\u0436\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044f\u043c - \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u044f \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u043b\u043e\u043a\u0430\u0445 \u043a\u043e\u0434\u0430 \u043d\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b\u043e\u0441\u044c. \u0420\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 - \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0434\u0435\u0441\u044f\u0442\u043a\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0438\u0445 \u0431\u0443\u0434\u0435\u0442 1000, \u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043d\u043e \u0434\u043b\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439. *\/   --  CREATE TABLE #consumers_report_columns( --  column_id int ) -- --  INSERT INTO #consumers_report_columns ( column_id ) --  SELECT  --    rc.column_id  --  FROM  --    consumers_report_columns rc  --  WHERE --    rc.consumer_id = @ConsumerId --  ; \/* \u0422\u0430\u0431\u043b\u0438\u0447\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u043e\u0442\u0447\u0451\u0442\u0430 *\/   DECLARE @consumers_report_columns TABLE ( column_id INT )   INSERT INTO @consumers_report_columns (column_id)   SELECT      rc.column_id    FROM      consumers_report_columns rc    WHERE     rc.consumer_id = @ConsumerId   ;    \/* -=* CYCLE BEGIN *=- *\/  --  DECLARE consumers_report_columns_cursor CURSOR FOR  --  SELECT  --    rc.column_id  --  FROM  --    #consumers_report_columns rc --  ; \/* \u041a\u0443\u0440\u0441\u043e\u0440 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438 *\/   DECLARE consumers_report_columns_cursor CURSOR FOR    SELECT      rc.column_id    FROM      @consumers_report_columns rc   ; \/* \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 *\/     DECLARE @ColumnId INT ;    OPEN consumers_report_columns_cursor ;      FETCH NEXT FROM consumers_report_columns_cursor    INTO        @ColumnId      WHILE @@FETCH_STATUS = 0   BEGIN        PRINT N' @ColumnId  = ' + CAST ( @ColumnId AS NVARCHAR ) ; \/* \u041a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430 \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0435\u0434\u0438\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u043e\u0442\u0447\u0451\u0442\u0430, \u043d\u043e \u043d\u0430 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u043d\u0435 \u0431\u044b\u043b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0432\u0435\u0440\u0435\u043d \u0432 \u0441\u0435\u0431\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0431\u0438\u0442 \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. *\/ \/* \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c &quot;\u0441\u0441\u044b\u043b\u043a\u0443&quot; \u043d\u0430 \u0444\u043e\u0440\u043c\u0443\u043b\u0443 \u0438\u0437 \u0437\u0430\u043f\u0438\u0441\u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 *\/     DECLARE @FormulaId INT;     SELECT        @FormulaId = cl.formula_id     FROM        columns cl     WHERE       cl.id = @ColumnId  ;     PRINT N' @FormulaId  = ' + CAST ( @FormulaId AS NVARCHAR ) ; \/* \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u0443 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 *\/         DECLARE @formula NVARCHAR(MAX);     SELECT        @formula = fm.formula      FROM        formulas fm      WHERE       fm.id = @FormulaId  ;     PRINT N' @formula  = ' + @formula ; \/* \u0422\u0435\u043a\u0441\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438, \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0435\u0437 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 *\/       DECLARE @column_formula_phrase NVARCHAR(MAX);       SET @column_formula_phrase = @C_COLUMN_FORMULA_SELECT + @formula + @C_COLUMN_FORMULA_FROM ;     PRINT N' @column_formula_phrase  = ' + @column_formula_phrase ; \/* \u043b\u0438\u0448\u043d\u0435\u0435 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0435, \u043d\u043e \u043c\u043d\u0435 \u0432 \u043e\u0442\u043b\u0430\u0434\u043a\u0435 \u0442\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u0435\u0439 *\/     DECLARE @column_formula_sql NVARCHAR(MAX);     SET @column_formula_sql = @column_formula_phrase ; \/* \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0438, \u0432\u044b\u0437\u043e\u0432 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0439, \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d, \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0438 *\/     EXEC sp_executesql          @column_formula_sql       , @ColumnFormulaParams       , @Station_Id = @Station       , @FromDate = @From       , @ThruDate =  @Thru        , @Column_Id = @ColumnId       , @Instance_Id = @Instance       , @Consumer_Id = @ConsumerId \/* \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0438 \u0435\u0451 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 report_cell_instances *\/     SET @column_formula_phrase = @C_COLUMN_FORMULA_INSERT + @C_COLUMN_FORMULA_SELECT + @formula + @C_COLUMN_FORMULA_FROM ;     PRINT N' @column_formula_phrase  = ' + @column_formula_phrase ; \/* \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f *\/     SET @column_formula_sql = @column_formula_phrase ;                      EXEC sp_executesql          @column_formula_sql       , @ColumnFormulaParams       , @Station_Id = @Station       , @FromDate = @From       , @ThruDate =  @Thru        , @Column_Id = @ColumnId       , @Instance_Id = @Instance       , @Consumer_Id = @ConsumerId        FETCH NEXT FROM consumers_report_columns_cursor      INTO          @ColumnId   END    CLOSE consumers_report_columns_cursor; \/* \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d \u0447\u0442\u043e &quot;DEALLOCATE&quot; \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c *\/   DEALLOCATE consumers_report_columns_cursor;      \/* -=* CYCLE END *=- *\/ \/* \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c *\/ --  DROP TABLE #consumers_report_columns   DELETE @consumers_report_columns ; \/* \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e *\/ \/* \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u043e\u0432 \u043e\u0442\u0447\u0451\u0442\u0430 *\/   DECLARE @consumers_report_regions TABLE ( region_id INT )   INSERT INTO @consumers_report_regions (region_id)   SELECT      rr.region_id    FROM      consumers_report_regions rr    WHERE     rr.consumer_id = @ConsumerId   ; \/* \u041a\u0443\u0440\u0441\u043e\u0440 \u043f\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430\u043c \u043e\u0442\u0447\u0451\u0442\u0430 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0432 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e  *\/   DECLARE consumers_report_regions_cursor CURSOR FOR    SELECT      rr.region_id    FROM      @consumers_report_regions rr   ; \/* \u0427\u0430\u0441\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0430 *\/   DECLARE @C_REGION_FORMULA_SELECT NVARCHAR(MAX) = N' SELECT @Result = ' ; \/* \u0417\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0430 *\/   DECLARE @C_REGION_FORMULA_FROM NVARCHAR(MAX) =  N' FROM    meteo_measurements mm  WHERE    mm.meteo_station_id = @Station_Id    AND mm.read_timestamp BETWEEN @FromDate AND @ThruDate    '; \/* \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0430 @Station_Id - \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e \u0441\u0442\u0430\u043d\u0446\u0438\u0438 @FromDate - \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0434\u0430\u0442\u044b @ThruDate - \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e \u0434\u0430\u0442\u044b @Result - \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u044b *\/   DECLARE @C_REGION_FORMULA_PARAMS NVARCHAR(MAX) =      N' @Station_Id bigint , ' +      N' @FromDate datetimeoffset(7) , ' +     N' @ThruDate datetimeoffset(7) , ' +     N' @Result NVARCHAR(MAX) OUT '   ;    \/*\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430*\/   DECLARE @RegionId INT ;    OPEN consumers_report_regions_cursor ;      FETCH NEXT FROM consumers_report_regions_cursor    INTO        @RegionId      WHILE @@FETCH_STATUS = 0   BEGIN        PRINT N' @RegionId  = ' + CAST ( @RegionId AS NVARCHAR ) ; \/* \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d \u0440\u0430\u0437\u0434\u0435\u043b\u0430 *\/     DECLARE @Pattern NVARCHAR(MAX) ;     SELECT       @Pattern = rg.pattern     FROM       regions rg     WHERE       rg.id = @RegionId     ;     PRINT N' @Pattern  = ' + @Pattern ; \/* \u0422\u0430\u0431\u043b\u0438\u0447\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f. \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0443\u043b \u0438 \u0438\u0445 \u043e\u0442\u043c\u0435\u0442\u043e\u043a \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 *\/     DECLARE @region_formulas_and_placeholders TABLE ( formula NVARCHAR(MAX) , placeholder NVARCHAR(MAX) ) \/* \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e *\/     INSERT INTO @region_formulas_and_placeholders ( formula , placeholder )     SELECT        fr.formula       , rf.placeholder     --  , rg.pattern     FROM       regions rg       JOIN region_formulas rf        ON rg.id = rf.region_id       JOIN formulas fr        ON rf.formula_id = fr.id     WHERE       rg.id = @RegionId     ; \/* \u041a\u0443\u0440\u0441\u043e\u0440 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 \u0444\u043e\u0440\u043c\u0443\u043b\u0430\u043c\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0430  *\/     DECLARE region_formulas_and_placeholders_cursor CURSOR FOR      SELECT          fp.formula       , fp.placeholder      FROM        @region_formulas_and_placeholders fp     ; \/* \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0430 *\/     DECLARE @region_formula NVARCHAR(MAX); \/*  \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043e\u0442\u043c\u0435\u0442\u043a\u0438 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0430. \u043c\u0435\u0441\u0442\u0430 \u043a\u0443\u0434\u0430 \u043d\u0430\u0434\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u044b *\/     DECLARE @placeholder NVARCHAR(MAX);      OPEN region_formulas_and_placeholders_cursor ;          FETCH NEXT FROM region_formulas_and_placeholders_cursor      INTO          @region_formula       , @placeholder          WHILE @@FETCH_STATUS = 0     BEGIN        PRINT N' @region_formula  = ' + @region_formula + N' @placeholder = ' + @placeholder; \/* \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0430 *\/           DECLARE @region_formula_phrase NVARCHAR(MAX) ;         SET @region_formula_phrase = @C_REGION_FORMULA_SELECT + @region_formula + @C_REGION_FORMULA_FROM ;       PRINT N' @region_formula_phrase  = ' + @region_formula_phrase ;              DECLARE @region_formula_sql NVARCHAR(MAX) ;        SET @region_formula_sql = @region_formula_phrase ; \/* \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0438 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043c\u0435\u0442\u043a\u043e\u0439 *\/       DECLARE @Substitute NVARCHAR(MAX) ;  \/* \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0430, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432 @Substitute *\/                          EXEC sp_executesql            @region_formula_sql         , @C_REGION_FORMULA_PARAMS         , @Station_Id = @Station         , @FromDate = @From         , @ThruDate =  @Thru         , @Result = @Substitute OUT       ;       PRINT N' @Substitute = ' + @Substitute ;  \/* \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043c\u0435\u043d\u0443 \u043c\u0435\u0442\u043a\u0438 \u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 *\/       SET @Pattern = REPLACE ( @Pattern , @placeholder , @Substitute ) ;         FETCH NEXT FROM region_formulas_and_placeholders_cursor        INTO            @region_formula         , @placeholder     END      CLOSE region_formulas_and_placeholders_cursor;     DEALLOCATE region_formulas_and_placeholders_cursor;  \/* \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 *\/     DELETE @region_formulas_and_placeholders ;      PRINT N' FINISH @Pattern ' + @Pattern ; \/* \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 report_region_instances *\/     INSERT INTO report_region_instances     ( instace_id ,consumer_id ,region_id ,value )     VALUES( @Instance , @ConsumerId , @RegionId , @Pattern )         ;        FETCH NEXT FROM consumers_report_regions_cursor      INTO          @RegionId   END    CLOSE consumers_report_regions_cursor;   DEALLOCATE consumers_report_regions_cursor; \/* \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e - \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c *\/   DELETE @consumers_report_regions ;  \/* \u0412\u0441\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u044b. \u0432\u0441\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u044b - \u043c\u044b \u043c\u043e\u043b\u043e\u0434\u0446\u044b :) *\/ END; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h4>\n<p>  \u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u044b\u043c, \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b\u043e\u0441\u044c.<\/p>\n<h5>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445<\/h5>\n<p>  \u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 <b>dbForge Studio<\/b>.<br \/>  \u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <b>meteo_measurements<\/b>, \u0442\u0438\u043f \u0434\u043b\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0438 <b>read_timestamp<\/b> \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0441 &quot;<b>timestamp<\/b>&quot; \u043d\u0430 &quot;<b>datetimeoffset<\/b>(7)&quot;, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 \u0442\u0438\u043f\u043e\u043c &quot;<b>timestamp<\/b>&quot; \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u0432\u0435\u0440, \u0432 \u0440\u0443\u0447\u043d\u0443\u044e \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043e, \u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0432 <b>dbForge Studio<\/b> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0440\u0443\u0447\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u2014 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438 \u00abINSERT\u00bb.<br \/>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u00abmeteo_station_id\u00bb \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438, \u0432 \u0441\u043c\u044b\u0441\u043b\u0435 \u0434\u043e\u043f\u0438\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442:  <\/p>\n<ol>\n<li>\u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u00abmeasurements(read_timestamp,\u00bb \u043d\u0430 \u00abmeasurements(meteo_station_id,read_timestamp,\u00bb<\/li>\n<li>\u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c <b>&quot;<\/b>wind_speed) VALUES (&#8216;<b>&quot;<\/b> \u043d\u0430 <b>&quot;<\/b>wind_speed) VALUES ((SELECT TOP 1 id FROM meteo_stations_reference ORDER BY NEWID()),&#8217;<b>&quot;<\/b><\/li>\n<\/ol>\n<p>  \u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u043d\u0430 15 000 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043d\u0430 16 000 \u0441\u0431\u0438\u0432\u0430\u043b\u0441\u044f \u043f\u0435\u0440\u0435\u043d\u043e\u0441 \u0441\u0442\u0440\u043e\u043a.  <\/p>\n<h5>\u0422\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438<\/h5>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041f\u0430\u0440\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0431\u044b\u043b\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0430, \u0438 \u044f \u0443\u0436\u0435 \u043d\u0435 \u043f\u043e\u043c\u043d\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044d\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u044e \u0432\u0441\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<br \/>  DDL \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 DML \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0441\u043e \u0432\u0441\u0442\u0430\u0432\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u043d\u0430 <b>GitHub<\/b>.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">DDL \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 DML \u0441 \u0432\u0441\u0442\u0430\u0432\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">CREATE TABLE Linegro.dbo.meteo_stations_reference (   id BIGINT NOT NULL  ,name NVARCHAR(4000) NOT NULL  ,description NVARCHAR(MAX) NULL  ,CONSTRAINT PK_meteo_stations_reference PRIMARY KEY CLUSTERED (id)  ,CONSTRAINT UK_meteo_stations_reference_name UNIQUE (name) ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET DATEFORMAT ymd SET ARITHABORT, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON SET NUMERIC_ROUNDABORT, IMPLICIT_TRANSACTIONS, XACT_ABORT OFF GO INSERT Linegro.dbo.meteo_stations_reference(id, name, description) VALUES (1, N'\u0422\u0410\u0413\u0410\u041d\u0410\u0419', N'\u041c\u0435\u0442\u0435\u043e\u0441\u0442\u0430\u043d\u0446\u0438\u044f &quot;\u0422\u0430\u0433\u0430\u043d\u0430\u0439&quot;') INSERT Linegro.dbo.meteo_stations_reference(id, name, description) VALUES (2, N'\u0441\u0432\u0435\u0440\u0434\u043b\u043e\u0432\u0441\u043a', N'\u041c\u0435\u0442\u0435\u043e\u0441\u0442\u0430\u043d\u0446\u0438\u044f \u043d\u0430 \u041c\u0435\u0442\u0435\u043e \u0433\u043e\u0440\u043a\u0435') INSERT Linegro.dbo.meteo_stations_reference(id, name, description) VALUES (3, N'\u0426\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u0430\u044f', N'\u041c\u043e\u0441\u043a\u0432\u0430 \u0426\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u0430\u044f') INSERT Linegro.dbo.meteo_stations_reference(id, name, description) VALUES (4, N'\u0412\u043b\u0430\u0434\u0438\u043a', N'\u041c\u043e\u0440\u0441\u043a\u043e\u0439 \u043f\u043e\u0440\u0442 \u0412\u043b\u0430\u0434\u0438\u0432\u043e\u0441\u0442\u043e\u043a') INSERT Linegro.dbo.meteo_stations_reference(id, name, description) VALUES (5, N'\u042f\u043a\u0443\u0442\u0438\u044f', N'\u041c\u0435\u0442\u0435\u043e\u0441\u0442\u0430\u043d\u0446\u0438\u044f \u0440\u0435\u0441\u043f\u0443\u0431\u043b\u0438\u043a\u0438 \u0421\u0430\u0445\u0430 - \u042f\u043a\u0443\u0442\u0438\u044f') GO CREATE TABLE Linegro.dbo.meteo_measurements (   meteo_station_id BIGINT NOT NULL  ,read_timestamp DATETIMEOFFSET NOT NULL  ,temperature DECIMAL(4, 1) NULL  ,pressure INT NULL  ,wind_direction INT NULL  ,wind_speed INT NULL  ,CONSTRAINT PK_meteo_measurements PRIMARY KEY CLUSTERED (meteo_station_id, read_timestamp)  ,CONSTRAINT FK_meteo_measurements_meteo_stations_reference_id FOREIGN KEY (meteo_station_id) REFERENCES dbo.meteo_stations_reference (id) ) ON [PRIMARY] GO CREATE TABLE Linegro.dbo.consumer_reference (   id INT NOT NULL  ,name NVARCHAR(4000) NOT NULL  ,description NVARCHAR(MAX) NULL  ,CONSTRAINT PK_consumer_reference PRIMARY KEY CLUSTERED (id)  ,CONSTRAINT UK_consumer_reference_name UNIQUE (name) ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET DATEFORMAT ymd SET ARITHABORT, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON SET NUMERIC_ROUNDABORT, IMPLICIT_TRANSACTIONS, XACT_ABORT OFF GO  INSERT Linegro.dbo.consumer_reference(id, name, description) VALUES (1, N'\u0418\u041f \u041d\u0430\u0438\u0431\u0435\u043d\u044c\u043a\u043e', N'\u043d\u0430\u0438\u0431\u0438 \u043f\u0440\u043e\u0445\u043e\u0436\u0435\u0433\u043e \u043d\u0430 \u0442\u0435\u0431\u044f \u043f\u043e\u0445\u043e\u0436\u0435\u0433\u043e') INSERT Linegro.dbo.consumer_reference(id, name, description) VALUES (2, N'\u041c\u041e \u0420\u0424', N'\u041c\u0438\u043d\u0438\u0441\u0442\u0435\u0440\u0441\u0442\u0432\u043e \u043e\u0431\u043e\u0440\u043e\u043d\u044b \u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u0439 \u0424\u0435\u0434\u0435\u0440\u0430\u0446\u0438\u0438') INSERT Linegro.dbo.consumer_reference(id, name, description) VALUES (3, N'\u0420\u043e\u0442\u0430 23', N'\u0410\u0440\u0442\u0438\u043b\u043b\u0435\u0440\u0438\u0439\u0441\u043a\u0438\u0439 \u0440\u0430\u0441\u0447\u0451\u0442 \u0440\u043e\u0442\u0430 23') INSERT Linegro.dbo.consumer_reference(id, name, description) VALUES (4, N'426 \u0413\u043e\u0440\u043d\u044b\u0439 2016', N'\u0433\u0440\u0443\u043f\u043f\u0430 \u043d\u043e\u043c\u0435\u0440 426 ( 2016 ) \u0413\u043e\u0440\u043d\u043e\u0433\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430 \u0433\u043e\u0440\u043e\u0434\u0430 \u0415\u043a\u0430\u0442\u0435\u0440\u0438\u043d\u0443\u0431\u0443\u0440\u0433\u0430 ') GO CREATE TABLE Linegro.dbo.formulas (   id INT NOT NULL  ,code NCHAR(50) NOT NULL  ,formula NVARCHAR(MAX) NOT NULL  ,CONSTRAINT PK_formulas PRIMARY KEY CLUSTERED (id)  ,CONSTRAINT UK_formulas_code UNIQUE (code) ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET DATEFORMAT ymd SET ARITHABORT, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON SET NUMERIC_ROUNDABORT, IMPLICIT_TRANSACTIONS, XACT_ABORT OFF GO  INSERT Linegro.dbo.formulas(id, code, formula) VALUES (1, N'temperature', N'COALESCE(temperature ,0) AS temperature') INSERT Linegro.dbo.formulas(id, code, formula) VALUES (2, N'pressure', N'COALESCE(pressure,0) AS pressure') INSERT Linegro.dbo.formulas(id, code, formula) VALUES (3, N'wind_direction', N'COALESCE(wind_direction,0) AS wind_direction') INSERT Linegro.dbo.formulas(id, code, formula) VALUES (4, N'wind_speed', N'wind_speed AS wind_speed') INSERT Linegro.dbo.formulas(id, code, formula) VALUES (5, N'temperature_max', N'MAX(COALESCE(temperature,0)) ') INSERT Linegro.dbo.formulas(id, code, formula) VALUES (6, N'temperature_min', N'MIN(COALESCE(temperature,0)) ') INSERT Linegro.dbo.formulas(id, code, formula) VALUES (7, N'temperature_avg', N'AVG(COALESCE(temperature,0)) ') INSERT Linegro.dbo.formulas(id, code, formula) VALUES (8, N'speed_m_s', N'CAST ( COALESCE(wind_speed  ,0) AS NVARCHAR ) + N'' ( $M_S$ )'' AS speed_m_s') GO CREATE TABLE Linegro.dbo.columns (   id INT NOT NULL  ,formula_id INT NOT NULL  ,name NVARCHAR(MAX) NOT NULL  ,description NVARCHAR(MAX) NULL  ,CONSTRAINT PK_columns PRIMARY KEY CLUSTERED (id)  ,CONSTRAINT FK_columns_formulas_id FOREIGN KEY (formula_id) REFERENCES dbo.formulas (id) ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET DATEFORMAT ymd SET ARITHABORT, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON SET NUMERIC_ROUNDABORT, IMPLICIT_TRANSACTIONS, XACT_ABORT OFF GO  INSERT Linegro.dbo.columns(id, formula_id, name, description) VALUES (1, 1, N'\u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430', N'\u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430 \u0432\u043e\u0437\u0434\u0443\u0445\u0430 ( \u0433\u0440\u0430\u0434\u0443\u0441\u043e\u0432 \u0426\u0435\u043b\u044c\u0441\u0438\u044f )  ') INSERT Linegro.dbo.columns(id, formula_id, name, description) VALUES (2, 2, N'\u0434\u0430\u0432\u043b\u0435\u043d\u0438\u0435', N'\u0430\u0442\u043c\u043e\u0441\u0444\u0435\u0440\u043d\u043e\u0435 \u0434\u0430\u0432\u043b\u0435\u043d\u0438\u0435 ( \u043c\u043c \u0440\u0442 \u0441\u0442 )') INSERT Linegro.dbo.columns(id, formula_id, name, description) VALUES (3, 3, N'\u0432\u0435\u0442\u0435\u0440', N'\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0435\u0442\u0440\u0430') INSERT Linegro.dbo.columns(id, formula_id, name, description) VALUES (4, 4, N'\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c', N'\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u0435\u0442\u0440\u0430 ( \u043c\/\u0441 )') INSERT Linegro.dbo.columns(id, formula_id, name, description) VALUES (5, 8, N'\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c', N'\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u0435\u0442\u0440\u0430') GO CREATE TABLE Linegro.dbo.regions (   id INT NOT NULL  ,pattern NVARCHAR(MAX) NOT NULL  ,name NVARCHAR(4000) NOT NULL  ,description NVARCHAR(MAX) NULL  ,CONSTRAINT PK_regions PRIMARY KEY CLUSTERED (id)  ,CONSTRAINT UK_regions_name UNIQUE (name) ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET DATEFORMAT ymd SET ARITHABORT, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON SET NUMERIC_ROUNDABORT, IMPLICIT_TRANSACTIONS, XACT_ABORT OFF GO  INSERT Linegro.dbo.regions(id, pattern, name, description) VALUES (1, N'max temp = $MAX_TEMP$ , min temp = $MIN_TEMP$ , average temp = $AVG_TEMP$', N'temp_statistics', N'\u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043f\u043e \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0435') INSERT Linegro.dbo.regions(id, pattern, name, description) VALUES (2, N'\u0433\u0440\u0443\u043f\u043f\u0430 \u043d\u043e\u043c\u0435\u0440 426 ( 2016 ) \u0413\u043e\u0440\u043d\u043e\u0433\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430 \u0433\u043e\u0440\u043e\u0434\u0430 \u0415\u043a\u0430\u0442\u0435\u0440\u0438\u043d\u0443\u0431\u0443\u0440\u0433\u0430 ', N'426_2016_title', N'\u0448\u0430\u043f\u043a\u0430') INSERT Linegro.dbo.regions(id, pattern, name, description) VALUES (3, N' ', N'empty', N'\u043f\u0443\u0441\u0442\u043e\u0435 \u043f\u043e\u043b\u0435') INSERT Linegro.dbo.regions(id, pattern, name, description) VALUES (4, N'\u041c\u0438\u043d\u0438\u0441\u0442\u0435\u0440\u0441\u0442\u0432\u043e \u043e\u0431\u043e\u0440\u043e\u043d\u044b \u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u0439 \u0424\u0435\u0434\u0435\u0440\u0430\u0446\u0438\u0438', N'\u041c\u041e \u0420\u0424', NULL) INSERT Linegro.dbo.regions(id, pattern, name, description) VALUES (5, N'\u0418\u041f \u041d\u0430\u0438\u0431\u0435\u043d\u044c\u043a\u043e', N'\u0418\u041f \u041d\u0430\u0438\u0431\u0435\u043d\u044c\u043a\u043e', NULL) GO CREATE TABLE Linegro.dbo.consumers_report_columns (   column_id INT NOT NULL  ,consumer_id INT NOT NULL  ,column_order INT NOT NULL  ,CONSTRAINT PK_consumers_report_columns PRIMARY KEY CLUSTERED (consumer_id, column_id)  ,CONSTRAINT UK_consumers_report_columns_column_order UNIQUE (consumer_id, column_order)  ,CONSTRAINT FK_consumers_report_columns_columns_id FOREIGN KEY (column_id) REFERENCES dbo.columns (id)  ,CONSTRAINT FK_consumers_report_columns_consumer_reference_id FOREIGN KEY (consumer_id) REFERENCES dbo.consumer_reference (id) ) ON [PRIMARY] GO SET DATEFORMAT ymd SET ARITHABORT, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON SET NUMERIC_ROUNDABORT, IMPLICIT_TRANSACTIONS, XACT_ABORT OFF GO  INSERT Linegro.dbo.consumers_report_columns(column_id, consumer_id, column_order) VALUES (3, 1, 1) INSERT Linegro.dbo.consumers_report_columns(column_id, consumer_id, column_order) VALUES (3, 2, 1) INSERT Linegro.dbo.consumers_report_columns(column_id, consumer_id, column_order) VALUES (4, 2, 3) INSERT Linegro.dbo.consumers_report_columns(column_id, consumer_id, column_order) VALUES (2, 2, 5) INSERT Linegro.dbo.consumers_report_columns(column_id, consumer_id, column_order) VALUES (1, 2, 14) INSERT Linegro.dbo.consumers_report_columns(column_id, consumer_id, column_order) VALUES (3, 3, 10) INSERT Linegro.dbo.consumers_report_columns(column_id, consumer_id, column_order) VALUES (5, 3, 20) INSERT Linegro.dbo.consumers_report_columns(column_id, consumer_id, column_order) VALUES (2, 4, 11) INSERT Linegro.dbo.consumers_report_columns(column_id, consumer_id, column_order) VALUES (1, 4, 22) GO CREATE TABLE Linegro.dbo.consumers_report_regions (   consumer_id INT NOT NULL  ,region_id INT NOT NULL  ,region_order INT NOT NULL  ,type_id INT NULL  ,CONSTRAINT PK_consumers_report_base PRIMARY KEY CLUSTERED (consumer_id, region_id)  ,CONSTRAINT UK_consumers_report_regions_region_order UNIQUE (consumer_id, region_order)  ,CONSTRAINT FK_consumers_report_regions_consumer_reference_id FOREIGN KEY (consumer_id) REFERENCES dbo.consumer_reference (id)  ,CONSTRAINT FK_consumers_report_regions_regions_id FOREIGN KEY (region_id) REFERENCES dbo.regions (id)  ,CONSTRAINT FK_consumers_report_regions_report_region_types_id FOREIGN KEY (type_id) REFERENCES dbo.report_region_types (id) ) ON [PRIMARY] GO SET DATEFORMAT ymd SET ARITHABORT, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON SET NUMERIC_ROUNDABORT, IMPLICIT_TRANSACTIONS, XACT_ABORT OFF GO  INSERT Linegro.dbo.consumers_report_regions(consumer_id, region_id, region_order, type_id) VALUES (1, 5, 1, 2) INSERT Linegro.dbo.consumers_report_regions(consumer_id, region_id, region_order, type_id) VALUES (2, 1, -1, 4) INSERT Linegro.dbo.consumers_report_regions(consumer_id, region_id, region_order, type_id) VALUES (2, 4, 1, 1) INSERT Linegro.dbo.consumers_report_regions(consumer_id, region_id, region_order, type_id) VALUES (3, 1, 50, 5) INSERT Linegro.dbo.consumers_report_regions(consumer_id, region_id, region_order, type_id) VALUES (3, 3, -100, 3) INSERT Linegro.dbo.consumers_report_regions(consumer_id, region_id, region_order, type_id) VALUES (3, 4, 5, 1) INSERT Linegro.dbo.consumers_report_regions(consumer_id, region_id, region_order, type_id) VALUES (4, 2, 10, 3) GO CREATE TABLE Linegro.dbo.region_formulas (   id INT NOT NULL  ,formula_id INT NOT NULL  ,region_id INT NOT NULL  ,placeholder NVARCHAR(4000) NOT NULL  ,CONSTRAINT PK_region_formulas PRIMARY KEY CLUSTERED (id)  ,CONSTRAINT UK_region_formulas UNIQUE (region_id, formula_id)  ,CONSTRAINT FK_region_formulas_formulas_formula_id FOREIGN KEY (formula_id) REFERENCES dbo.formulas (id)  ,CONSTRAINT FK_region_formulas_regions_id FOREIGN KEY (region_id) REFERENCES dbo.regions (id) ) ON [PRIMARY] GO SET DATEFORMAT ymd SET ARITHABORT, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON SET NUMERIC_ROUNDABORT, IMPLICIT_TRANSACTIONS, XACT_ABORT OFF GO  INSERT Linegro.dbo.region_formulas(id, formula_id, region_id, placeholder) VALUES (1, 5, 1, N'$MAX_TEMP$') INSERT Linegro.dbo.region_formulas(id, formula_id, region_id, placeholder) VALUES (2, 6, 1, N'$MIN_TEMP$') INSERT Linegro.dbo.region_formulas(id, formula_id, region_id, placeholder) VALUES (3, 7, 1, N'$AVG_TEMP$') GO CREATE TABLE Linegro.dbo.report_instace_states_reference (   id INT NOT NULL  ,code NCHAR(50) NOT NULL  ,description NVARCHAR(MAX) NULL  ,CONSTRAINT PK_report_instace_states_reference PRIMARY KEY CLUSTERED (id)  ,CONSTRAINT UK_report_instace_states_reference_code UNIQUE (code) ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET DATEFORMAT ymd SET ARITHABORT, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON SET NUMERIC_ROUNDABORT, IMPLICIT_TRANSACTIONS, XACT_ABORT OFF GO  INSERT Linegro.dbo.report_instace_states_reference(id, code, description) VALUES (1, N'\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f', N'\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f') INSERT Linegro.dbo.report_instace_states_reference(id, code, description) VALUES (2, N'\u0433\u043e\u0442\u043e\u0432', N'\u0433\u043e\u0442\u043e\u0432') INSERT Linegro.dbo.report_instace_states_reference(id, code, description) VALUES (3, N'\u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d', N'\u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d') INSERT Linegro.dbo.report_instace_states_reference(id, code, description) VALUES (4, N'\u0443\u0434\u0430\u043b\u0451\u043d', N'\u0443\u0434\u0430\u043b\u0451\u043d') GO <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0445 \u0444\u043e\u0440\u043c\u0443\u043b \u00ab\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f\u00bb \u043a\u0430\u043a <b>NVARCHAR<\/b>(MAX), \u043d\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043d\u0435 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u2014 \u044d\u0442\u043e \u043d\u0430 \u0441\u043e\u0432\u0435\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0438\u0445 \u043a\u0432\u0430\u043b\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<h4>\u0423\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b<\/h4>\n<p>  \u0412 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043d\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <b>formula_parameters<\/b>, \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0443.<\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0451 \u0432 \u0432\u0430\u0448\u0438\u0445 \u0440\u0443\u043a\u0430\u0445, \u0438\u0437 \u044d\u0442\u043e\u0439 \u0431\u043e\u043b\u0432\u0430\u043d\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0430\u0441\u0442\u0435\u0440\u0438\u0442\u044c \u0432\u0441\u0451 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0438 \u043a\u0430\u043a \u0432\u0430\u043c \u0443\u0433\u043e\u0434\u043d\u043e \ud83d\ude42<br \/>  \u0415\u0441\u043b\u0438 \u044f \u0447\u0442\u043e \u0442\u043e \u0443\u043f\u0443\u0441\u0442\u0438, \u0442\u043e \u043c\u043e\u0433\u0443 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<br \/>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<h4>\u0421\u0441\u044b\u043b\u043a\u0438<\/h4>\n<p>  <\/p>\n<ol>\n<li> <a href=\"https:\/\/habrahabr.ru\/post\/278595\/\">\u0414\u0432\u0438\u0436\u043e\u043a \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043e\u0442\u0447\u0451\u0442\u043e\u0432 \u043d\u0430 SQL. \u0418\u0434\u0435\u044f<\/a> <\/li>\n<li> <a href=\"https:\/\/github.com\/SbWereWolf\/SqlReportConstructor\">\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u2014 GitHub<\/a> <\/li>\n<li> <a href=\"https:\/\/habrahabr.ru\/post\/220185\/\">\u041a\u0430\u043a \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 MS SQL \u0440\u0430\u0437\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u043c\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438\u043b\u0438 17 \u0447\u0430\u0441\u043e\u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f<\/a> <\/li>\n<li> <a href=\"https:\/\/www.devart.com\/ru\/dbforge\/sql\/studio\/download.html\">dbForge Studio for SQL Server<\/a> <\/li>\n<li> <a href=\"http:\/\/stackoverflow.com\/questions\/19412\/how-to-request-a-random-row-in-sql\">How to request a random row in SQL?<\/a> <\/li>\n<li> <a href=\"http:\/\/www.sommarskog.se\/dynamic_sql.html\">The Curse and Blessings of Dynamic SQL<\/a> <\/li>\n<li> <a href=\"http:\/\/www.sqlteam.com\/article\/temporary-tables\">Temporary Tables<\/a> <\/li>\n<\/ol>\n<div class=\"clear\"><\/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=\"https:\/\/habrahabr.ru\/post\/278921\/\"> https:\/\/habrahabr.ru\/post\/278921\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<br \/>\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 ( <a href=\"https:\/\/habrahabr.ru\/post\/278595\/\">\u0414\u0432\u0438\u0436\u043e\u043a \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043e\u0442\u0447\u0451\u0442\u043e\u0432 \u043d\u0430 SQL. \u0418\u0434\u0435\u044f<\/a> ) \u044f \u043f\u043e\u0434\u0435\u043b\u0438\u043b\u0441\u044f \u0438\u0434\u0435\u0435\u0439. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0435\u043b\u044e\u0441\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c ( \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a\u043e\u043c ). \u042d\u0442\u043e\u0442 \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a \u2014 \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 \u00ab\u0441\u0435\u0440\u044c\u0435\u0437\u043d\u043e\u0439\u00bb \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <b>T-SQL<\/b>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0435\u0433\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u0430 \u043e\u0431\u0440\u0430\u0437\u0435\u0446 \u00ab\u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e\u00bb \u043a\u043e\u0434\u0430.<br \/>  \u0421\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e\u0435 \u0432 \u044d\u0442\u043e\u043c \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a\u0435 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u0443\u043b \u0432 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u0412\u0442\u043e\u0440\u043e\u0435 \u043f\u043e \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439.   <\/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-275803","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/275803","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=275803"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/275803\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=275803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=275803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=275803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}