<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>&#8235;Madeira &#187; שי אנגלברג&#8236;</title>	<atom:link href="http://www.madeira.co.il/author/shy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.madeira.co.il</link>
	<description>&#8235;SQL Server Services&#8236;</description>	<lastBuildDate>Sat, 19 May 2012 09:04:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>he</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>&#8235;24Hours of PASS&#8236;</title>		<link>http://www.madeira.co.il/24-hours-of-pass/</link>
		<comments>http://www.madeira.co.il/24-hours-of-pass/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 13:11:39 +0000</pubDate>
		<dc:creator>&#8235;שי אנגלברג&#8236;</dc:creator>				<category><![CDATA[אל תציג בבלוגים]]></category>
		<category><![CDATA[חדשות ואירועים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[PASS]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=2247</guid>
		<description><![CDATA[&#8235;כולכם מוזמנים לצפות איתנו במיטב ההרצאות של מיטב המומחים.
7-8.9 בקפה מצדה בהרצליה.
&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/2247.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>למי ששכח ולמי שלא ידע,</p>
<p>מדירה מזמינה את כולם לצפות בצוותא בהרצאות של 24 שעות של PASS.</p>
<p>בימים רביעי וחמישי, 7-8.9 נצפה יחדיו במיטב ההרצאות של מיטב המומחים בעולם בתחום ה SQL.</p>
<p>האירוע יתקיים בקפה מצדה בהרצליה בין השעות 15:00-03:00.</p>
<p>פרטים נוספים ניתן למצוא כאן: <a href="http://www.madeira.co.il/contact/post_notifications/pass2011">http://www.madeira.co.il/contact/post_notifications/pass2011</a></p>
<p>נשמח לראותכם.</p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/24-hours-of-pass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8235;עבודה עם שעות ותאריכים של SQL AGENT&#8236;</title>		<link>http://www.madeira.co.il/working-with-sqlagent-dateandtime/</link>
		<comments>http://www.madeira.co.il/working-with-sqlagent-dateandtime/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 11:16:05 +0000</pubDate>
		<dc:creator>&#8235;שי אנגלברג&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[כללי]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[Agent]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Datetime]]></category>
		<category><![CDATA[msdb]]></category>
		<category><![CDATA[SQL Server Agent]]></category>
		<category><![CDATA[sysjobhistory]]></category>
		<category><![CDATA[System function]]></category>
		<category><![CDATA[Time]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/%d7%a2%d7%91%d7%95%d7%93%d7%94-%d7%a2%d7%9d-%d7%a9%d7%a2%d7%95%d7%aa-%d7%95%d7%aa%d7%90%d7%a8%d7%99%d7%9b%d7%99%d7%9d-%d7%a9%d7%9c-sql-agent/</guid>
		<description><![CDATA[&#8235;פונקצית מערכת נוחה שעוזרת לנו להפוך את הייצוג המוזר של תאריכים ושעות בטבלאות של ה SQL Agent ל DateTime.&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/2121.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<div dir="rtl" align="right">
<div dir="rtl" align="right">עולם ה DBA-ים מתחלק בגסות לשתי קבוצות:</div>
<div dir="rtl" align="right">אלו שכבר ניתחו את טבלאות המערכת והלוגים של ה SQL Agent ואלו שיעשו זאת בקרוב מאוד.</div>
<div dir="rtl" align="right">כידוע, טבלאות המערכת של ה Agent מצויות ב msdb.</div>
<div dir="rtl" align="right">ברוב הטבלאות שמשמשות את ה Agent הרישום של תאריכים ושעות מופיע בצורה משונה של שני ערכים מספריים – האחד מסמל את התאריך והשני מסמל את השעה.</div>
<div dir="rtl" align="right">כך ניתן לראות את זמני תחילת הריצה של Job ושל ה steps שלו בטבלת המערכת&#160; dbo.sysjobhistory (המכילה את היסטוריית הריצה של ה Jobs)</div>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; height: 71px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">SELECT</span> </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> job_id,step_id,step_name,run_status,run_date,run_time,run_duration </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> <span style="color: #0000ff">FROM</span> msdb.dbo.sysjobhistory</pre>
<p><!--CRLF--></div>
</p></div>
<p>&#160;<a href="http://www.madeira.co.il/wp-content/uploads/2011/08/image6.png" rel="wp-prettyPhoto[g2121]"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.madeira.co.il/wp-content/uploads/2011/08/image_thumb6.png" width="354" height="143" /></a></p>
<p>&#160;</p>
</div>
<div dir="rtl" align="right">
<div dir="rtl" align="right">שימו לב לעמודות ה run_date ו run_time שם מופיעים מספרים שמייצגים תאריך ושעה. שימו לב, סוג העמודות הנ”ל הוא INT.</div>
<div dir="rtl" align="right">התאריך מופיע בפורמט YYYYMMDD.</div>
<div dir="rtl" align="right">השעה מופיעה בפורמט HHMMSS בשעון של 24 שעות.</div>
<div dir="rtl" align="right">כפי שכתבתי, הצורה הזו של שמירת תאריכים ושעות משמשת כמעט בכל הטבלאות של ה Agent כמו למשל:</div>
<div dir="rtl" align="right">dbo.sysjobschedules</div>
<div dir="rtl" align="right">dbo.sysschedules</div>
<div dir="rtl" align="right">ועוד.&lt;</div>
<div dir="rtl" align="right">&#160;</div>
<div dir="rtl" align="right"><strong>הפתרון</strong></div>
<div dir="rtl" align="right">כדי לפענח או יותר נכון להמיר את המספרים האלו ל Datetime, ישנה פונקצית מערכת קטנה ונחמדה ב msdb שמקבלת שני פרמטרים, שניהם מסוג INT ומחזירה DateTime.</div>
<div dir="rtl" align="right">הפונקצייה נקראת dbo.agent_datetime.</div>
<div dir="rtl" align="right">הפרמטר הראשון הוא המספר שמייצג את התאריך והשני הוא המספר שמייצג את השעה.</div>
<div dir="rtl" align="right">תוכן הפונקציה הוא:</div>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; height: 213px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">FUNCTION</span> agent_datetime(@<span style="color: #0000ff">date</span> <span style="color: #0000ff">int</span>, @<span style="color: #0000ff">time</span> <span style="color: #0000ff">int</span>)  </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> <span style="color: #0000ff">RETURNS</span> DATETIME  </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> <span style="color: #0000ff">AS</span>  </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> <span style="color: #0000ff">BEGIN</span>  </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>  <span style="color: #0000ff">RETURN</span>  </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>   (  </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>     <span style="color: #0000ff">CONVERT</span>(DATETIME,  </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>           <span style="color: #0000ff">CONVERT</span>(NVARCHAR(4),@<span style="color: #0000ff">date</span> / 10000) + N<span style="color: #006080">'-'</span> +   </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>           <span style="color: #0000ff">CONVERT</span>(NVARCHAR(2),(@<span style="color: #0000ff">date</span> % 10000)/100)  + N<span style="color: #006080">'-'</span> +  </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>           <span style="color: #0000ff">CONVERT</span>(NVARCHAR(2),@<span style="color: #0000ff">date</span> % 100) + N<span style="color: #006080">' '</span> +          </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>           <span style="color: #0000ff">CONVERT</span>(NVARCHAR(2),@<span style="color: #0000ff">time</span> / 10000) + N<span style="color: #006080">':'</span> +          </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>           <span style="color: #0000ff">CONVERT</span>(NVARCHAR(2),(@<span style="color: #0000ff">time</span> % 10000)/100) + N<span style="color: #006080">':'</span> +          </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>           <span style="color: #0000ff">CONVERT</span>(NVARCHAR(2),@<span style="color: #0000ff">time</span> % 100),  </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>     120)  </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span>   )  </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span> <span style="color: #0000ff">END</span>  </pre>
<p><!--CRLF--></div>
</p></div>
</div>
<div dir="rtl" align="right">
<div dir="rtl" align="right">זוהי לא פונקציה מסובכת לכתיבה או להבנה, אך בהיותנו DBA חסכנים (שלא לומר עצלנים) טוב לדעת שקיימת פונקציה בכל שרת שתעזור לנו לנתח את מה שכתוב בטבלאות המערכת של ה Agent בלי להשקיע בכתיבה.</div>
<div dir="rtl" align="right">לדוגמא, על מנת להבין את הנתונים שמופיעים בטבלת sysjobhistory, נריץ את השאילתא הבאה:</div>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; height: 69px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">SELECT</span> </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> job_id,step_id,step_name,run_status,dbo.agent_datetime(run_date,run_time) <span style="color: #0000ff">AS</span> Run_DateTime,run_duration </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> <span style="color: #0000ff">FROM</span> msdb.dbo.sysjobhistory</pre>
<p><!--CRLF--></div>
</p></div>
<p><a href="http://www.madeira.co.il/wp-content/uploads/2011/08/image7.png" rel="wp-prettyPhoto[g2121]"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.madeira.co.il/wp-content/uploads/2011/08/image_thumb7.png" width="354" height="140" /></a></p>
</div>
<div dir="rtl" align="right">בצורה כזו הרבה יותר נוח לנתח את הנתונים, למיין אותם וכו’…</div>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/working-with-sqlagent-dateandtime/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8235;השורה שלפני והשורה שאחרי&#8211;הפונקציות LEAD ו LAG ב DENALI&#8236;</title>		<link>http://www.madeira.co.il/denali-lead-lag/</link>
		<comments>http://www.madeira.co.il/denali-lead-lag/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 07:45:46 +0000</pubDate>
		<dc:creator>&#8235;שי אנגלברג&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[Denali]]></category>
		<category><![CDATA[LAG]]></category>
		<category><![CDATA[LEAD]]></category>
		<category><![CDATA[OVER]]></category>
		<category><![CDATA[puzzles]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[What's New]]></category>
		<category><![CDATA[window functions]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=1991</guid>
		<description><![CDATA[&#8235;ב Denali, מצטרפות למשפחת הפקודות ב T-SQL שתי פקודות שמאפשרות לנו להצמיד לשורה ערכים משורה עוקבת או משורה קודמת- LEAD ו LAG.
כיום ישנן מספר שיטות לבצע זאת אשר כולן משתמשות בצורה כזו או אחרת ב Self-Join.
הפונקציות החדשות ב Denali מאפשרות לנו לעשות זאת בקלות ובביצועים גבוהים.&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/1991.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<div dir="rtl">
<div dir="rtl">לפני שאכנס לפונקציות החדשות ב Denali, הסבר קצר למה הכוונה ב”שורה שלפני והשורה שאחרי”.</div>
<div dir="rtl">לעיתים אנו מעוניינים להצמיד לשורה מסויימת ערכים מהשורה שמופיעה לפניה או אחריה, זאת בהסתמך על מיון מסויים.</div>
<div dir="rtl">גרי רשף כתב על כך לא מעט, לדוגמא <a href="http://www.sqlserver.co.il/?p=2974">כאן</a>.</div>
<div dir="rtl">כיום ישנן מספר שיטות לבצע זאת אשר כולן משתמשות בצורה כזו או אחרת ב Self-Join.</div>
<div dir="rtl">תחילה נעבור על השיטות שבהן השתמשנו עד היום כדי לעשות זאת.</div>
<div dir="rtl">לצורך ההדגמות, אשתמש בטבלת מכירות פשוטה.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"></div>
<div dir="rtl"><strong><span style="font-size: x-small;">סקריפט 1. יצירת הטבלה ומילוי נתונים ראשוני</span></strong></div>
<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;" id="codeSnippetWrapper">
<div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;" id="codeSnippet">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum1">   1:</span> <span style="color: #0000ff;">CREATE</span> <span style="color: #0000ff;">TABLE</span> Sales(</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum2">   2:</span>     SalesPersonID <span style="color: #0000ff;">INT</span> <span style="color: #0000ff;">NOT</span> <span style="color: #0000ff;">NULL</span>,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum3">   3:</span>     SaleDay <span style="color: #0000ff;">Date</span> <span style="color: #0000ff;">NOT</span> <span style="color: #0000ff;">NULL</span>,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum4">   4:</span>     TotalDue <span style="color: #0000ff;">Decimal</span>(8,2) <span style="color: #0000ff;">NOT</span> <span style="color: #0000ff;">NULL</span>)</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum5">   5:</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum6">   6:</span> INSERT <span style="color: #0000ff;">INTO</span> Sales(SalesPersonID,SaleDay,TotalDue)</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum7">   7:</span> <span style="color: #0000ff;">VALUES</span>(1,<span style="color: #006080;">'2010-01-01'</span>,1442.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum8">   8:</span> (1,<span style="color: #006080;">'2010-01-15'</span>,1521.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum9">   9:</span> (1,<span style="color: #006080;">'2010-01-18'</span>,22.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum10">  10:</span> (1,<span style="color: #006080;">'2010-03-21'</span>,3792.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum11">  11:</span> (1,<span style="color: #006080;">'2010-04-01'</span>,1690.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum12">  12:</span> (1,<span style="color: #006080;">'2010-05-24'</span>,1670.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum13">  13:</span> (1,<span style="color: #006080;">'2010-11-13'</span>,1211.50)</pre>
<p><!--CRLF--></p>
</div>
</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl">ב SQL 2000 השתמשנו ב SubQuery על מנת לבצע זאת.</div>
<div dir="rtl">בדוגמא הראשונה אני אשלוף עבור איש המכירות את נתוני המכירה לכל יום ואצמיד להם את נתוני המכירה מהיום הקודם. כך נוכל להשוות את השינויים בין המכירות ועוד.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"></div>
<div dir="rtl"><strong><span style="font-size: x-small;">סקריפט 2. SQL 2000 – שימוש ב SubQuery</span></strong></div>
</div>
<div dir="rtl">
<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;" id="codeSnippetWrapper">
<div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;" id="codeSnippet">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum1">   1:</span> <span style="color: #0000ff;">SELECT</span>    a.SalesPersonID,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum2">   2:</span>         a.SaleDay,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum3">   3:</span>         a.TotalDue,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum4">   4:</span>         (</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum5">   5:</span>             <span style="color: #0000ff;">SELECT</span> <span style="color: #0000ff;">TOP</span> 1</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum6">   6:</span>                 TotalDue</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum7">   7:</span>              <span style="color: #0000ff;">FROM</span> Sales b</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum8">   8:</span>              <span style="color: #0000ff;">WHERE</span> a.SaleDay&gt;b.SaleDay</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum9">   9:</span>              <span style="color: #0000ff;">ORDER</span> <span style="color: #0000ff;">BY</span> SaleDay <span style="color: #0000ff;">DESC</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum10">  10:</span>         ) <span style="color: #0000ff;">as</span> PrevDaySale</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum11">  11:</span> <span style="color: #0000ff;">FROM</span> Sales a</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum12">  12:</span> <span style="color: #0000ff;">ORDER</span> <span style="color: #0000ff;">BY</span> a.SaleDay</pre>
<p><!--CRLF--></p>
</div>
</div>
<p><a href="http://www.madeira.co.il/wp-content/uploads/2011/08/image.png" rel="wp-prettyPhoto[g1991]"><img title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" src="http://www.madeira.co.il/wp-content/uploads/2011/08/image_thumb.png" border="0" alt="image" width="354" height="173" /></a></p>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl">בדוגמא הזו אנו שולפים בשאילתא הפנימית באמצעות TOP 1 ORDER BY את  השורה הראשונה אשר התאריך בה קטן מהערך בשאילתא החיצונית כאשר ממיינים מהגדול לקטן.</div>
<div dir="rtl">זאת אומרת, עבור כל שורה בשאילתא החיצונית באמצעות השאילתא הפנימית את התאריך המקסימלי אשר קטן מהתאריך החיצוני.</div>
<div dir="rtl">בכך, לכל תאריך בטבלה נצמיד את התאריך שבא לפניו.</div>
<div dir="rtl">השיטה הזו מסתבכת כאשר נכניס לטבלה נתונים של איש מכירות נוסף ואז נרצה לחלק את הנתונים שלנו לקבוצות. זאת אומרת, אני אמיין את הנתונים לפי התאריך,</div>
<div dir="rtl">אבל לכל שורה בשאילתא החיצונית אשתמש בשאילתא הפנימית רק בשורות המתאימות לאיש המכירות מהשורה החיצונית.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"></div>
<div dir="rtl"><strong><span style="font-size: x-small;">סקריפט 3א. הכנסת נתונים של איש מכירות נוסף</span></strong></div>
<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;" id="codeSnippetWrapper">
<div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;" id="codeSnippet">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum1">   1:</span> INSERT <span style="color: #0000ff;">INTO</span> Sales(SalesPersonID,SaleDay,TotalDue)</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum2">   2:</span> <span style="color: #0000ff;">VALUES</span>(2,<span style="color: #006080;">'2010-01-02'</span>,1452.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum3">   3:</span> (2,<span style="color: #006080;">'2010-01-16'</span>,1581.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum4">   4:</span> (2,<span style="color: #006080;">'2010-01-19'</span>,2218.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum5">   5:</span> (2,<span style="color: #006080;">'2010-03-22'</span>,3892.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum6">   6:</span> (2,<span style="color: #006080;">'2010-04-02'</span>,6690.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum7">   7:</span> (2,<span style="color: #006080;">'2010-05-25'</span>,3670.50),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum8">   8:</span> (2,<span style="color: #006080;">'2010-11-15'</span>,1711.50)</pre>
<p><!--CRLF--></p>
</div>
</div>
<p><strong><span style="font-size: x-small;"> </span></strong></p>
<p><strong><span style="font-size: x-small;">סקריפט 3ב. SQL 2000 – שימוש ב SubQuery &#8211; מיון על פי עמודה וחלוקה לקבוצות</span></strong></p>
<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;" id="codeSnippetWrapper">
<div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;" id="codeSnippet">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum1">   1:</span> <span style="color: #0000ff;">SELECT</span>  a.SalesPersonID,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum2">   2:</span>         a.SaleDay,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum3">   3:</span>         a.TotalDue,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum4">   4:</span>         (</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum5">   5:</span>             <span style="color: #0000ff;">SELECT</span> <span style="color: #0000ff;">TOP</span> 1</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum6">   6:</span>                 TotalDue</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum7">   7:</span>              <span style="color: #0000ff;">FROM</span> Sales b</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum8">   8:</span>              <span style="color: #0000ff;">WHERE</span> a.SaleDay&gt;b.SaleDay <span style="color: #0000ff;">and</span> a.SalesPersonID=b.SalesPersonID</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum9">   9:</span>              <span style="color: #0000ff;">ORDER</span> <span style="color: #0000ff;">BY</span> SaleDay <span style="color: #0000ff;">DESC</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum10">  10:</span>         ) <span style="color: #0000ff;">AS</span> PrevDaySale</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum11">  11:</span> <span style="color: #0000ff;">FROM</span> Sales a</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum12">  12:</span> <span style="color: #0000ff;">ORDER</span> <span style="color: #0000ff;">BY</span> a.SalesPersonID,a.SaleDay</pre>
<p><!--CRLF--></p>
</div>
</div>
<p><a href="http://www.madeira.co.il/wp-content/uploads/2011/08/image1.png" rel="wp-prettyPhoto[g1991]"><img title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" src="http://www.madeira.co.il/wp-content/uploads/2011/08/image_thumb1.png" border="0" alt="image" width="354" height="303" /></a></p>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl">ב SQL 2005 הוצגו בפנינו ה Ranking functions ובהן ROW_NUMBER השימושית.</div>
<div dir="rtl">באמצעות הפונקציה הזו ניתן לבצע את ההצמדה בין שורה לשורה שלפניה/ אחריה ביתר קלות-</div>
<div dir="rtl">הפונקציה מעניקה לכל שורה “מספר שורה” לפי מיקומה על פי המיון.</div>
<div dir="rtl">באמצעות מספר השורה נוכל להצמיד בקלות  לכל מספר שורה את מספר השורה הגדול/ קטן ממנו באחד.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"></div>
<div dir="rtl"><strong><span style="font-size: x-small;">סקריפט 4. SQL 2005 – שימוש ב ROW_NUMBER</span></strong></div>
<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;" id="codeSnippetWrapper">
<div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;" id="codeSnippet">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum1">   1:</span> <span style="color: #0000ff;">WITH</span> CTE <span style="color: #0000ff;">AS</span> (</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum2">   2:</span>     <span style="color: #0000ff;">SELECT</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum3">   3:</span>         a.SalesPersonID,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum4">   4:</span>         a.SaleDay,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum5">   5:</span>         a.TotalDue,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum6">   6:</span>         ROW_NUMBER() <span style="color: #0000ff;">OVER</span> (PARTITION <span style="color: #0000ff;">BY</span> SalesPersonID <span style="color: #0000ff;">ORDER</span> <span style="color: #0000ff;">BY</span> SaleDay) <span style="color: #0000ff;">AS</span> RowNum</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum7">   7:</span> <span style="color: #0000ff;">FROM</span> Sales a</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum8">   8:</span> )</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum9">   9:</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum10">  10:</span> <span style="color: #0000ff;">SELECT</span> a.SalesPersonID,a.SaleDay,a.TotalDue,b.TotalDue <span style="color: #0000ff;">as</span> PrevDaySale</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum11">  11:</span> <span style="color: #0000ff;">FROM</span> CTE a</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum12">  12:</span> <span style="color: #0000ff;">LEFT</span> <span style="color: #0000ff;">JOIN</span> CTE b</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum13">  13:</span> <span style="color: #0000ff;">ON</span> a.RowNum-1=b.RowNum</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum14">  14:</span> <span style="color: #0000ff;">AND</span> a.SalesPersonID=b.SalesPersonID</pre>
<p><!--CRLF--></p>
</div>
</div>
</div>
<p dir="rtl"><a href="http://www.madeira.co.il/wp-content/uploads/2011/08/image2.png" rel="wp-prettyPhoto[g1991]"><img title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" src="http://www.madeira.co.il/wp-content/uploads/2011/08/image_thumb2.png" border="0" alt="image" width="354" height="304" /></a></p>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl">בדוגמא זו אני מגדיר CTE המכיל את עמודת איש המכירות, סכום המכירה ומכיל עמודה נוספת שמכילה את תוצאת הפונקציה ROW_NUMBER.</div>
<div dir="rtl">פונקציית ה ROW_NUMBER מחלקת מספרי שורה על פי מיון של עמודת התאריך ומחלקת לקבוצות על סמך עמודת איש המכירות.</div>
<div dir="rtl">לאחר מכן, אני מבצע Self-join על CTE זה, כאשר תנאי השוויון בין שני המופעים הוא: מספר השורה במופע הראשון פחות אחד שווה למספר השורה במופע השני.</div>
<div dir="rtl">כך לכל שורה אני מצמיד את השורה שלפניה.</div>
<div dir="rtl">תנאי נוסף ב join מגדיר שאיש המכירות צריך להיות זהה.</div>
<div dir="rtl">שימו לב, על מנת לראות גם את השורות הראשונות בכל קבוצה שאין לפניהן שורה (אין שורה עם “מספר שורה” 0) נשתמש ב  Outer join.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"></div>
<div dir="rtl"><strong>הפונקציות החדשות ב Denali</strong></div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"></div>
<div dir="rtl">בגרסא הבאה של SQL, שבינתיים נקראת Denali, מצטרפות למשפחת הפקודות ב T-SQL שתי פקודות שמאפשרות לנו להצמיד לשורה ערכים משורה עוקבת או משורה קודמת.</div>
<div dir="rtl">הפקודות האלו מוכרות לכל מי שהשתמש ב ORACLE ומוכיחות כמה מהר נסגרים הפערים (מהר? לאט?)</div>
<div dir="rtl">הפונקציות נקראות <strong>LAG</strong> ו <strong>LEAD </strong>והן זהות מבחינת התחביר שלהן. ההבדל ביניהן הוא, כמו שהשמות מרמזים, שאחת מהפונקציות מצמידה שורה קודמת והשנייה מצמידה שורה עוקבת.</div>
<div dir="rtl">הפונקציה יכולה להופיע ברשימת ה SELECT ו/או ב ORDER BY, היא לא יכולה להופיע ב WHERE או ב GROUP BY.</div>
<div dir="rtl">מבנה הפונקציה הוא:</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"></div>
<div dir="rtl"><a href="http://www.madeira.co.il/wp-content/uploads/2011/08/image41.png" rel="wp-prettyPhoto[g1991]"><img title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" src="http://www.madeira.co.il/wp-content/uploads/2011/08/image4_thumb.png" border="0" alt="image" width="454" height="53" /></a></div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"></div>
<div dir="rtl">Scalar_expression – הביטוי שאותו מחזירה הפונקציה בהתחשב ב offset. בדרך כלל מכיל שם עמודה, כאשר הערך המוחזר הוא מהשורה העוקבת\ קודמת, זאת שהצמדנו לשורה הנוכחית.</div>
<div dir="rtl">offset – המרחק של השורה שאנו רוצים להצמיד מהשורה הנוכחית. ברירת המחדל היא 1.</div>
<div dir="rtl">default – מגדיר איזה ערך יוחזר במידה ולא קיימת שורה במרחק offset מהשורה הנוכחית. ברירת המחדל היא NULL.</div>
<div dir="rtl">OVER – כמו בפונקציית ה ROW_NUMBER תפקידו להגדיר את העמודות לפיהן יבוצע מיון השורות. אם נרצה בכך, נשתמש  בו גם כדי להגדיר את החלוקה לקבוצות.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl">הערת ביניים – פקודת ה OVER הורחבה מאוד ב Denali ומאפשרת לנו לבצע חישובים שבעבר היה מסובך לעשות. עוד על כך בפעם אחרת.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl">בואו נראה איך מחזירים את אותן התוצאות מהשיטות הקודמות באמצעות הפקודות החדשות של Denali</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"><strong><span style="font-size: x-small;">סקריפט 5. SQL Denali – שימוש ב LAG</span></strong></div>
<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;" id="codeSnippetWrapper">
<div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;" id="codeSnippet">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum1">   1:</span> <span style="color: #0000ff;">SELECT</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum2">   2:</span>     SalesPersonID,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum3">   3:</span>     SaleDay,TotalDue,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum4">   4:</span>     LAG(TotalDue,1,0) <span style="color: #0000ff;">OVER</span> (PARTITION <span style="color: #0000ff;">BY</span> SalesPersonID <span style="color: #0000ff;">ORDER</span> <span style="color: #0000ff;">BY</span> SaleDay) <span style="color: #0000ff;">AS</span> PrevDaySale</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum5">   5:</span> <span style="color: #0000ff;">FROM</span> Sales</pre>
<p><!--CRLF--></p>
</div>
</div>
<div dir="rtl"><a href="http://www.madeira.co.il/wp-content/uploads/2011/08/image4.png" rel="wp-prettyPhoto[g1991]"><img title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" src="http://www.madeira.co.il/wp-content/uploads/2011/08/image_thumb4.png" border="0" alt="image" width="354" height="307" /></a></div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"></div>
<div dir="rtl">בשאילתא זו השתמשתי בפונקציה LAG על מנת להצמיד לכל שורה את השורה שלפניה.</div>
<div dir="rtl">אסביר בקצרה את השאילתא:</div>
<div dir="rtl">הפרמטר הראשון בפונקציית ה LAG הוא הביטוי שמגדיר איזה נתון אני רוצה להחזיר מהשורה שלפניי. במקרה הזה אני אחזיר את הערך שבעמודת ה TotalDue.</div>
<div dir="rtl">הפרמטר השני בפונקציה הוא המרחק של השורה אותה אני רוצה להצמיד מהשורה הנוכחית, במקרה הזה 1.</div>
<div dir="rtl">הפרמטר השלישי מגדיר איזה ערך תחזיר הפונקציה אם לא קיימת שורה לפניי ( במרחק המוגדר בפרמטר השני ), במקרה הזה אחזיר 0.</div>
<div dir="rtl">לאחר מכן, באמצעות פקודת ה OVER אגדיר את העמודות לפיהן אמיין את הנתונים ואת העמודות לפיהן אחלק את הנתונים לקבוצות, במקרה הזה החלוקה לקבוצות מתבצעת לפי איש המכירות והמיון מתבצע לפי תאריך המכירה.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl">כך, ללא צורך ב Self-join החזרתי את אותן תוצאות כמו קודם, אך עם מספר יתרונות שמספקות לנו הפונקציות החדשות:</div>
<ul dir="rtl">
<li>
<div>ביצועים – בפונקציות אלו אנו ניגשים לטבלה רק פעם אחת (בניגוד לשיטות הקודמות)</div>
</li>
<li>
<div>קוד נקי וקריא – בלא צורך ב self-join ועם שימוש בפונקציה אחת בלבד, הקוד קריא ומובן יותר.</div>
</li>
</ul>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl">אך יש לפונקציות אלו גם חסרונות (או יותר נכון, חולשות) – הן פועלות על ה Resultset שחוזר מתוצאת ה Select, ז”א שהשורה שאותה ברצוני להצמיד חייבת לחזור בתוצאת ה select בנוסף לשורה אליה אני מצמיד.</div>
<div dir="rtl">כך שאם ברצוני להחזיר רק שורה אחת עם שורה מוצמדת אליה, לא אוכל לסנן את הנתונים שלי באמצעות WHERE כך שיכילו רק את השורה שברצוני להחזיר,</div>
<div dir="rtl">אלא עליי להחזיר ב WHERE גם את השורה שברצוני להצמיד.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"></div>
<div dir="rtl"><strong><span style="font-size: x-small;"> </span></strong></div>
<div dir="rtl"><strong><span style="font-size: x-small;">סקריפט 6. SQL Denali – שימוש ב LAG מחזיר תוצאה לא רצויה</span></strong></div>
<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;" id="codeSnippetWrapper">
<div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;" id="codeSnippet">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum1">   1:</span> <span style="color: #0000ff;">SELECT</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum2">   2:</span>     SalesPersonID,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum3">   3:</span>     SaleDay,TotalDue,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum4">   4:</span>     LAG(TotalDue,1,0) <span style="color: #0000ff;">OVER</span> (PARTITION <span style="color: #0000ff;">BY</span> SalesPersonID <span style="color: #0000ff;">ORDER</span> <span style="color: #0000ff;">BY</span> SaleDay) <span style="color: #0000ff;">AS</span> PrevDaySale</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #606060;" id="lnum5">   5:</span> <span style="color: #0000ff;">FROM</span> Sales</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #606060;" id="lnum6">   6:</span> <span style="color: #0000ff;">WHERE</span> SalesPersonID=1 <span style="color: #0000ff;">AND</span> SaleDay=<span style="color: #006080;">'2010-01-15'</span></pre>
<p><!--CRLF--></p>
</div>
</div>
<div dir="rtl">
<div dir="rtl"><a href="http://www.madeira.co.il/wp-content/uploads/2011/08/image5.png" rel="wp-prettyPhoto[g1991]"><img title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" src="http://www.madeira.co.il/wp-content/uploads/2011/08/image_thumb5.png" border="0" alt="image" width="354" height="51" /></a></div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl"></div>
<div dir="rtl">לדוגמא, בשאילתא זו אני מבקש להחזיר רק את ערכי המכירה של איש מכירות מספר 1 מתאריך 2010-01-15.</div>
<div dir="rtl">אני מבקש להצמיד לשורה זו את נתוני המכירה מהיום שלפני.</div>
<div dir="rtl">אך, למרבה ההפתעה, למרות שאני יודע שהיו מכירות מוקדמות יותר ממכירה זו, אני מקבל בשדה PrevDaySale את הערך 0 – שהוא ערך ברירת המחדל בפונקציית ה LAG למקרה שלא קיימת שורה מתאימה במרחק המבוקש.</div>
<div dir="rtl">כאן ניתן לראות בבירור שאם השורה המוצמדת לא חוזרת ב Select, לא ניתן להצמידה לשום שורה.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl">אגב, החזרת רק שורה אחת עם השורה שמוצמדת אליה היא פעולה פשוטה ביותר לביצוע בכל אחת מהשיטות הקודמות עליהן דיברתי.</div>
<div dir="rtl"></div>
<div dir="rtl"><strong>לסיכום,</strong></div>
<div dir="rtl">הפונצקיות החדשות LAG ו LEAD מסייעות לנו בביצוע פעולות שבעבר דרשו פיתוח ארוך ומסובך יותר.</div>
<div dir="rtl">הן מאפשרות לנו גמישות רבה יותר בביצוע פעולות אלו וביצועים גבוהים יותר.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl">לכל מי שמעוניין בעוד מידע,</div>
<div dir="rtl">במפגש ה ISUG שייערך בספטמבר, אעביר הרצאה מעמיקה בנושא החידושים ב Denali.</div>
<div dir="rtl">כחלק מההרצאה אתעמק בנושא הביצועים של הפונקציות הנ”ל.</div>
<div dir="rtl">כולכם מוזמנים להגיע ולשמוע כמובן.</div>
<p dir="rtl">
<div dir="rtl"></div>
<div dir="rtl">אשמח לשמוע ביקורות, הערות ושאלות.</div>
</div>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/denali-lead-lag/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8235;What&#8217;s new in SQL Server 2008 R2 SP1&#8236;</title>		<link>http://www.madeira.co.il/whats-new-in-sql-server-2008-r2-sp1/</link>
		<comments>http://www.madeira.co.il/whats-new-in-sql-server-2008-r2-sp1/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 07:09:51 +0000</pubDate>
		<dc:creator>&#8235;שי אנגלברג&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[2008 R2]]></category>
		<category><![CDATA[DMV]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[SP1]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=1935</guid>
		<description><![CDATA[&#8235;שבוע שעבר שוחרר ה SP1 של 2008 R2.
יחד עם תיקוני הבאגים נוספו גם המון דברים חדשים- הנה רשימה של המעניינים שבהם.&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/1935.png&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="rtl">ביום רביעי בשבוע שעבר התבשרנו על חידושים ושחרורים רבים ב SQL.</p>
<p dir="rtl">השחרור עליו אני רוצה לדבר הפעם הוא של SP1 ל R2 2008.</p>
<p dir="rtl">את ה-SP ניתן להוריד <a href="http://www.microsoft.com/download/en/details.aspx?id=26727">כאן</a>.</p>
<p dir="rtl">את רשימת הבאגים שתוקנו ניתן למצוא <a href="http://support.microsoft.com/?kbid=2528583">כאן</a>.</p>
<p dir="rtl">
<p dir="rtl">אני רוצה להציג כמה חידושים שנוספו בגרסא זו:</p>
<p dir="rtl"><strong>1) </strong><a href="http://msdn.microsoft.com/en-us/library/ms187373.aspx"><strong>ForceSeek</strong></a></p>
<p dir="rtl">זהו table hint אשר קיים כבר מגרסת 2008.</p>
<p dir="rtl">השימוש בו מכריח את האופטימייזר לעשות seek על טבלה (או אינדקס) במקום לבצע scan.</p>
<p dir="rtl">הוא יעיל בעיקר במצבים בהם האופטימייזר לא מעריך נכון את כמות הרשומות שתחזור וחושב שיחזרו יותר רשומות מאשר באמת חוזרות (קורה הרבה בעבודה עם FTS)</p>
<p dir="rtl">במקרה כזה האופטימייזר מחליט לעיתים לעשות scan על הטבלה במקום seek.</p>
<p dir="rtl">החידוש ב SP הזה הוא שכעת ניתן להגדיר ל hint פרמטרים שאומרים על איזה אינדקס לעשות את ה seek ובאמצעות אילו עמודות.</p>
<p dir="rtl">כמובן שלהתערבות כל כך בוטה באופטימייזר יש את ההשלכות וההגבלות שלה, ואלו הן:</p>
<div dir="rtl">
<ol>
<li>לא ניתן להשתמש ב hint הזה על טבלאות מרוחקות.</li>
<li>יכול להיות שהשימוש בו יגרום לכך שלא תימצא שום PLAN לביצוע השאילתא- במקרה כזה נקבל ERROR.</li>
<li>כאשר מספקים לו כפרמטר את שם האינדקס, חובה לספק לפחות שם של עמודה אחת עליה יבוצע החיפוש, העמודה חייבת להיות חלק מהאינדקס.</li>
<li>ניתן לספק יותר משם של עמודה אחת, אך הן חייבות להופיע לפי הסדר שבו הן מופיעות באינדקס ולא ניתן לדלג על עמודות.<br />
ז&quot;א אם אינדקס בנוי על עמודות A,B,C בסדר הזה, אז ב hint נהיה חייבים לציין את העמודות החל מ &#8211; A ומשם נהיה חייבים להכניס את העמודות הבאות בלי לדלג על אף עמודה, כך:</li>
</ol>
</div>
<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; height: 92px; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;">
<div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;">   1:</span> -<span style="color: #008000;">-- Only the first column</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;">   2:</span> FORCESEEK (MyIndex (a))</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;">   3:</span> -<span style="color: #008000;">-- Or with the column that comes right after</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;">   4:</span> FORCESEEK (MyIndex (a, b))</pre>
<p><!--CRLF--></p>
</div>
</div>
<p dir="rtl">
<p dir="rtl">אך לא ניתן לעשות כך:</p>
<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;">
<div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #008000;">-- using only the third column </span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;">   2:</span> FORCESEEK (MyIndex (c))</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;">   3:</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;">   4:</span> <span style="color: #008000;">-- skipping a clolumn in the index</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;">   5:</span> <span style="color: #0000ff;">and</span> FORCESEEK (MyIndex (a, c))</pre>
<p><!--CRLF--></p>
</div>
</div>
<p dir="rtl"><strong>2) ForceScan</strong></p>
<p dir="rtl">זהו hint חדש שמטרתו להכריח את האופטימייזר להשתמש ב scan במקום ב seek. גם כאן כמו ב forceseek השימוש יעיל בעיקר כשהאופטימיזר מעריך שיחזרו פחות רשומות מאשר באמת חוזרות.</p>
<p dir="rtl">מיותר לציין שלא ניתן להשתמש בשני ה hints האלו ביחד.</p>
<p dir="rtl">
<p dir="rtl">עד כאן לגבי hints, עכשיו בוא נעבר למעט DMV חדשים שיכולים להקל עלינו את החיים בהרבה משימות:</p>
<p dir="rtl">
<p dir="rtl"><strong>3) </strong><a href="http://msdn.microsoft.com/en-us/library/hh223223.aspx"><strong>sys.dm_os_volume_stats</strong></a></p>
<p dir="rtl">זוהי פונקצית ניהול חדשה (DMF &#8211; Dynamic Management Function) אשר מקבלת כפרמטרים את ה Database_Id ואת ה File_Id של קבצים (קבצי DB כמובן, LDF ו MDF)</p>
<p dir="rtl">ומספקת לנו נתונים אודות ה VOLUME עליו יושב הקובץ הזה – הכוונה ב VOLUME היא התיקייה בתוכה נמצא הקובץ.</p>
<p dir="rtl">אם נפעיל את הפונקציה הזו בעזרת CROSS APLLY על sys.master_files נוכל לקבל את הנתונים הנ&quot;ל לגבי כל הקבצים של כל ה DBs ב instance שלנו.</p>
<p dir="rtl">
<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;">
<div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #0000ff;">SELECT</span></pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;">   2:</span> DB_NAME(f.database_id),</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;">   3:</span> f.physical_name,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;">   4:</span> f.<span style="color: #0000ff;">size</span>,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;">   5:</span> f.growth,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;">   6:</span> f.is_percent_growth,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;">   7:</span> vs.file_system_type,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;">   8:</span> vs.total_bytes,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;">   9:</span> vs.available_bytes,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;">  10:</span> vs.is_compressed,</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;">  11:</span> vs.is_read_only</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;">  12:</span> <span style="color: #0000ff;">FROM</span>   sys.master_files <span style="color: #0000ff;">AS</span> f</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;">  13:</span> <span style="color: #0000ff;">CROSS</span> APPLY   sys.dm_os_volume_stats(f.database_id, f.file_id) <span style="color: #0000ff;">AS</span> vs</pre>
<p><!--CRLF--></p>
</div>
</div>
<p dir="rtl">
<p dir="rtl"><a href="http://www.madeira.co.il/wp-content/uploads/2011/07/image8.png" rel="wp-prettyPhoto[g1935]"><img title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" src="http://www.madeira.co.il/wp-content/uploads/2011/07/image_thumb8.png" border="0" alt="image" width="475" height="96" /></a></p>
<p dir="rtl">
<p dir="rtl">(הקליקו על התמונה להגדלה)</p>
<p dir="rtl">הנתון העיקרי והחשוב ביותר שאנחנו מקבלים מהפונקציה הזו הוא הנתון לגבי המקום הפנוי בדיסק עליו יושב הקובץ.</p>
<p dir="rtl">בעבר על מנת לקבל את המידע הזה היינו צריכים להשתמש בפרוצדורה xp_fixeddrives אשר דרשה הרשאות sysadmin והחזירה את המקום הפנוי בשביל כל אות כונן על השרת שלנו.</p>
<p dir="rtl">כיום, באמצעות הפונקציה הזו לא רק שניתן לדעת את המקום הפנוי בשביל כל קובץ (בלי לעשות מניפולציות על השם שלו כדי להוציא את אות הכונן),</p>
<p dir="rtl">אלא מעבר לכך, אם הקובץ נמצא מתחת ל mount point, נקבל את המקום הפנוי בדיסק עליו הקובץ יושב בצורה פיזית.</p>
<p dir="rtl">באמצעות הנתונים על Auto growth של הקבצים שקיימים ב sys.master_files אפשר לחשב בקלות עוד כמה מקום יש לקובץ לגדול אם בכלל, ולהוציא התרעות על סמך נתונים אלו.</p>
<p dir="rtl">בנוסף אפשר לדעת האם הדיסק עליו יושב הקובץ דחוס, איזה fie system בשימוש ועוד.</p>
<p dir="rtl">
<p dir="rtl"><strong>4) </strong><a href="http://msdn.microsoft.com/en-us/library/hh204561.aspx"><strong>sys.dm_server_registry</strong></a></p>
<p dir="rtl">זוכרים איך שפעם בשביל לקרוא נתונים מהרג'יסטרי היינו צריכים להשתמש ב master.dbo.xp_regread שהיא פרוצדורה לא מתועדת?</p>
<p dir="rtl">אז עכשיו כבר לא צריך.</p>
<p dir="rtl">בעזרת ה DMV החדש ניתן לגשת לכל מידע מה Registry שקשור ל Instance (כן, רק למידע ששייך ל SQL, זה סוג של חיסרון)</p>
<p dir="rtl">אבל עכשיו ניתן לדעת בקלות מה ה STARTUP PARAMETERS, לאיזה פורט מאזין האינסטנס ועוד.</p>
<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;">
<div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #0000ff;">SELECT</span>    registry_key,   value_name,   value_data</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;">   2:</span> <span style="color: #0000ff;">FROM</span>   sys.dm_server_registry</pre>
<p><!--CRLF--></p>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;">   3:</span> <span style="color: #0000ff;">WHERE</span> registry_key <span style="color: #0000ff;">LIKE</span> <span style="color: #006080;">'%Tcp\IPAll%'</span></pre>
<p><!--CRLF--></p>
</div>
</div>
<p><a href="http://www.madeira.co.il/wp-content/uploads/2011/07/image9.png" rel="wp-prettyPhoto[g1935]"><img title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" src="http://www.madeira.co.il/wp-content/uploads/2011/07/image_thumb9.png" border="0" alt="image" width="449" height="58" /></a></p>
<p dir="rtl">(הקליקו על התמונה להגדלה)</p>
<p dir="rtl">
<p dir="rtl"><strong>5) </strong><a href="http://msdn.microsoft.com/en-us/library/hh204542.aspx"><strong>sys.dm_server_services</strong></a></p>
<p dir="rtl">בעזרת View זה ניתן לקבל מידע על כל ה services שקשורים ל Instance שאליו אנו מחוברים.</p>
<p dir="rtl">אפשר לראות האם service רץ, באיזה מצב של הפעלה הוא, באיזה PROCESSID הוא רץ, מה היוזר שמריץ אותו והאם הוא קלאסטרד.</p>
<p dir="rtl">זה נוח לצרכים של Troubleshoot כאשר אנחנו לא מחוברים פיזית למכונה, אבל רוצים לקבל נתונים לגבי ה services- למשל בדיקה האם ה Agent רץ לפני שמנסים להפעיל ג’וב.</p>
<p dir="rtl">
<p dir="rtl"><a href="http://www.madeira.co.il/wp-content/uploads/2011/07/image10.png" rel="wp-prettyPhoto[g1935]"><img title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" src="http://www.madeira.co.il/wp-content/uploads/2011/07/image_thumb10.png" border="0" alt="image" width="428" height="25" /></a></p>
<p dir="rtl">(הקליקו על התמונה להגדלה)</p>
<p dir="rtl">
<p dir="rtl"><strong>6) </strong><a href="http://msdn.microsoft.com/en-us/library/hh204565.aspx"><strong>sys.dm_os_windows_info</strong></a></p>
<p dir="rtl">מספק לנו נתונים לגבי מערכת ההפעלה שמותקנת על השרת.</p>
<p dir="rtl">
<p dir="rtl"><strong>7) </strong><a href="http://msdn.microsoft.com/en-us/library/ms189741.aspx"><strong>Sys.dm_exec_query_stats</strong></a></p>
<p dir="rtl">נוספו עמודות חדשות אשר מספקות מידע בנוגע לכמות השורות שחזרו במהלך הרצת השאילתא.</p>
<p dir="rtl">
<p dir="rtl">יש עוד כמה וכמה חידושים ותיקונים בגרסא הזו, כמו התמיכה במעל ל 1000 פרטישנים (שהוצגה כבר ב SP2 של 2008- <a href="http://msdn.microsoft.com/en-us/library/gg981694.aspx">מידע נוסף</a> )</p>
<p dir="rtl">אני ממליץ לכם לחקור ולבדוק אותם וכמובן שאשמח לשמוע תגובות ממי שהתקין, התנסה, שיחק וחקר.</p>
<p dir="rtl">בפעם הבאה אספר לכם על Denali CTP3 וכל מיני דברים טובים שהוא מכיל.</p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/whats-new-in-sql-server-2008-r2-sp1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>&#8235;My SQL Explore Lecture&#8236;</title>		<link>http://www.madeira.co.il/my-sql-explore-lecture/</link>
		<comments>http://www.madeira.co.il/my-sql-explore-lecture/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 09:19:10 +0000</pubDate>
		<dc:creator>&#8235;שי אנגלברג&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[הורדות]]></category>
		<category><![CDATA[כנסים ואירועים]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=1885</guid>
		<description><![CDATA[&#8235;I had the pleasure of giving the "Top 10 Features Every DBA Must Know" at the SQL Explore conference.  Here is a link to all the materials&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/1885.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="ltr">I had the pleasure of giving the &quot;Top 10 Features Every DBA Must Know&quot; at the SQL Explore conference.</p>
<p dir="ltr">For all of you who would like to go over the materials and make further use of them, please turn to: <a href="http://www.madeira.co.il/top-10-features-every-dba-must-know-sql-explore/">http://www.madeira.co.il/top-10-features-every-dba-must-know-sql-explore/</a></p>
<p dir="ltr">Good Luck!<br />
Shy</p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/my-sql-explore-lecture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8235;Top 10 Features Every DBA Must Know&#8236;</title>		<link>http://www.madeira.co.il/top-10-features-every-dba-must-know-sql-explore/</link>
		<comments>http://www.madeira.co.il/top-10-features-every-dba-must-know-sql-explore/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 09:06:24 +0000</pubDate>
		<dc:creator>&#8235;שי אנגלברג&#8236;</dc:creator>				<category><![CDATA[הורדות]]></category>
		<category><![CDATA[כנסים ואירועים]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=1881</guid>
		<description><![CDATA[&#8235;Attached are all the materials from the "Top 10 Features Every DBA Must Know" course that was presented at the SQL Explore conference&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><div id="_mcePaste" dir="ltr">Hi!</div>
<div id="_mcePaste" dir="ltr">Attached are all the materials from the &quot;Top 10 Features Every DBA Must Know&quot; course that was presented at the SQL Explore conference.</div>
<div id="_mcePaste" dir="ltr">I hope you find it handy and useful for your day to day work.</div>
<div dir="ltr">If any questions come up now or in the future, you're more than welcome to leave your comment on this post or on my personal blog.</div>
<div dir="ltr">Good luck!</div>
<div dir="ltr">Shy</div>
<div dir="ltr"></div>
<div dir="ltr">
<div id="attachment_679" class="wp-caption alignnone" style="width: 138px"><a href="http://www.madeira.co.il/wp-content/uploads/2011/07/Top-10-Features-Every-DBA-Must-Know.zip"><img class="size-full wp-image-679" title="zip" src="http://www.madeira.co.il/wp-content/uploads/2009/12/zip.png" alt="" width="128" height="128" /></a><p class="wp-caption-text">Press to Download</p></div>
</div>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/top-10-features-every-dba-must-know-sql-explore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8235;נעים מאוד, שי&#8236;</title>		<link>http://www.madeira.co.il/shy-engelberg-intro/</link>
		<comments>http://www.madeira.co.il/shy-engelberg-intro/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 09:10:52 +0000</pubDate>
		<dc:creator>&#8235;שי אנגלברג&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[להיות DBA]]></category>
		<category><![CDATA[קריירה]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=1834</guid>
		<description><![CDATA[&#8235;הכירו את שי אנגלברג, היועץ הטרי במדירה&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/1834.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>היי,<br />
נעים מאוד.</p>
<p>אני שי אנגלברג ואני שמח לכתוב פה לראשונה כחלק מהצוות של מדירה.<br />
אני מתעסק ב SQL SERVER כבר כ-5 שנים ולהפתעתי הרבה, התחום לא מפסיק לאתגר אותי כל פעם מחדש.</p>
<p>אני אשתדל לכתוב פה על אתגרים מעניינים שאני נתקל בהם, על פתרונות לבעיות מסובכות וסתם על דברים מעניינים שחקרתי או נתקלתי בהם.</p>
<p>אשמח תמיד לשמוע ביקורות, תגובות, בקשות, רעיונות וכו'.</p>
<p>ניפגש בקרוב,<br />
שי.</p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/shy-engelberg-intro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

