<rss version="2.0"><channel><title>beyondrelational.com</title><link>http://beyondrelational.com</link><description>beyondrelational.com rss feed</description><webMaster>beyondrelational</webMaster><language>en-us</language><image><url>http://beyondrelational.com/modules/23/groups/362/images/17021eb5-e554-4269-a990-37b1db2393c9thumbnail.jpg</url><title>beyondrelational.com</title><link>http://beyondrelational.com</link><width>50</width><height>50</height></image><copyright>Copyright © Beyondrelational.com</copyright><lastBuildDate>Wed, 19 Jun 2013 08:02:13 GMT</lastBuildDate><ttl>60</ttl><item><title>Cross-Database Computing at Will Is No Longer Miracle</title><link>http://beyondrelational.com/modules/2/blogs/925/posts/19527/cross-database-computing-at-will-is-no-longer-miracle.aspx</link><description>&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi" lang=EN-US&gt;Java language does not have any competitive advantages in data computing, in particular the massive &lt;A href="http://www.raqsoft.com/product-esproc"&gt;structural data computing&lt;/A&gt;. For example, according to the order detail computation, find out the sales persons who achieve the sales increase over 10% in consecutive 3 months.&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi" lang=EN-US&gt;Java does not have the related advanced function to implement this. So, only with its native capability, Java can hardly handle such computation, at the cost of a large amount of time and effort to implement the details in computation manually. For example, firstly, define classes and represent every piece of data with objects; secondly, use List to store multi-pieces of data; thirdly, use the nested multi-level loops to compute. Except the sorting algorithm, almost all massive data processing algorithms involved in the computation require implementing manually, such as aggregating, filtering, and grouping. Such computations usually involve the set computation and relation computation between massive data, or computation on relative positions between objects and object attributes. It takes great efforts to implement the underlying logics for these computations.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi" lang=EN-US&gt;That’s why we must improve the Java computational capability. We need a tool tailored for implementing the structural data computation easily!&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi" lang=EN-US&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi" lang=EN-US&gt;How about SQL? Not all Java application allows for using database. In addition, there are many databases in Txt/Excel, and sometimes, problems of computation across databases and code reuse may be encountered. Moreover, SQL is still not convenient for handling many computation cases.Take the above-mentioned computation for example. SQL is by no means convenient to compose:&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;01 WITH A AS &lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;02&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;(SELECT salesMan,month, amount/lag(amount)&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;03&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;OVER(PARTITION BY salesMan ORDER BY month)-1 rising_range&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;04&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;FROM sales),&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;05 &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;B AS &lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;06&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;(SELECT salesMan,&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;07&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CASE WHEN rising_range&amp;gt;=1.1 AND &lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;08&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;lag(rising_range) OVER(PARTITION BY salesMan&lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;09&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ORDER BY month)&amp;gt;=1.1 AND &lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;10&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;lag(rising_range,2) OVER(PARTITION BY salesMan&lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;11&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ORDER BY month)&amp;gt;=1.1&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;12&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;THEN 1 ELSE 0 END is_three_consecutive_month&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;13&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;FROM A)&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #17365d; mso-hansi-font-family: Calibri; mso-ascii-font-family: Calibri" lang=EN-US&gt;&lt;FONT face=Calibri&gt;14 SELECT DISTINCT salesMan FROM B WHERE is_three_consecutive_month=1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi" lang=EN-US&gt;In this case, esProc is the better choice.&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi" lang=EN-US&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi" lang=EN-US&gt;esProc is a &lt;A href="http://www.raqsoft.com/download.html"&gt;development tool&lt;/A&gt; for database computing, specializing in simplifying the complex computation and is quite convenient to integrate with Java. For esProc, the corresponding scripts are shown below:&lt;BR&gt;&lt;BR&gt;&lt;IMG src="http://api.ning.com/files/*HLEuecomY9cIeHL87kKv4eBtr0QqpiP26Y-zg0P15s98iVIu6W05V8WAqVivOOTe53LxnewmnQYUhoFx9YCNUnpwCMcJs3l/scriptinesProc_developmenttool.png"&gt;&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi" lang=EN-US&gt;esProc allows for the direct retrieval and computation across multiple databases, text files, and Excel sheets. Its grid-like cellset and agile syntax are especially designed for the massive structural data computation. The result can be output via JDBC directly. So, with esProc, the computational capability of Java is dramatically improved.In addition, by nature, esProc supports the computation across databases and the code reuse, with a set of very perfect debugging functions. No wonder that the development productivity in esProc is also superior to that in SQL.&lt;/SPAN&gt;&lt;SPAN lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/925/posts/19527/cross-database-computing-at-will-is-no-longer-miracle.aspx</guid><pubDate>Wed, 19 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Make capital letter the first character of each word in a sentence</title><link>http://beyondrelational.com/modules/2/blogs/557/posts/19525/make-capital-letter-the-first-character-of-each-word-in-a-sentence.aspx</link><description>&lt;P&gt;There are many questions on making/replacing the capital letter the first character of each word in a sentence in every forums. Find the below function for such cases without a loop. Hope this would help you...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=brush:sql&gt;
Create Function dbo.CapitalizeEachword ( @MyString varchar(max))

Returns nvarchar(Max)
As
Begin
	Declare @XML xml

	Set @XML =CAST( '&lt;Root&gt;&lt;Rows&gt;&lt;Row&gt;' + REPLACE(@MyString,' ','&lt;/Row&gt;&lt;/Rows&gt;&lt;Rows&gt;&lt;Row&gt;') + '&lt;/Row&gt;&lt;/Rows&gt;&lt;/Root&gt;' As XML)

	Return 
			(
			Stuff (
				(Select ' ' + Col
				From
				(
						Select Stuff(COL, 1,1, UPPER(Left(col,1))) As Col
						From 
							(
								Select X.p.value('Row[1]','nvarchar(200)') As col
								From @XML.nodes('/Root/Rows') As X(p)
							) X
				) Y
				For XML Path('')), 1, 1, '')
			)

End


Select dbo.CapitalizeEachword('This is an example of capitalize the each word in a sentence.')



&lt;/PRE&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/557/posts/19525/make-capital-letter-the-first-character-of-each-word-in-a-sentence.aspx</guid><pubDate>Wed, 19 Jun 2013 00:00:00 GMT</pubDate></item><item><title>what are Difference between DATALENGTH and LEN?</title><link>http://beyondrelational.com/modules/2/blogs/372/posts/19524/what-are-difference-between-datalength-and-len.aspx</link><description>&lt;div&gt;1) LEN- it returns the number of characters, not bytes, and it is return same output for regular character or Unicode character string.&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;it&amp;nbsp; remove trailing spaces&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;SELECT LEN(N'abc d ') &amp;nbsp;/*OUTPUT:5*/&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;2) DATALENGTH-returns the length of the input in terms of number of bytes and for Unicode character string, it will count 2 bytes&lt;/div&gt;&lt;div&gt;per character,&amp;nbsp;it&amp;nbsp;does not remove trailing spaces&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;SELECT&amp;nbsp;DATALENGTH(N'abc d ') &amp;nbsp;/*OUTPUT:12*/&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/372/posts/19524/what-are-difference-between-datalength-and-len.aspx</guid><pubDate>Tue, 18 Jun 2013 00:00:00 GMT</pubDate></item><item><title>#0273 - SQL Server - IDENTITY columns – Myths – IDENTITY columns cannot be added to existing tables – Part 02</title><link>http://beyondrelational.com/modules/2/blogs/77/posts/19518/0273-sql-server-identity-columns-myths-identity-columns-cannot-be-added-to-existing-tables-part-02.aspx</link><description>&lt;P&gt;As seen in the &lt;A href="http://beyondrelational.com/modules/2/blogs/77/posts/19516/0272-sql-server-identity-columns-myths-identity-columns-cannot-be-added-to-existing-tables-part-01.aspx"&gt;first part of this post&lt;/A&gt;, we can add IDENTITY columns to existing tables without any issue. &lt;A href="http://beyondrelational.com/modules/2/blogs/77/posts/19491/0265-sql-server-an-introduction-to-identity-columns.aspx"&gt;IDENTITY columns cannot be NULL&lt;/A&gt;.&amp;nbsp; Hence, when we add a new column as an IDENTITY column, every record existing in the table has to be assigned an IDENTITY value. So, the question arises that which record should be the first one to be assigned with the Identity seed, which record will be the second record and so on. In short:&lt;/P&gt;
&lt;BLOCKQUOTE style="MARGIN-RIGHT: 0px" dir=ltr&gt;
&lt;P&gt;How existing records are assigned the IDENTITY value?&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We saw in the &lt;A href="http://beyondrelational.com/modules/2/blogs/77/posts/19516/0272-sql-server-identity-columns-myths-identity-columns-cannot-be-added-to-existing-tables-part-01.aspx"&gt;first part&lt;/A&gt; of the post that because a table was ordered via a clustered primary key, the IDENTITY specification was directly applied in that order. However, when the table is a heap (i.e. does not have a clustered index defined on it and is therefore unordered), the IDENTITY values are assigned based on the order in which records were inserted into the table.&lt;/P&gt;
&lt;P&gt;The script and it’s results below prove this point.&lt;/P&gt;&lt;PRE class="brush: sql"&gt;USE tempdb;
GO

SET NOCOUNT ON;

--1. Prepare the environment
--   Create a table, and add some test data into it

--Safety Check
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

--Create a table, this time WITHOUT a Clustered Key
CREATE TABLE dbo.tIdentity (RecordId INT,
                            IdentityValue VARCHAR(20),
                            CONSTRAINT pk_tIdentityRecordId PRIMARY KEY NONCLUSTERED (RecordId)
                           );
GO

--2. Add some test data
INSERT INTO dbo.tIdentity (RecordId, IdentityValue)
VALUES (3, 'Three'),
       (5, 'Five'),
       (1, 'One'),
       (0, 'Zero'),
       (4, 'Four');
GO

--2b. As a test, inserting some interleaving data separately
INSERT INTO dbo.tIdentity (RecordId, IdentityValue)
VALUES (2, 'Two'),
       (6, 'Six');
GO

--3. Check the values inserted into the table
--   Observe the order of the records that come up in the results
SELECT RecordId, IdentityValue
FROM dbo.tIdentity;
GO

--4. Alter the table to add an IDENTITY Column
ALTER TABLE dbo.tIdentity
    ADD IdentityId INT IDENTITY(1,1);
GO    
    
--4. Check the values inserted into the table
--   Observe the order of the records that come up in the results
--   v/s the value of the IdentityId
SELECT RecordId, IdentityId, IdentityValue
FROM dbo.tIdentity;
GO

----4b.One may also want to check the value of IDENT_CURRENT
--SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValueAfterDBCC;
--GO

/**********************************************
               RESULTS
**********************************************/
/*
RecordId    IdentityValue
----------- --------------
3           Three
5           Five
1           One
0           Zero
4           Four
2           Two
6           Six

RecordId    IdentityId  IdentityValue
----------- ----------- --------------
3           4           Three
5           6           Five
1           2           One
0           1           Zero
4           5           Four
2           3           Two
6           7           Six
*/
&lt;/PRE&gt;
&lt;P&gt;Now, let us define a CLUSTERED INDEX on this table such that the records are re-arranged. Once the clustered index is defined, we will insert a couple of records and then look at the assignment of the IDENTITY column. We can see that IDENTITY values continue to be assigned in the order in which records are inserted, however, the records are now ordered based on the clustered index specification.&lt;/P&gt;&lt;PRE class="brush: sql"&gt;USE tempdb;
GO

-- 5. Define a clustered index for the Primary Key
ALTER TABLE dbo.tIdentity
    DROP CONSTRAINT pk_tIdentityRecordId;
GO

ALTER TABLE dbo.tIdentity
    ADD CONSTRAINT pk_tIdentityRecordId PRIMARY KEY CLUSTERED (RecordId);
GO

--6. As a test, inserting some interleaving data separately
INSERT INTO dbo.tIdentity (RecordId, IdentityValue)
VALUES (-1, 'Minus One'),
       (7, 'Seven'),
       (8, 'Eight');
GO

--7. Check the values inserted into the table
--   Observe the order of the records that come up in the results
--   v/s the value of the IdentityId
SELECT RecordId, IdentityId, IdentityValue
FROM dbo.tIdentity;
GO

----7b.One may also want to check the value of IDENT_CURRENT
--SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValueAfterDBCC;
--GO  

--4. Cleanup
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

/**********************************************
               RESULTS
**********************************************/
/*
RecordId    IdentityId  IdentityValue
----------- ----------- --------------
-1          8           Minus One
0           1           Zero
1           2           One
2           3           Two
3           4           Three
4           5           Four
5           6           Five
6           7           Six
7           9           Seven
8           10          Eight
*/
&lt;/PRE&gt;
&lt;H2&gt;Conclusion (Part 02)&lt;/H2&gt;
&lt;P&gt;The behavior of IDENTITY columns and of SQL Server seen in this post is quite interesting – IDENTITY values are always generated in the order in which the records are inserted. When adding IDENTITY column to an existing table, this is true only if the table is not ordered, i.e. does not have a clustered index. Once the IDENTITY values have been assigned to all existing records in the table, all future values will be generated in the order of insertion.&lt;/P&gt;
&lt;P&gt;Until we meet next time, &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;A href="http://www.cars.com/go/advice/Story.jsp?section=top&amp;amp;subject=more&amp;amp;story=top10annoying&amp;amp;referer&amp;amp;year&amp;amp;aff=national"&gt;&lt;STRONG&gt;&lt;FONT color=#3366cc&gt;Be courteous. Drive responsibly.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/77/posts/19518/0273-sql-server-identity-columns-myths-identity-columns-cannot-be-added-to-existing-tables-part-02.aspx</guid><pubDate>Mon, 17 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Configuration Replication failure and retry alert-SQL Server</title><link>http://beyondrelational.com/modules/2/blogs/88/Posts/19421/configuration-replication-failure-and-retry-alert-sql-server.aspx</link><description>&lt;p&gt;As I wrote about replication latency from publisher to distributor and distributor to subscriber for replication and an alert for replication latency, same as we need to have an alert in case of replication failure. I would like to review some of my earlier posts about replication before move to this post which you may like,&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/19093/skip-log-reader-error-in-sql-server-replication-how-to.aspx" target="_blank"&gt;Skip Log Reader error in SQL Server replication - How to&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/88/posts/10169/review-of-some-replication-issues-and-workaround-sql-server.aspx" target="_blank"&gt;Review of some replication issues and workaround - SQL Server&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/18945/could-not-find-the-distributor-or-the-distribution-database-for-the-local-server-error-while-posts-a.aspx" target="_blank"&gt;Could not find the Distributor or the distribution database for the local server-Error while posts a tracer token in Replication&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Let the discussion to move ahead and check as how can we setup an alert for in case of replication failure. So going with steps,&lt;/p&gt;  &lt;p&gt;1. Create a job which having static code to fire an email as following and do not need to schedule it,&lt;/p&gt;  &lt;pre class="brush: sql"&gt;DECLARE @Subject varchar(50), @body varchar(200)
SET @Subject = 'Replication Alert (Agent Failure)'
SET @body = 'Replication Alert (Agent Failure).&amp;lt;BR /&amp;gt;Check the status of agent from replication monitor.'

EXEC msdb.dbo.sp_send_dbmail 
		@recipients = 'prajapatipareshm@gmail.com',
		@subject = @Subject, 
		@body = @body,
		@profile_name = '&amp;lt;Profile Name&amp;gt;',
		@body_format = 'HTML';
		&lt;/pre&gt;

&lt;p&gt;2. Go to Replication monitor from Replication tab under SQL server instance.&lt;/p&gt;

&lt;p&gt;3. Select the Publication for which you want to receive an alert for failure and move to &lt;strong&gt;Warning&lt;/strong&gt; tab as following,&lt;/p&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=458829a8f3ab4f9e8cc94283a6d696e6&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;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="FailureAlert1" border="0" alt="FailureAlert1" src="http://media.beyondrelational.com/images.ashx?id=c1f8cf8fdfe646469cda82fe9e5b46e0&amp;amp;w=-1&amp;amp;h=-1" width="244" height="136"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;(Click on image to enlarge)&lt;/p&gt;

&lt;p&gt;4. Go Configure alert and select “&lt;strong&gt;Replication : agent failure&lt;/strong&gt;” as mentioned in below image,&lt;/p&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=fbbe3615cad0402fa5096150b4b7134c&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;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="FailureAlert2" border="0" alt="FailureAlert2" src="http://media.beyondrelational.com/images.ashx?id=d4f3746fd13b4510887d93b8c9eb76be&amp;amp;w=-1&amp;amp;h=-1" width="244" height="140"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;(Click on image to enlarge)&lt;/p&gt;

&lt;p&gt;5. For agent property, click on &lt;strong&gt;configure&lt;/strong&gt; button&amp;nbsp; –&amp;gt; &lt;strong&gt;Response&lt;/strong&gt; tab and select the job which we created earlier in step 1 in Execute job check box,&lt;/p&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=d908f352668146459c1daf35cdafd7c9&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;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="FailureAlert3" border="0" alt="FailureAlert3" src="http://media.beyondrelational.com/images.ashx?id=9d5875a491f34a0d8ea2af5353beac9b&amp;amp;w=-1&amp;amp;h=-1" width="244" height="122"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;(Click on image to enlarge)&lt;/p&gt;

&lt;p&gt;This is the just steps to configure an alert for replication agent failure. We can also add notification alert to job operators also, so whenever replication agent fails, this configuration run the job and it will fire an email. We can setup the same configuration for &lt;strong&gt;replication agent retry&lt;/strong&gt; too.&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/88/Posts/19421/configuration-replication-failure-and-retry-alert-sql-server.aspx</guid><pubDate>Sun, 16 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Relive TechEd 2013 at SQLBangalore User Group Meeting</title><link>http://beyondrelational.com/modules/2/blogs/562/posts/19523/relive-teched-2013-at-sqlbangalore-user-group-meeting.aspx</link><description>&lt;div&gt;Impressed by awesome sessions at SQLBangalore user group meeting today (15th of June, 2013), I decided to write a blog post about it. It’s a monthly event that takes place at Microsoft campus in Bangalore. &amp;nbsp;Today’s UG meeting named “Relive TechEd 2013 at SQL Bangalore” had three 1-hour sessions:&lt;/div&gt;&lt;div&gt;-&lt;b&gt; Balmukund Lakhani&lt;/b&gt;. SQL Server 2012 - High Availability Redefined.&lt;/div&gt;&lt;div&gt;- &lt;b&gt;Vinod Kumar&lt;/b&gt;. What is wrong with Transactional Logs? Common Misconceptions.&lt;/div&gt;&lt;div&gt;- &lt;b&gt;Pinal Dave&lt;/b&gt;. Indexes – The Unsung Hero.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;I should point out that UG meeting had great success and I personally loved it. There were lots of fun and learning. Though the meeting had early start today (9-45 against 10-30 before), many people came there. I reached Microsoft campus by 9-30 and was impressed by a queue of people waiting to get their visitor badges. &amp;nbsp;By 10 o’clock the room was full or I can even say overfull (some people was listening sessions standing all 3 hours long). &amp;nbsp;UG was started by small introductory speech by Vinod Kumar and giving special gifts from Pluralsight to all members, who brought friends with them to UG.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;First session was done by Balmukund Lakhani (Microsoft), blogger, speaker and father of one daughter and husband of one wife, as his “About me” slide said. He started his session with special funny clapping exercises. &amp;nbsp;And later it was very interesting session about AlwaysOn Availability Groups (AG).&amp;nbsp;&lt;/div&gt;&lt;img src="http://sphotos-e.ak.fbcdn.net/hphotos-ak-ash4/998113_10151648235419029_2013873284_n.jpg"&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;We learned that they are flexible, integrated and efficient, and got information about pre-requisites. As I remember, it is not possible to implement them if database has simple or bulk recovery model (so need only full model), or if there is no back ups. Also all nodes should be in same domain and same cluster. Then Balmukund made several demos:&amp;nbsp;&lt;/div&gt;&lt;div&gt;-&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;Creating AG&lt;/div&gt;&lt;div&gt;-&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;Back up on secondary replicas&lt;/div&gt;&lt;div&gt;-&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;Readable secondary replicas&lt;/div&gt;&lt;div&gt;-&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;AG listener&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;The next session was done by Vinod Kumar, Technology Architect at Microsoft. &amp;nbsp;First he asked audience what transaction log is and got many different answers. &amp;nbsp;He presented “What is wrong with Transactional Logs? Common Misconceptions”, including transaction log physical architecture, virtual log files (VLFs), log cycling, log shrinking. Session had many very interesting demos. Personally, I learned new command for me DBCC LOGINFO to get information about virtual log files inside transaction log.&lt;/div&gt;&lt;div&gt;&lt;img src="http://sphotos-e.ak.fbcdn.net/hphotos-ak-ash3/8654_10151432725442452_1663617381_n.jpg"&gt;&lt;/div&gt;&lt;div&gt;The last session of the UG meeting was made by Pinal Dave “Indexes – The Unsung Hero”. &amp;nbsp;It was really amazing session. During it Pinal told us imaginary story about Raj, Priya and Rahul, 3 coworkers at Yash Raj Computers. According to story Raj was a big fan of indexes, Priya was neutral and Rahul was against indexes.&amp;nbsp;&lt;/div&gt;&lt;img src="http://sphotos-f.ak.fbcdn.net/hphotos-ak-frc1/1003103_10151648235979029_2075231417_n.jpg"&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;So to let us know who is right Raj or Rahul, we passed through several interesting demos. Out of demos audience learned that unused indexes can slow down performance not only of DML queries, but also performance of SELECT; that clustered indexes can give less performance than non-clustered indexes in some cases. &amp;nbsp;And there is no “depends” for all questions he asks.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;And at the end of my post I want just to say “Thank you” to all speakers, it was so great that it impressed me to write about it.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;PS: &lt;a href="http://www.facebook.com/groups/SQLBangalore/"&gt;SQLBangalore &lt;/a&gt;is an open group, so feel free to join us in Facebook and come to our monthly meetings. &amp;nbsp;The next &amp;nbsp;meeting’s date was announced today and it’s 13th of July.&lt;/div&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/562/posts/19523/relive-teched-2013-at-sqlbangalore-user-group-meeting.aspx</guid><pubDate>Sat, 15 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Containers in SSIS</title><link>http://beyondrelational.com/modules/2/blogs/1002/posts/19522/containers-in-ssis.aspx</link><description>&lt;P&gt;&lt;FONT face=Arial&gt;Moving ahead from Import and Export Wizard, we will now discuss on the topic &lt;STRONG&gt;Containers in SSIS&lt;/STRONG&gt;. In my previous post on&lt;SPAN style="TEXT-DECORATION: underline" class=last&gt;&lt;STRONG class=last&gt;&lt;A class=last title="What is SSIS and it’s Architecture?" href="http://www.phpring.com/ssis/"&gt;&lt;FONT color=#e65c5c&gt; SSIS and It’s Architecture&lt;/FONT&gt;&lt;/A&gt; &lt;/STRONG&gt;&lt;/SPAN&gt;, I discussed about Packages, Control and Data flow, Connection Managers, Containers, etc. Let’s recall some of the concepts and wrap it shortly:-&lt;/FONT&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;FONT face=Arial&gt;&lt;STRONG class=last&gt;Package: &lt;/STRONG&gt;- A basic unit of Design, Deployment and Execution.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Arial&gt;&lt;STRONG class=last&gt;Connection Managers: &lt;/STRONG&gt;- A logical representation of connections stored in the package. These cannot be shared between the packages.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Arial&gt;&lt;STRONG class=last&gt;Data Flow: -&lt;/STRONG&gt; It is defined as the complete process of Extracting data into server’s memory, transforming it and Load the transformed data onto Destination.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=last&gt;&lt;FONT face=Arial&gt;&lt;STRONG&gt;Control Flow: -&lt;/STRONG&gt; It acts as the brain of a package. A package consists of a single control flow. It contains &lt;I class=last&gt;Containers, Tasks, Variables, Precedence constraints and Event handlers.&lt;/I&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;So, we are clear with the basics now. &lt;STRONG&gt;For further details,&lt;/STRONG&gt; you can jump to my article on &lt;SPAN style="TEXT-DECORATION: underline"&gt;&lt;STRONG class=last&gt;&lt;A class=last title="What is SSIS and it’s Architecture?" href="http://www.phpring.com/ssis/"&gt;&lt;FONT color=#e65c5c&gt;SSIS and its Architecture&lt;/FONT&gt;&lt;/A&gt;&lt;/STRONG&gt; &lt;/SPAN&gt;. Now, let’s unite our concentration on the main point- &lt;STRONG class=last&gt;Containers.&lt;/STRONG&gt; They are classified as follows:-&lt;/FONT&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;FONT face=Arial&gt;&lt;STRONG class=last&gt;Task Host Containers: -&lt;/STRONG&gt; This is an abstract concept like an interface. They are not visible in our toolbox and provides services to a single task.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;SPAN style="TEXT-DECORATION: underline" class=last&gt;&lt;A class=last title="Sequence Container in SSIS" href="http://www.phpring.com/sequence-container/"&gt;&lt;FONT color=#e65c5c face=Arial&gt;Sequence Container&lt;/FONT&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;FONT face=Arial&gt;:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face=Arial&gt;&lt;B class=last&gt; -&lt;/B&gt; It allows you to group tasks into logical subject areas. Within the development environment, you can then collapse or expand this container for usability.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG class=last&gt;&lt;SPAN style="TEXT-DECORATION: underline" class=last&gt;&lt;A class=last title="For Loop Container in SSIS" href="http://www.phpring.com/for-loop-container/"&gt;&lt;FONT color=#e65c5c face=Arial&gt;For Loop Container&lt;/FONT&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;FONT face=Arial&gt;: -&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face=Arial&gt; The basic function of this is to loop through a series of tasks contained in a container until a condition is met or for predetermined number of times.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=last&gt;&lt;STRONG class=last&gt;&lt;SPAN style="TEXT-DECORATION: underline" class=last&gt;&lt;A class=last title="Foreach Loop Container in SSIS" href="http://www.phpring.com/foreach-loop-container/"&gt;&lt;FONT color=#e65c5c face=Arial&gt;For Each Loop Container:&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Arial&gt; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT face=Arial&gt;- &lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face=Arial&gt;It Loops through a series of files or records in a data set, and then execute the tasks in the container for each record in the collection.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Each container has some common properties that affect the usage of these features. Understanding these properties and what they do helps a lot in the developing SSIS packages.&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE border=1&gt;
&lt;TBODY class=last&gt;
&lt;TR&gt;
&lt;TH&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Property&lt;/FONT&gt;&lt;/P&gt;&lt;/TH&gt;
&lt;TH class=last&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Description&lt;/FONT&gt;&lt;/P&gt;&lt;/TH&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;DelayValidation&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=last&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;A Boolean value that indicates whether validation of the container is delayed until run time&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Disable&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=last&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;A Boolean value that indicates whether the container runs&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;DisableEventHandlers&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=last&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;A Boolean value that indicates whether the event handlers associated with the container run&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;FailPackageOnFailure&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=last&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;A Boolean value that specifies whether the package fails if an error occurs in the container.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;FailParentOnError&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=last&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;A Boolean value that specifies whether the parent container fails if an error occurs in the container.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;IsolationLevel&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=last&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;The isolation level of the container transaction. The values are Unspecified, Chaos, ReadUncommitted, ReadCommitted, RepeatableRead, Serializable, and Snapshot.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;MaximumErrorCount&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=last&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;The maximum number of errors that can occur before a container stops running.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR class=last&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;TransactionOption&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=last&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;The transactional participation of the container. The values are NotSupported, Supported, Required.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;We will cover all the above mentioned &lt;STRONG&gt;containers&lt;/STRONG&gt; by implementing them separately with reference to simple &lt;STRONG class=last&gt;examples&lt;/STRONG&gt;. I am mentioning the links below, Click on the respective link who’s Implementation you want to see :-&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG class=last&gt;&lt;FONT face=Arial&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;Click Here for the &lt;/SPAN&gt;==&amp;gt; &lt;/FONT&gt;&lt;A class=last title="Sequence Container in SSIS" href="http://www.phpring.com/sequence-container/"&gt;&lt;FONT color=#e65c5c face=Arial&gt;Implementation Of SEQUENCE CONTAINER.&lt;/FONT&gt;&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG class=last&gt;&lt;FONT face=Arial&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;Click Here for the&lt;/SPAN&gt; ==&amp;gt; &lt;/FONT&gt;&lt;A class=last title="For Loop Container in SSIS" href="http://www.phpring.com/for-loop-container/"&gt;&lt;FONT color=#e65c5c face=Arial&gt;Implementation Of FOR LOOP CONTAINER&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Arial&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG class=last&gt;&lt;FONT face=Arial&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;Click Here for the&lt;/SPAN&gt; ==&amp;gt; &lt;/FONT&gt;&lt;A class=last title="Foreach Loop Container in SSIS" href="http://www.phpring.com/foreach-loop-container/"&gt;&lt;FONT color=#e65c5c face=Arial&gt;Implementation Of FOREACH LOOP CONTAINER.&lt;/FONT&gt;&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/1002/posts/19522/containers-in-ssis.aspx</guid><pubDate>Thu, 13 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Export to XML File using SSIS</title><link>http://beyondrelational.com/modules/2/blogs/51/posts/19521/export-to-xml-file-using-ssis.aspx</link><description>&lt;p&gt;Recently I was given a task to export data in XML format using SSIS.
I initially thought it should be straight forward – just dump it in a flat file and
give it a name xml type, however SSIS has no XML destination just an XML source. I had no luck dumping the XML in
flat file. My solution was to use a script task which worked well. &lt;br&gt;&lt;/p&gt;
&lt;p&gt;My requirement is that the stored
procedure would return the XML as a single row and I need to export that in a
file. &lt;br&gt;&lt;/p&gt;&lt;p&gt;Please visit the article posted on &lt;a href="http://www.sql-server-performance.com/2013/export-to-xml-using-ssis/"&gt;Sql-Server-Performance&lt;/a&gt; for the complete solution. Here, is the complete link&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.sql-server-performance.com/2013/export-to-xml-using-ssis/"&gt;http://www.sql-server-performance.com/2013/export-to-xml-using-ssis/&lt;/a&gt;&lt;br&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/51/posts/19521/export-to-xml-file-using-ssis.aspx</guid><pubDate>Thu, 13 Jun 2013 00:00:00 GMT</pubDate></item><item><title>#0272 - SQL Server - IDENTITY columns – Myths – IDENTITY columns cannot be added to existing tables – Part 01</title><link>http://beyondrelational.com/modules/2/blogs/77/posts/19516/0272-sql-server-identity-columns-myths-identity-columns-cannot-be-added-to-existing-tables-part-01.aspx</link><description>&lt;P&gt;Generally, IDENTITY columns are used when developing new tables so that when records are inserted into a table, they are assigned the appropriate values.&lt;/P&gt;
&lt;P&gt;Hence if ever the need arises to insert an IDENTITY column into an existing question, the big question is – can it be done?&lt;/P&gt;
&lt;BLOCKQUOTE style="MARGIN-RIGHT: 0px" dir=ltr&gt;
&lt;P&gt;Is it really possible to add an IDENTITY column to an existing table?&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The answer is quite simple – &lt;STRONG&gt;&lt;EM&gt;Yes!&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The only restrictions that ALTER TABLE enforces upon us are that a new column must be added and that it should be of a data-type compatible with IDENTITY Columns. To demonstrate these points, I will perform two experiments shown below.&lt;/P&gt;
&lt;H2&gt;Modifying an existing column to an IDENTITY column&lt;/H2&gt;
&lt;P&gt;Other than recreating the entire table, an existing column cannot be modified to an IDENTITY column. Copy-Paste the query below into SSMS and simply parse it by using Ctrl+ F5 key combination or the blue check mark on the SSMS toolbar. The following error will be encountered:&lt;/P&gt;&lt;PRE class="brush: sql"&gt;USE tempdb;
GO

SET NOCOUNT ON;

--1. Prepare the environment
--   Create a table, and add some test data into it

--Safety Check
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

--Create a table
CREATE TABLE dbo.tIdentity (RecordId INT,
                            IdentityValue VARCHAR(20)
                           );
GO

--2. Add some test data
INSERT INTO dbo.tIdentity (RecordId, IdentityValue)
VALUES (3, 'Three'),
       (2, 'Two'),
       (1, 'One'),
       (0, 'Zero'),
       (4, 'Four'),
       (5, 'Five'),
       (6, 'Six');
GO

--3. Check the values inserted into the table
SELECT RecordId, IdentityValue
FROM dbo.tIdentity;
GO

--4. Alter the table to add an IDENTITY Column
ALTER TABLE dbo.tIdentity
    ALTER COLUMN RecordId INT NOT NULL IDENTITY(1,1) PRIMARY KEY CLUSTERED;
GO    
    
--4. Check the values inserted into the table
SELECT RecordId, IdentityValue
FROM dbo.tIdentity;
GO

----4b.One may also want to check the value of IDENT_CURRENT
--SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValueAfterDBCC;
--GO

--4. Cleanup
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

/**********************************************
               RESULTS
**********************************************/
/*
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'IDENTITY'.
*/
&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;Tip:&lt;/STRONG&gt; If your design ever needs to be modified to convert an existing column into an IDENTITY column, this can be achieved using the following high-level steps:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create an identical table under a different name, but with an IDENTITY column (e.g. &lt;EM&gt;tmp_tIdentity&lt;/EM&gt;) 
&lt;LI&gt;Set IDENTITY_INSERT to ON for this new table 
&lt;LI&gt;Pump data from the old table to the new table (i.e. from &lt;EM&gt;tIdentity&lt;/EM&gt; to &lt;EM&gt;tmp_tIdentity&lt;/EM&gt;) 
&lt;LI&gt;Set IDENTITY_INSERT to OFF for this new table 
&lt;LI&gt;Drop the old table 
&lt;LI&gt;Rename the newly created table (i.e. rename from &lt;EM&gt;tmp_tIdentity&lt;/EM&gt; to &lt;EM&gt;tIdentity&lt;/EM&gt;)&lt;/LI&gt;&lt;/OL&gt;&lt;/BLOCKQUOTE&gt;
&lt;H2&gt;Adding a new Identity column to an existing table&lt;/H2&gt;
&lt;P&gt;While existing columns cannot be converted to IDENTITY columns, new IDENTITY column can always be added to an existing table (provided there are no other IDENTITY columns on it).&lt;/P&gt;
&lt;P&gt;The below script quite simply creates a table and then add an IDENTITY column to it. As can be seen from the results below, although the records were inserted randomly, the identity values are assigned based on the way in which the &lt;EM&gt;records are ordered&lt;/EM&gt;. This is an important consideration, as we will see in part 02 of this post. In this case, we have a clustered key on the &lt;EM&gt;RecordId&lt;/EM&gt; column and therefore, the values in the IDENTITY column follow the same order as the &lt;EM&gt;RecordId&lt;/EM&gt;.&lt;/P&gt;&lt;PRE class="brush: sql"&gt;USE tempdb;
GO

SET NOCOUNT ON;

--1. Prepare the environment
--   Create a table, and add some test data into it

--Safety Check
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

--Create a table
CREATE TABLE dbo.tIdentity (RecordId INT PRIMARY KEY CLUSTERED,
                            IdentityValue VARCHAR(20)
                           );
GO

--2. Add some test data
INSERT INTO dbo.tIdentity (RecordId, IdentityValue)
VALUES (3, 'Three'),
       (5, 'Five'),
       (1, 'One'),
       (0, 'Zero'),
       (4, 'Four'),
       (2, 'Two'),
       (6, 'Six');
GO

--3. Check the values inserted into the table
SELECT RecordId, IdentityValue
FROM dbo.tIdentity;
GO

--4. Alter the table to add an IDENTITY Column
ALTER TABLE dbo.tIdentity
    ADD IdentityId INT IDENTITY(1,1);
GO    
    
--4. Check the values inserted into the table
SELECT RecordId, IdentityId, IdentityValue
FROM dbo.tIdentity;
GO

----4b.One may also want to check the value of IDENT_CURRENT
--SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValueAfterDBCC;
--GO

--4. Cleanup
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

/**********************************************
               RESULTS
**********************************************/
/*
--Before adding the IDENTITY value
RecordId    IdentityValue
----------- --------------
0           Zero
1           One
2           Two
3           Three
4           Four
5           Five
6           Six

--After adding the IDENTITY value
RecordId    IdentityId  IdentityValue
----------- ----------- --------------
0           1           Zero
1           2           One
2           3           Two
3           4           Three
4           5           Four
5           6           Five
6           7           Six
*/
&lt;/PRE&gt;
&lt;H2&gt;Conclusion (Part 01)&lt;/H2&gt;
&lt;P&gt;The above experiments show that Microsoft SQL Server allows us to define IDENTITY columns on existing tables, under certain restrictions. This can be a very useful feature in case an original, legacy design needs to be changed for a universal adoption of IDENTITY columns in your product.&lt;/P&gt;
&lt;P&gt;Until we meet next time, &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;A href="http://www.cars.com/go/advice/Story.jsp?section=top&amp;amp;subject=more&amp;amp;story=top10annoying&amp;amp;referer&amp;amp;year&amp;amp;aff=national"&gt;&lt;STRONG&gt;&lt;FONT color=#3366cc&gt;Be courteous. Drive responsibly.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/77/posts/19516/0272-sql-server-identity-columns-myths-identity-columns-cannot-be-added-to-existing-tables-part-01.aspx</guid><pubDate>Thu, 13 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Question of the month June 2013 - When did you use CURSOR for performance benefit?</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/19520/question-of-the-month-june-2013-when-did-you-use-cursor-for-performance-benefit.aspx</link><description>As we know, in SQL Server we can almost use SET-BASED approach to implement any kind of business logic. Rarely CURSOR is used in some cases.&amp;nbsp;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Now the question is &lt;b&gt;"When did you use CURSOR to get better performance than SET-BASED approach?"&lt;/b&gt;&lt;/div&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/19520/question-of-the-month-june-2013-when-did-you-use-cursor-for-performance-benefit.aspx</guid><pubDate>Wed, 12 Jun 2013 00:00:00 GMT</pubDate></item><item><title>T SQL Script - Splitting a delimited column value to multiple columns</title><link>http://beyondrelational.com/modules/2/blogs/557/posts/19519/t-sql-script-splitting-a-delimited-column-value-to-multiple-columns.aspx</link><description>&lt;P&gt;There is a large number of requests in multiple forums to split a delimitted column value to multiple columns. Here is one method that I worked on, probably, this would help most of us in future if we come across similar situation:&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&amp;nbsp;&lt;/P&gt;

&lt;pre class="brush:sql"&gt;

Create Table Product(Col1 varchar(10),Col2 Varchar(1000))

iNSERT INTO pRODUCT(Col1,Col2) sELECT 1,'AR-5381 BA-8327 BB-7421 BB-8107 BB-9108'
iNSERT INTO pRODUCT(Col1,Col2) sELECT 2,'BC-M005 BC-R205 BE-2349 BE-2908 BK-M18B-40'
 
    
;WITH
L0 AS(SELECT 1 AS c UNION ALL SELECT 1),
L1 AS(SELECT 1 AS c FROM L0 AS A, L0 AS B),
L2 AS(SELECT 1 AS c FROM L1 AS A, L1 AS B),
L3 AS(SELECT 1 AS c FROM L2 AS A, L2 AS B),
Numbers AS(SELECT ROW_NUMBER() OVER(ORDER BY c) AS n FROM L3)
SELECT Col1, [1] AS Column1, [2] AS Column2, [3] AS Column3, [4] AS Column4, [5] AS Column5
FROM
(SELECT Col1,
        ROW_NUMBER() OVER (PARTITION BY Col1 ORDER BY nums.n) AS PositionInList,
        LTRIM(RTRIM(SUBSTRING(valueTable.Col2, nums.n, charindex(N' ', valueTable.Col2 + N' ', nums.n) - nums.n))) AS [Value]
 FROM   Numbers AS nums INNER JOIN Product AS valueTable ON nums.n &lt;= CONVERT(int, LEN(valueTable.Col2)) AND SUBSTRING(N' ' + valueTable.Col2, n, 1) = N' ') AS SourceTable
PIVOT
(
MAX([VALUE]) FOR PositionInList IN ([1], [2], [3], [4], [5])
) AS Table2

Drop table Product

&lt;/pre&gt;

</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/557/posts/19519/t-sql-script-splitting-a-delimited-column-value-to-multiple-columns.aspx</guid><pubDate>Mon, 10 Jun 2013 00:00:00 GMT</pubDate></item><item><title>POWER function may not return accurate values</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/19517/power-function-may-not-return-accurate-values.aspx</link><description>&lt;b&gt;POWER&lt;/b&gt; is one of the mathematical functions used in SQL Server which returns the value of the expression to a specific power. But it rounds the values after 16 digits if the result is more than 16 digits. Consider the following example&lt;pre class="brush:sql"&gt;declare @value decimal(38), @power_to int, @total decimal(38)
select @value=5, @power_to =29, @total=1
select power(@value,@power_to) as value
&lt;/pre&gt;
The result is
&lt;pre class="brush:sql"&gt;value
---------------------------------------
186264514923095690000
&lt;/pre&gt;
We know that any power(&amp;gt;0) of 5 ends with 5 only and the result ends with 0. As you see the result is rounded from 16th digit onwards. So how do we overcome this problem? As usual a &lt;b&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/70/posts/19504/table-with-only-one-column.aspx" target="_new"&gt;numbers or tally table&lt;/a&gt;&lt;/b&gt; comes handy. Use the following code 
&lt;pre class="brush:sql"&gt;declare @value decimal(38), @power_to int, @total decimal(38)
select @value=5, @power_to =29, @total=1
select @total=@total*@value from master..spt_values where type='p' and number &amp;lt; @power_to
select @total as value
&lt;/pre&gt;

The result is&lt;pre class="brush:sql"&gt;value
---------------------------------------
186264514923095703125
&lt;/pre&gt;

So beware of this behavior of power function. </description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/19517/power-function-may-not-return-accurate-values.aspx</guid><pubDate>Mon, 10 Jun 2013 00:00:00 GMT</pubDate></item><item><title>#0271 - SQL Server - IDENTITY columns – Myths – IDENTITY values (including SEED &amp; INCREMENT) cannot be negative</title><link>http://beyondrelational.com/modules/2/blogs/77/posts/19515/0271-sql-server-identity-columns-myths-identity-values-including-seed-increment-cannot-be-negative.aspx</link><description>&lt;P&gt;When one thinks of an incremental number, a series of positive numbers comes to mind. Since IDENTITY columns are an auto-incrementing series of numbers, it is human to associate IDENTITY columns with positive numbers. However when we talk about numbers and the number line, we can go to infinity from both sides of 0 (-Infinity….-5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5,….+Infinity).&lt;/P&gt;
&lt;P&gt;Hence, the question that comes up is whether IDENTITY values (including the seed &amp;amp; increment values) can be negative. The only way to test it out is to use an example:&lt;/P&gt;&lt;PRE class="brush: sql"&gt;USE tempdb;
GO

SET NOCOUNT ON;

--1. Prepare the environment
--   Create a table, and add some test data into it

--Safety Check
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

--Create a table
CREATE TABLE dbo.tIdentity (IdentityId INT IDENTITY (-1, -1),
                            IdentityValue VARCHAR(20)
                           );
GO

--2. Add some test data
INSERT INTO dbo.tIdentity (IdentityValue)
VALUES ('Minus One'),
       ('Minus Two'),
       ('Minus Three'),
       ('Minus Four'),
       ('Minus Five');
GO

--3. Check the values inserted into the table
SELECT IdentityId, IdentityValue
FROM dbo.tIdentity;

----3b.One may also want to check the value of IDENT_CURRENT
--SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValue;
--GO

--4. Cleanup
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

/**********************************************
               RESULTS
**********************************************/
/*
IdentityId  IdentityValue
----------- --------------
-1          Minus One
-2          Minus Two
-3          Minus Three
-4          Minus Four
-5          Minus Five
*/
&lt;/PRE&gt;
&lt;P&gt;As can be seen from the result of the script above, it is possible for the SEED, INCREMENT and the IDENTITY column value itself to be negative. Keeping in mind the rules of the number line (from elementary school), please note that as one moves away from 0 (in either direction), the number keeps increasing in value and is therefore incrementing.&lt;/P&gt;
&lt;H2&gt;Conclusion&lt;/H2&gt;
&lt;P&gt;As shown by the quick experiment above, it is quite possible to have negative values for IDENTITY columns. As of writing this post, I do not have a practical implementation of this in mind. However, if you have ever encountered a situation where auto-incrementing negative values might be useful, do drop a line in the blog comments below.&lt;/P&gt;
&lt;P&gt;Until we meet next time, &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;A href="http://www.cars.com/go/advice/Story.jsp?section=top&amp;amp;subject=more&amp;amp;story=top10annoying&amp;amp;referer&amp;amp;year&amp;amp;aff=national"&gt;&lt;STRONG&gt;&lt;FONT color=#3366cc&gt;Be courteous. Drive responsibly.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/77/posts/19515/0271-sql-server-identity-columns-myths-identity-values-including-seed-increment-cannot-be-negative.aspx</guid><pubDate>Mon, 10 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Script to get replication latency and alert in SQL Server</title><link>http://beyondrelational.com/modules/2/blogs/88/Posts/19420/script-to-get-replication-latency-and-alert-in-sql-server.aspx</link><description>&lt;p&gt;Recently I had posted for one issue I faced for replication trace token ,&lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/18945/could-not-find-the-distributor-or-the-distribution-database-for-the-local-server-error-while-posts-a.aspx" target="_blank"&gt;Could not find the Distributor or the distribution database for the local server&lt;/a&gt;. Hope you read and liked it. Today I am writing for replication latency and it’s alert and I am using one script to post a tracer token which I used same in &lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/18945/could-not-find-the-distributor-or-the-distribution-database-for-the-local-server-error-while-posts-a.aspx" target="_blank"&gt;earlier post&lt;/a&gt; where you can see the script there and details for same. So move on the topic here as how can we get replication latency information and alert for same. Putting in steps,&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1. Post tracer tokens : &lt;/strong&gt;Schedule a script to post a tracer tokens frequently, says 5 minutes which posts a tracer token into the transaction log at the Publisher and begins the process of tracking latency statistics and run this script at publisher,&lt;/p&gt;  &lt;pre class="brush: sql"&gt;USE publisherdb 
GO

DECLARE @out_tracer_token_id INT 

EXEC sys.Sp_posttracertoken 
  @publication = N'&amp;lt;Publication Name&amp;gt;',  -- Put Publication name here
  @tracer_token_id=@out_tracer_token_id out 

SELECT @out_tracer_token_id &lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;2. Script :&lt;/strong&gt; After scheduling above scripts every 5 minutes which will put latency history in MStracer_history system table in distribution database, following script use to get details for the latency from publisher to distributor and distributor to subscriber which belongs to distribution database,&lt;/p&gt;

&lt;pre class="brush: sql"&gt;USE distribution 
GO 

SELECT publisher_db                                                    AS 
       [PublisherDB] 
       , 
       publication 
       AS [Publication], 
       name                                                            AS 
       [Subscriber], 
       subscriber_db                                                   AS 
       [SubscriberDB], 
       RIGHT('0' + Cast([timetosubscriber]/3600 AS VARCHAR(3)), 2) 
       + ':' 
       + RIGHT('0' + Cast(([timetosubscriber] % 3600) / 60 AS VARCHAR(2)), 2) 
       + ':' 
       + RIGHT('0' + Cast(([timetosubscriber] % 60) AS VARCHAR(2)), 2) AS 
       [DistToSubLatency], 
       RIGHT('0' + Cast([timetopublisher]/3600 AS VARCHAR(3)), 2) 
       + ':' 
       + RIGHT('0' + Cast(([timetopublisher] % 3600) / 60 AS VARCHAR(2)), 2) 
       + ':' 
       + RIGHT('0' + Cast(([timetopublisher] % 60) AS VARCHAR(2)), 2)  AS 
       [PubToDistLatency], 
       RIGHT('0' + Cast([totaltime]/3600 AS VARCHAR(3)), 2) 
       + ':' 
       + RIGHT('0' + Cast(([totaltime] % 3600) / 60 AS VARCHAR(2)), 2) 
       + ':' 
       + RIGHT('0' + Cast(([totaltime] % 60) AS VARCHAR(2)), 2)        AS 
       [TotalLatency] 
FROM   (SELECT DISTINCT msda.publisher_db, 
                        syss.name, 
                        msda.subscriber_db, 
                        msda.publication, 
                        publisher_commit, 
                        distributor_commit, 
                        Datediff(ss, publisher_commit, distributor_commit)    AS 
                               [TimeToPublisher], 
                        subscriber_commit, 
                        Datediff(ss, distributor_commit, subscriber_commit)   AS 
                               [TimeToSubscriber], 
                        Datediff(ss, publisher_commit, distributor_commit) 
                        + Datediff(ss, distributor_commit, subscriber_commit) AS 
                               [TotalTime] 
        FROM   mstracer_history msth 
               INNER JOIN msdistribution_agents msda 
                       ON msth.agent_id = msda.id 
               INNER JOIN sys.servers syss 
                       ON msda.subscriber_id = syss.server_id 
               INNER JOIN mstracer_tokens 
                       ON msth.parent_tracer_id = mstracer_tokens.tracer_id 
        WHERE  subscriber_commit &amp;gt; Dateadd(mi, -5, Getdate())) res 
ORDER  BY [totaltime] DESC &lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;3. Alert : &lt;/strong&gt;As we seen a script to get the latency for replication , herewith I am sharing a script to get alert for &lt;u&gt;highest latency&lt;/u&gt;, In script logic is implies to send an alert only when publisher to distributor or distributor to subscriber latency exceed 1 minute. You can schedule this script to every 5 minutes as we use&amp;nbsp; condition to&amp;nbsp; scan latency history inserted in last 5 minutes,&lt;/p&gt;

&lt;pre class="brush: sql"&gt;USE distribution 
GO 

DECLARE @subject SYSNAME 
DECLARE @body VARCHAR(4000) 
DECLARE @SubscriberTime VARCHAR(20) 
DECLARE @PublisherTime VARCHAR(20) 
DECLARE @TotalTime VARCHAR(20) 
DECLARE @PublisherDB VARCHAR(20) 
DECLARE @Publication VARCHAR(20) 
DECLARE @Subscriber VARCHAR(20) 
DECLARE @SubscriberDB VARCHAR(20) 

SELECT @PublisherDB = publisher_db, 
       @Publication = publication, 
       @Subscriber = name, 
       @SubscriberDB = subscriber_db, 
       @SubscriberTime = RIGHT('0' + Cast([timetosubscriber]/3600 AS VARCHAR(3)) 
                         , 2) 
                         + ':' 
                         + RIGHT('0' + Cast(([timetosubscriber] % 3600) / 60 AS 
                         VARCHAR 
                         (2)), 2) 
                         + ':' 
                         + RIGHT('0' + Cast(([timetosubscriber] % 60) AS VARCHAR 
                         (2)), 2 
                         ), 
       @PublisherTime = RIGHT('0' + Cast([timetopublisher]/3600 AS VARCHAR(3)), 
                        2) 
                        + ':' 
                        + RIGHT('0' + Cast(([timetopublisher] % 3600) / 60 AS 
                        VARCHAR(2 
                        )), 2) 
                        + ':' 
                        + RIGHT('0' + Cast(([timetopublisher] % 60) AS VARCHAR(2 
                        )), 2), 
       @TotalTime = RIGHT('0' + Cast([totaltime]/3600 AS VARCHAR(3)), 2) 
                    + ':' 
                    + RIGHT('0' + Cast(([totaltime] % 3600) / 60 AS VARCHAR(2)), 
                    2) 
                    + ':' 
                    + RIGHT('0' + Cast(([totaltime] % 60) AS VARCHAR(2)), 2) 
FROM   (SELECT DISTINCT msda.publisher_db, 
                        syss.name, 
                        msda.subscriber_db, 
                        msda.publication, 
                        publisher_commit, 
                        distributor_commit, 
                        Datediff(ss, publisher_commit, distributor_commit)    AS 
                               [TimeToPublisher], 
                        subscriber_commit, 
                        Datediff(ss, distributor_commit, subscriber_commit)   AS 
                               [TimeToSubscriber], 
                        Datediff(ss, publisher_commit, distributor_commit) 
                        + Datediff(ss, distributor_commit, subscriber_commit) AS 
                               [TotalTime] 
        FROM   mstracer_history msth 
               INNER JOIN msdistribution_agents msda 
                       ON msth.agent_id = msda.id 
               INNER JOIN sys.servers syss 
                       ON msda.subscriber_id = syss.server_id 
               INNER JOIN mstracer_tokens 
                       ON msth.parent_tracer_id = mstracer_tokens.tracer_id 
        WHERE  subscriber_commit &amp;gt; Dateadd(mi, -5, Getdate())) res 
WHERE  ( [timetopublisher] &amp;gt; 60 
          OR [timetosubscriber] &amp;gt; 60 ) 
-- Fetch if publisher to distributor or distributor to subscriber latency greater than 60 seconds
ORDER  BY [totaltime] DESC 

SET @subject='Replication Latency Alert' 
SET @body= 
'Replication latency exceeded the highest acceptable replication delay' 
SET @body=@body 
          + 'Publisher to Distributor: ' + @PublisherTime 
          + 'Distributor to Subscriber: '+ @SubscriberTime 
          + 'Total Delay: '+ @TotalTime 
          + 'Publication: '+ @Publication 
          + 'Subscriber: ' + @Subscriber 

IF ( @body IS NOT NULL ) 
  BEGIN 
      EXEC msdb.dbo.Sp_send_dbmail 
        @recipients = 'prajapatipareshm@gmail.com', 
        @subject = @subject, 
        @body = @body, 
        @profile_name = '&amp;lt;Profile name&amp;gt;', 
        @body_format = 'HTML'; 
  END &lt;/pre&gt;

This is the details I wanted to present here to catch up replication latency and hope you may like it. </description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/88/Posts/19420/script-to-get-replication-latency-and-alert-in-sql-server.aspx</guid><pubDate>Sun, 09 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Inter-row Computation of Summary Value-A Tough Issue in Spreadsheet</title><link>http://beyondrelational.com/modules/2/blogs/925/posts/19514/inter-row-computation-of-summary-value-a-tough-issue-in-spreadsheet.aspx</link><description>&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;A name=OLE_LINK1&gt;&lt;SPAN style="mso-bookmark: OLE_LINK2"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;Spreadsheet is popular with business users for its simplicity and usability. But it is a pity that some common computations are still tough to solve with spreadsheets. The inter-row computation of summary value is such tough problem.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN style="mso-bookmark: OLE_LINK1"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK2"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;BR&gt;&lt;BR&gt;According to the data of order below, how to calculate the rate of sales increase in each month?&lt;BR&gt;&lt;BR&gt;&lt;IMG src="http://qph.is.quoracdn.net/main-qimg-6b06aa839d8eebff3c973f47e7006dc7"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-bookmark: OLE_LINK1"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK2"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN style="mso-bookmark: OLE_LINK1"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK2"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-bookmark: OLE_LINK1"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK2"&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;Obviously, the rate of increase in February should be &lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;FONT face=Calibri&gt;(D58-D2)/D2, which is a typical inter-row computation.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt; The tough problem for traditional &lt;A href="http://www.raqsoft.com/"&gt;business spreadsheet software&lt;/A&gt; is that the traditional business spreadsheet software only allows for manual formulas entering. Copying or dragging formulas to other cells will only lead to the wrong result. For example, copy a formula to the cell of March, as shown in below figure:&lt;BR&gt;&lt;BR&gt;&lt;IMG src="http://qph.is.quoracdn.net/main-qimg-5f2c22a029687d03c983cf623f39bc68"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;75-fold increase? Obviously wrong! The correct formula should be &lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;FONT face=Calibri&gt;(D113-D58)/D58, while the resulting formula by copying is (D113-D57)/D57.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt; The reason for this phenomenon is that the traditional business spreadsheet software only allows for the rigid formula-pasting based on the relative positions, lacking the intelligent adjustment mechanism.&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;Obviously, if the data volume is huge, entering all formulas manually will be such a pain and error-prone. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;Then, let’s talk about esCalc. As brand new business spreadsheet software reputed for great computing capability, esCalc is highly expected on this problem.&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="LAYOUT-GRID-MODE: line; FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10.5pt; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'; mso-fareast-font-family: ??; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA" lang=EN-US&gt;The same data is shown below:&lt;BR&gt;&lt;BR&gt;&lt;IMG src="http://qph.is.quoracdn.net/main-qimg-7167882a53a3ae98b77f63368aa8872e"&gt;&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;o:p&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;In esCalc, you only need to input the formula once to solve this problem! For example, enter &lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;FONT face=Calibri&gt;(D58-D2)/D2 for February, and the result is shown below:&lt;BR&gt;&lt;BR&gt;&lt;IMG src="http://qph.is.quoracdn.net/main-qimg-b3fbd8038f295f90836f33f2fc24a075"&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;o:p&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;FONT face=Calibri&gt;&lt;o:p&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;BR&gt;No doubt you’ve seen that all computations are finished by entering the formula for once. No need to copy or adjust the formula. Take the formula for March for example, it is (D113-D58)/D58, just the same as I expected.&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;esCalc boasts an unique homocell model which arranges cells not in a simple relative positions, but in an auto-established business association. The immediate benefit is that the formulas will be copied automatically, that is, the formula will be copied and pasted to the cells at the same business level automatically. In the above-mentioned case, for the March, April, and February bands, the respective cell in the respective summery row can be regarded as the homocells to each other. Therefore, the formula written in the cell of February will be copied and pasted to the corresponding cells of March and April.&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;Needless to say, such copying is not the migration of the relative positions in the traditional business spreadsheet software. This is a kind of Intelligent Migration, for example, migrate the formula for February to the homocell for March, as mentioned above. &lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;BR&gt;&lt;IMG src="http://qph.is.quoracdn.net/main-qimg-19dd10f3a09af8e99b70d417e32cd427"&gt;&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;Through the auto-pasting and intelligent migration of formulas, esCalc can relieve the great amount of manual work. Because it is implemented automatically, the possibilities of errors are also reduced greatly.&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'" lang=EN-US&gt;Seeing is believing. The computational capability of esCalc, as legend has it, is truly powerful. Let &lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 12.0pt" lang=EN-US&gt;Excel trembles at esCalc!&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/925/posts/19514/inter-row-computation-of-summary-value-a-tough-issue-in-spreadsheet.aspx</guid><pubDate>Fri, 07 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Convert XML data to sql table data</title><link>http://beyondrelational.com/modules/2/blogs/51/Posts/19513/convert-xml-data-to-sql-table-data.aspx</link><description>&lt;p&gt;Few days back, I came across a situation in which I need to import my table data from SSIS into XML file. I did that part, now I have to do enough testing that whether the XML generated was correct or not. The XML contains thousands of nodes and checking each node one by one was a pain, and even the structure of XML was custom and having hundred’s of columns, so cannot easily convert into table format. &lt;/p&gt;  &lt;p&gt;I searched about it and created one generic solution which will convert the XML into a table in sql server and then it will be easy to join the table with source and do testing.&lt;/p&gt;  &lt;p&gt;Let us run an example to demonstrate the solution.&lt;/p&gt;  &lt;p&gt;I have created a TestData table, in which all the XML file data will be saved, it will behave as an audit table, where the history is logged.&lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;
&lt;pre class="brush:sql"&gt;CREATE TABLE TestData (RowID int, XMLdata XML)
&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;  &lt;p&gt;I am inserting a test xml row created from sysobjects for testing.&lt;/p&gt;  

&lt;pre class="brush:sql"&gt;INSERT INTO dbo.TestData(RowID,XMLdata)
SELECT 1,
			(SELECT name as "name" ,
					object_id as "objectid",
					schema_id as "schemaid",
					type  as "objecttype"
			FROM sys.objects
			FOR XML PATH ('Objects'), ROOT('AllObjects'))   &lt;br&gt;&lt;/pre&gt;Now, once the data is inserted let us start coverting it row by row into a table  &lt;p&gt;I have used Xquery&amp;nbsp; local-name function to fetch the node name value, since there are 100’s of nodes inside the xml, it’s a generic method. Now, each node should have a unique identifier to identify the record. Here, I am having Objectid as a Unique identifier node, which can be used to identify a row. Since this will be totally unpivoted data, we need one identification column, and objectid will be the same.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;
&lt;pre class="brush:sql"&gt;   

SELECT  DISTINCT
		a.RowID,
		f.x.value('(objectid)[1]', 'varchar(max)')  AS ObjectID,
		t.c.value('local-name(..)', 'varchar(max)') AS ParentNodeName,
		t.c.value('local-name(.)', 'varchar(max)') AS NodeName,        
		t.c.value('(.)[1]', 'varchar(max)') AS NodeText
		INTO #TempNodeValues
FROM   TestData a
CROSS APPLY a.XMLdata.nodes('//AllObjects/Objects') AS   f(x)
CROSS APPLY f.x.nodes('./*') AS   t(c)

&lt;/pre&gt; &lt;br&gt;&lt;p&gt;&lt;/p&gt;  &lt;p&gt;Insert the data of the above query in some Temp table. I am inserting in #TempNodeValues temp table.  &lt;/p&gt;&lt;p&gt;Next step is to PIVOT the data so that all the columns comes up in one single row for one objectid. So, do a distinct nodename from the temp table &lt;/p&gt;  &lt;p&gt;
&lt;/p&gt;&lt;pre class="brush:sql"&gt;  
SELECT DISTINCT NodeName from #TempNodeValues
&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;  &lt;p&gt;&amp;nbsp;Output is four values which we have used while creating the XML  &lt;/p&gt;&lt;p&gt;NodeName&lt;/p&gt;  &lt;p&gt;------------    &lt;br&gt;objectid     &lt;br&gt;name     &lt;br&gt;objecttype     &lt;br&gt;schemaid&lt;/p&gt;  &lt;p&gt;Now all the major work is completed. We just need to pivot the data. In the query below paste the distinct nodenames in the Pivot section. Since we have taken objectid as a separate column in the hash table we will ignore it now.&amp;nbsp; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;
&lt;pre class="brush:sql"&gt;
SELECT rowid, objectid,name,objecttype,schemaid
FROM (SELECT *  FROM #TempNodeValues )T
PIVOT
( 
	MIN(T.NODETEXT) FOR NODENAME IN (name,objecttype,schemaid)
)PVT

  

&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;  &lt;p&gt;Run the query, and all the XML is now converted to table. Here, only two place we need to do a manual work, otherwise it is generic to every problem. &lt;br&gt;&lt;/p&gt;  &lt;p&gt;Let me know your views on the post and If anyone has implemented the solution in some other way, please share with me. &lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/51/Posts/19513/convert-xml-data-to-sql-table-data.aspx</guid><pubDate>Thu, 06 Jun 2013 00:00:00 GMT</pubDate></item><item><title>#0270 - SQL Server - IDENTITY columns – Myths – The value for SEED and INCREMENT must be 1</title><link>http://beyondrelational.com/modules/2/blogs/77/posts/19511/0270-sql-server-identity-columns-myths-the-value-for-seed-and-increment-must-be-1.aspx</link><description>&lt;P&gt;When I interview students and ask them about IDENTITY values, they are often under the impression that they have a fixed starting value (i.e. SEED) and increment (i.e. IDENTITY values go from 1, 2, 3, 4, 5… and so on).&lt;/P&gt;
&lt;P&gt;For those who read my &lt;A href="http://beyondrelational.com/modules/2/blogs/77/posts/19491/0265-sql-server-an-introduction-to-identity-columns.aspx"&gt;Introduction&amp;nbsp;to this series on IDENTITY values&lt;/A&gt;, I had mentioned that it is a common implementation to have the IDENTITY value increment by 1, but it is not the only implementation possible. Let’s look at this by means of some examples:&lt;/P&gt;
&lt;H2&gt;SEED &amp;amp; INCREMENT values – DEFAULT behavior&lt;/H2&gt;
&lt;P&gt;It might come as a surprise to many that the customary definition of IDENTITY (1,1) is used for consistency purposes only. Simply defining a column as IDENTITY would cause the database engine to assume a default value of 1 for the seed and identity.&lt;/P&gt;
&lt;P&gt;The script below shows this by not specifying anything for the seed &amp;amp; increment values when defining the IDENTITY column.&lt;/P&gt;&lt;PRE class="brush: sql"&gt;USE tempdb;
GO

SET NOCOUNT ON;

--1. Prepare the environment
--   Create a table, and add some test data into it

--Safety Check
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

--Create a table
--NOTE! No values have been explicitly defined for the SEED &amp;amp; INCREMENT
CREATE TABLE dbo.tIdentity (IdentityId INT IDENTITY,
                            IdentityValue VARCHAR(10)
                           );
GO

--2. Add some test data
INSERT INTO dbo.tIdentity (IdentityValue)
VALUES ('One'),
       ('Two'),
       ('Three');
GO

--3. Check the values inserted into the table
SELECT IdentityId, IdentityValue
FROM dbo.tIdentity;

----3b.One may also want to check the value of IDENT_CURRENT
--SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValueAfterDBCC;
--GO

--4. Cleanup
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

/**********************************************
               RESULTS
**********************************************/
/*
IdentityId  IdentityValue
----------- -------------
1           One
2           Two
3           Three
*/
&lt;/PRE&gt;
&lt;P&gt;As can be seen from the results shown above, the database engine used default values of 1 for both seed &amp;amp; increment.&lt;/P&gt;
&lt;H2&gt;SEED &amp;amp; INCREMENT values – Custom values&lt;/H2&gt;
&lt;P&gt;Now, let us attempt a similar experiment but with a seed value of 10 and an increment value of 5.&lt;/P&gt;&lt;PRE class="brush: sql"&gt;USE tempdb;
GO

SET NOCOUNT ON;

--1. Prepare the environment
--   Create a table, and add some test data into it

--Safety Check
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

--Create a table
CREATE TABLE dbo.tIdentity (IdentityId INT IDENTITY (10, 5),
                            IdentityValue VARCHAR(10)
                           );
GO

--2. Add some test data
INSERT INTO dbo.tIdentity (IdentityValue)
VALUES ('Ten'),
       ('Fifteen'),
       ('Twenty');
GO

--3. Check the values inserted into the table
SELECT IdentityId, IdentityValue
FROM dbo.tIdentity;

----3b.One may also want to check the value of IDENT_CURRENT
--SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValueAfterDBCC;
--GO

--4. Cleanup
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

/**********************************************
               RESULTS
**********************************************/
/*
IdentityId  IdentityValue
----------- -------------
10          Ten
15          Fifteen
20          Twenty
*/
&lt;/PRE&gt;
&lt;P&gt;As can be seen from the results shown above, the identity columns worked perfectly fine with seed and increment values other than 1.&lt;/P&gt;
&lt;P&gt;The only limitation that this approach might end up with is the limited range of allowed values. For example, if the seed is kept at 1000, the column can accommodate an equivalent number of lesser records before the max. value for the given data-type is reached.&lt;/P&gt;
&lt;H2&gt;Conclusion&lt;/H2&gt;
&lt;P&gt;As shown by the experiments above, it is not necessary for any application to use the default values of IDENTITY columns – they can be set to values acceptable by the business and domain rules applicable to the application.&lt;/P&gt;
&lt;P&gt;Until we meet next time, &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;A href="http://www.cars.com/go/advice/Story.jsp?section=top&amp;amp;subject=more&amp;amp;story=top10annoying&amp;amp;referer&amp;amp;year&amp;amp;aff=national"&gt;&lt;STRONG&gt;&lt;FONT color=#3366cc&gt;Be courteous. Drive responsibly.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/77/posts/19511/0270-sql-server-identity-columns-myths-the-value-for-seed-and-increment-must-be-1.aspx</guid><pubDate>Thu, 06 Jun 2013 00:00:00 GMT</pubDate></item><item><title>How to Migrate the SSIS Packages from 2005 to 2008</title><link>http://beyondrelational.com/modules/3/ask/questions/19512/how-to-migrate-the-ssis-packages-from-2005-to-2008.aspx</link><description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;1)I have an requirement where&amp;nbsp;I need to migrate the SSIS Packages from 2005 to 2008, and Please list out the possible issues while migrating the SSIS Packages from 2005 to 2008&lt;/P&gt;
&lt;P&gt;2)I also need to migrate the SQL Server 2005 Database Server to SQL Server 2008 Database Server.&lt;/P&gt;
&lt;P&gt;If Possible Please help me out with the screen shots.&lt;/P&gt;
&lt;P&gt;Thank You.&lt;/P&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/3/ask/questions/19512/how-to-migrate-the-ssis-packages-from-2005-to-2008.aspx</guid><pubDate>Wed, 05 Jun 2013 00:00:00 GMT</pubDate></item><item><title>#0269 - SQL Server - IDENTITY columns – Myths – Duplicate Values cannot exist IDENTITY columns</title><link>http://beyondrelational.com/modules/2/blogs/77/posts/19510/0269-sql-server-identity-columns-myths-duplicate-values-cannot-exist-identity-columns.aspx</link><description>&lt;P&gt;The SQL Server database engine automatically generates the next value for use by the IDENTITY column on a table. This often leads to a misconception that IDENTITY columns always contain unique values.&lt;/P&gt;
&lt;P&gt;The truth is that they don’t have to be unique. It is perfectly valid to have duplicate values in IDENTITY columns and today, I present two such scenarios under which this is possible:&lt;/P&gt;
&lt;H2&gt;Duplicate values in IDENTITY columns – Explicit Inserts&lt;/H2&gt;
&lt;P&gt;As already know, &lt;A href="http://beyondrelational.com/modules/2/blogs/77/posts/19501/0268-sql-server-identity-columns-myths-values-cannot-explicitly-inserted-into-identity-columns.aspx"&gt;explicit values can be inserted into IDENTITY columns&lt;/A&gt;. It is therefore possible to insert duplicate values in this scenario:&lt;/P&gt;&lt;PRE class="brush: sql"&gt;USE tempdb;
GO

SET NOCOUNT ON;

--1. Prepare the environment
--   Create a table, and add some test data into it

--Safety Check
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

--Create a table
CREATE TABLE dbo.tIdentity (IdentityId INT IDENTITY(1,1),
                            IdentityValue VARCHAR(10)
                           );
GO

--Add some test data
INSERT INTO dbo.tIdentity (IdentityValue)
VALUES ('One'),
       ('Two'),
       ('Three');
GO

--2. Check the current identity value of the table using IDENT_CURRENT()
SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValueBeforeTest;
GO

--3. Turn Explicit IDENTITY_INSERT ON and insert duplicate IDENTITY values
SET IDENTITY_INSERT dbo.tIdentity ON;
GO

INSERT INTO dbo.tIdentity (IdentityId, IdentityValue)
VALUES (2, 'Two2'),
       (3, 'Three2');
GO

SET IDENTITY_INSERT dbo.tIdentity OFF;
GO

--4. Check the current identity value of the table using IDENT_CURRENT()
SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValueAfterExplicitInsert;
GO

SELECT * FROM dbo.tIdentity;
GO

--5. Run DBCC CHECKIDENT and see what happens
DBCC CHECKIDENT ('dbo.tIdentity');
GO
SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValueAfterDBCC;
GO

--Cleanup
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

/**********************************************
               RESULTS
**********************************************/
/*
IdentityValueBeforeTest
-----------------------
3

IdentityValueAfterExplicitInsert
--------------------------------
3

IdentityId  IdentityValue
----------- -------------
1           One
2           Two
3           Three
2           Two2
3           Three2

Checking identity information: current identity value '3', current column value '3'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

IdentityValueAfterDBCC
----------------------
3
*/
&lt;/PRE&gt;
&lt;P&gt;As can be seen from the script above, we were successfully able to insert duplicate values for the &lt;EM&gt;IdentityId&lt;/EM&gt; column in the table. Also, the current IDENTITY value continues to remain 3 although there are about 5 records inserted in the table.&lt;/P&gt;
&lt;H2&gt;Duplicate values in IDENTITY columns – Re-seed IDENTITY column&lt;/H2&gt;
&lt;P&gt;The &lt;A href="http://msdn.microsoft.com/en-us/library/ms176057.aspx"&gt;DBCC CHECKIDENT&lt;/A&gt; can be used to get the current value of the IDENTITY column value. By default, this DBCC statement does not reseed the IDENTITY column. However, if the RESEED parameter is specified, it allows the administrator to reset the “seed” value of the column to any value supplied (Refer the &lt;A href="http://beyondrelational.com/modules/2/blogs/77/posts/19491/0265-sql-server-an-introduction-to-identity-columns.aspx"&gt;Introductory Post&lt;/A&gt;&amp;nbsp;for a refresher).&lt;/P&gt;
&lt;P&gt;The query shown below:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Creates a test table and inserts some test data into it&lt;/LI&gt;
&lt;LI&gt;Verifies the value of the IDENTITY column&lt;/LI&gt;
&lt;LI&gt;Reseed the IDENTITY column using DBCC CHECKIDENT with the RESEED parameter&lt;/LI&gt;
&lt;LI&gt;Insert some test data into the test table&lt;/LI&gt;
&lt;LI&gt;Verify the values in the table and the current value of the IDENTITY column&lt;/LI&gt;&lt;/UL&gt;&lt;PRE class="brush: sql"&gt;USE tempdb;
GO

SET NOCOUNT ON;

--1. Prepare the environment
--   Create a table, and add some test data into it

--Safety Check
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

--Create a table
CREATE TABLE dbo.tIdentity (IdentityId INT IDENTITY(1,1),
                            IdentityValue VARCHAR(10)
                           );
GO

--Add some test data
INSERT INTO dbo.tIdentity (IdentityValue)
VALUES ('One'),
       ('Two'),
       ('Three');
GO

--2. Check the current identity value of the table using IDENT_CURRENT()
SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValueBeforeTest;
GO

--3. Reseed the IDENTITY column
DBCC CHECKIDENT ('dbo.tIdentity', RESEED, 1);
GO

INSERT INTO dbo.tIdentity (IdentityValue)
VALUES ('Two2'),
       ('Three2');
GO

--4. Check the current identity value of the table using IDENT_CURRENT()
SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValuesAfterReseed;
GO

SELECT * FROM dbo.tIdentity;
GO

--5. Run DBCC CHECKIDENT and see what happens
DBCC CHECKIDENT ('dbo.tIdentity');
GO
SELECT IDENT_CURRENT('dbo.tIdentity') AS IdentityValueAfterDBCC;
GO

--Cleanup
IF OBJECT_ID('tIdentity','U') IS NOT NULL
    DROP TABLE dbo.tIdentity;
GO

/**********************************************
               RESULTS
**********************************************/
/*
IdentityValueBeforeTest
-----------------------
3

Checking identity information: current identity value '3', current column value '1'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

IdentityValuesAfterReseed
-------------------------
3

IdentityId  IdentityValue
----------- -------------
1           One
2           Two
3           Three
2           Two2
3           Three2

Checking identity information: current identity value '3', current column value '3'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

IdentityValueAfterDBCC
----------------------
3
*/
&lt;/PRE&gt;
&lt;H2&gt;Duplicate values in IDENTITY columns – BCP/BULK INSERT/OPENROWSET - -E, KEEPIDENTITY, -f switches&lt;/H2&gt;
&lt;P&gt;A long time ago, I wrote about the &lt;A href="http://beyondrelational.com/modules/2/blogs/77/posts/11313/bcp-amp-bulk-inserts-underappreciated-features-of-microsoft-sql-server.aspx"&gt;BCP utility&lt;/A&gt;&amp;nbsp;being an &lt;A href="http://beyondrelational.com/modules/2/blogs/77/posts/11271/underappreciated-features-of-microsoft-sql-server.aspx"&gt;underappreciated feature of Microsoft SQL Server&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;When data is exported or inserted in bulk via the bcp and BULK INSERT statements, it is possible to preserve the value of IDENTITY columns using the following switches:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;BCP uses the –E switch&lt;/LI&gt;
&lt;LI&gt;BULK INSERT uses the KEEPIDENTITY switch&lt;/LI&gt;
&lt;LI&gt;OPENROWSET uses the –f switch&lt;/LI&gt;&lt;/UL&gt;
&lt;H2&gt;Conclusion&lt;/H2&gt;
&lt;P&gt;As is the case with all columns in SQL Server, uniqueness can only be guaranteed by the use of a UNIQUE constraint. Without the constraint, IDENTITY columns may end up having duplicate values.&lt;/P&gt;
&lt;P&gt;Often, applications and T-SQL code use IDENTITY columns as a unique sequence of numbers – this should be done with due care as duplicate values may cause the code to break.&lt;/P&gt;
&lt;P&gt;Until we meet next time, &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;A href="http://www.cars.com/go/advice/Story.jsp?section=top&amp;amp;subject=more&amp;amp;story=top10annoying&amp;amp;referer&amp;amp;year&amp;amp;aff=national"&gt;&lt;STRONG&gt;&lt;FONT color=#3366cc&gt;Be courteous. Drive responsibly.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/77/posts/19510/0269-sql-server-identity-columns-myths-duplicate-values-cannot-exist-identity-columns.aspx</guid><pubDate>Tue, 04 Jun 2013 00:00:00 GMT</pubDate></item><item><title>REPLACE string function in SQL Server and C#</title><link>http://beyondrelational.com/modules/2/blogs/562/posts/19509/replace-string-function-in-sql-server-and-c.aspx</link><description>&lt;div&gt;Recently I’ve faced with one error in our .NET application code, which I did not expect. &amp;nbsp;But it helped me to learn something new for me.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;All we know about string function REPLACE. We have it in SQL Server and in .NET (as a method of String class).&lt;/div&gt;&lt;div&gt;Let’s make a small research and compare results of REPLACE functions in SQL Server and C#. &amp;nbsp;Let us have string variable to save in it a substring to be changed in some other original string. So our small research will concern one question: what will we get if this substring (to be replaced) is empty string?&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;First let’s check in SQL Server:&lt;/div&gt;
&lt;pre class="brush: plain"&gt;DECLARE @toReplace varchar(50) = ''
SELECT REPLACE('Hello', @toReplace, '') AS Result&lt;/pre&gt;&lt;div&gt;When we execute this snippet of code, we will get:&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="Courier New"&gt;&amp;nbsp;Result&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="Courier New"&gt;---------------------------------------------&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="Courier New"&gt;Hello&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Let’s implement the same logic in C# and check result:&lt;/div&gt;
&lt;pre class="brush: plain"&gt;using System;
namespace TestStringReplace
{
  class Program
  {
    static void Main()
    {
       string toReplace = string.Empty;
       Console.WriteLine("Hello".Replace(toReplace, string.Empty));
    }
  }
}&lt;/pre&gt;&lt;div&gt;And guess what will we get? The answer is ArgumentException:&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="Courier New"&gt;&lt;b&gt;Unhandled Exception: System.ArgumentException: String cannot be of zero length.&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="Courier New"&gt;&lt;b&gt;Parameter name: oldValue&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;So now we know that in .NET first argument of REPLACE string function cannot be empty string.&lt;/div&gt;&lt;div&gt;Hope, it would be useful for somebody.&lt;/div&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/562/posts/19509/replace-string-function-in-sql-server-and-c.aspx</guid><pubDate>Tue, 04 Jun 2013 00:00:00 GMT</pubDate></item><item><title>just another solution</title><link>http://beyondrelational.com/modules/19/tsql-beginners/302/solutions/19508/just-another-solution.aspx</link><description /><guid isPermaLink="true">http://beyondrelational.com/modules/19/tsql-beginners/302/solutions/19508/just-another-solution.aspx</guid><pubDate>Tue, 04 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Microsoft announced new SQL Server 2014</title><link>http://beyondrelational.com/modules/2/blogs/562/posts/19507/microsoft-announced-new-sql-server-2014.aspx</link><description>&lt;div&gt;Software world is changing very fast these days. It’s been only 14 months since Microsoft released SQL Server 2012. And yesterday (June 3, 2013) at TechEd North America Microsoft announced &amp;nbsp;a wave of new products and services that will help customers embrace the “enterprise cloud era”, including next version of data platform – SQL Server 2014.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Microsoft states that SQL Server 2014 is designed and developed with cloud-first principles in mind, it delivers built-in in-memory capabilities, new hybrid cloud scenarios and enables even faster data insights. What new features are waiting for us in SQL Server 2014, including:&lt;/div&gt;&lt;div&gt;- In memory OLTP (codename Hekaton)&lt;/div&gt;&lt;div&gt;- Improved AlwaysOn features (including AlwaysOn to Windows Azure Virtual machine)&lt;/div&gt;&lt;div&gt;- Hybrid cloud&lt;/div&gt;&lt;div&gt;- Hadoop connectivity&lt;/div&gt;&lt;div&gt;&lt;img src="http://blogs.technet.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-60-54-metablogapi/8311.The_2D00_Evolution_2D00_of_2D00_SQL_2D00_Server_5F00_42D968E2.jpg"&gt;&lt;/div&gt;&lt;div&gt;Microsoft officials said that SQL Server 2014 would be out shortly after release of Windows Server 2012 R2, System Center 2012 R2 and Visual Studio 2013 (planned tobe out by the end of calendar 2013).&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;I’m personally exciting to explore new features of announced product. So you are, I think.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Read &lt;a href="http://blogs.technet.com/b/dataplatforminsider/archive/2013/06/03/sql-server-2014-unlocking-real-time-insights.aspx"&gt;more&lt;/a&gt;.&lt;/div&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/562/posts/19507/microsoft-announced-new-sql-server-2014.aspx</guid><pubDate>Tue, 04 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Database mail sending fails with SP_Send_DBmail.</title><link>http://beyondrelational.com/modules/3/ask/questions/19506/database-mail-sending-fails-with-spsenddbmail.aspx</link><description>&lt;div&gt;Hi,&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;I am stuck in below problem.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;I have two servers; ServerA and ServerB. I have linked serverA to serverB by&lt;/div&gt;&lt;div&gt;sp_addlinkedserver @server = 'serverB',@provider = 'SQLNCLI',@datasrc = 'ServerB',&amp;nbsp;&lt;/div&gt;&lt;div&gt;@srvproduct = '' on serverA. Now I am querying on ServerA and retriveing data from ServerB's Table.&lt;/div&gt;&lt;div&gt;The Query is :&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;EXEC msdb.dbo.sp_send_dbmail @recipients = 'myname@myDomain.com',&lt;/div&gt;&lt;div&gt;@subject = 'MySubject',&lt;/div&gt;&lt;div&gt;@body = 'This Is Test.',&lt;/div&gt;&lt;div&gt;@body_format = 'Text', @profile_name = 'Profile1',&lt;/div&gt;&lt;div&gt;@query = 'set nocount on&lt;/div&gt;&lt;div&gt;SELECT * FROM [ServerB].[Database].dbo.myTable AS MT&lt;/div&gt;&lt;div&gt;WHERE DATEADD(DAY,0,DATEDIFF(DAY,0,Date_Col)) = DATEADD(DAY,0,DATEDIFF(DAY,0,GETDATE()))',&lt;/div&gt;&lt;div&gt;@execute_query_database = 'master',&lt;/div&gt;&lt;div&gt;@query_result_separator = ' &amp;nbsp; ',&lt;/div&gt;&lt;div&gt;@attach_query_result_as_file = 1,&lt;/div&gt;&lt;div&gt;@query_attachment_filename = 'myFile.csv'&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;I have created an proc on serverA's master database and calling this proc into a job.&lt;/div&gt;&lt;div&gt;This job throws an error:&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;" Executed as user: ServerA\sqlAgent. Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. [SQLSTATE 28000] (Error 18452). &amp;nbsp;The step failed. "&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Can Anybody help in solving this??&lt;/div&gt;&lt;div&gt;It would be a great help.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Thanks and Regards,&lt;/div&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/3/ask/questions/19506/database-mail-sending-fails-with-spsenddbmail.aspx</guid><pubDate>Tue, 04 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Table with only one column</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/19504/table-with-only-one-column.aspx</link><description>One of my colleagues asked me &lt;b&gt;"Is there a real practical use of having a table with only one column?"&lt;/b&gt; Well. There are some cases where a table with only one column makes sense. Here are some cases I know&amp;nbsp;
&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;1 The numbers or Tally table&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;This table can have one column with serial numbers and there can be many uses of this table

Let us consider this table
&lt;pre class="brush:sql"&gt;Create table #numbers(number int)
insert into #numbers(number)
select top 100000 row_number() over (order by (select 0)) from sys.columns as c1 
cross join sys.columns as c2
select * from #numbers 
&lt;/pre&gt;

The above will create a table of numbers from 1 to 100000

Now this can be used to generate a series dates for a year, split a string, extract some part of data from a string, etc.&lt;/div&gt;&lt;div&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/70/posts/10821/extract-only-numbers-from-a-string.aspx" target="_new"&gt;&lt;b&gt;Extract only numbers from a String&lt;/b&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/70/posts/10820/count-number-of-words-in-a-string.aspx" target="_new"&gt;Count number of words in a string&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Jeff Moden&lt;/b&gt;, SQL Server MVP, has written an excellant aricle here &lt;a href="http://www.sqlservercentral.com/articles/T-SQL/62867/" target="_new"&gt;&lt;b&gt;http://www.sqlservercentral.com/articles/T-SQL/62867/&amp;nbsp;
&lt;/b&gt;&lt;/a&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;2 To have Maximum value of a sequence number&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;If your business requirement needs you to generate a sequence number without gaps for each record before data are added to a table, you can &amp;nbsp;update the maximum value to this table and pick it up whenever needed

 

Suppose you have another table where you want to add sequence number to that table along with the data, you can use
&lt;pre class="brush:sql"&gt;Create table #sequence(number int)

insert into #sequence(number)
select 1

Create table #customers(cust_id varchar(15), customer_name varchar(100), dob datetime)

declare @cust_id varchar(15)
select @cust_id ='CUST'+replace(str(number,10),' ','0') from #sequence 
 insert into #customers(cust_id,customer_name,dob)
select @cust_id, 'Vimal','19650119'

update #sequence 
set number=number+1

select * from #customers 
select * from #sequence 
&lt;/pre&gt;

 Note that the #sequence table has next value that can be used to #customers table&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Have you used one column table for any other purposes?
&lt;/div&gt;&lt;/div&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/19504/table-with-only-one-column.aspx</guid><pubDate>Tue, 04 Jun 2013 00:00:00 GMT</pubDate></item><item><title>Art of Filestream - Chapter 2</title><link>http://beyondrelational.com/modules/9/books/30/comments/19505/art-of-filestream-chapter-2.aspx</link><description>I have reached only as far as Chapter 2, but here are my observations so far:


1) The download page  http://brurl.com/fs4 is empty. The scripts and labs are available elsewhere, but not philFactor.gif, MicrosoftMouse.jpg or the other images mentioned in the book.

2) On page 50, you write: 

&gt; a FILESTREAM-enabled database needs to have at least three filegroups:
&gt; •	 a data filegroup to store relational data 
&gt; •	 a log filegroup to store transactional logs 
&gt; •	 a FILESTREAM filegroup to store FILESTREAM data.

However, a log file cannot be put in a file group. See [Add Data or Log Files to a Database][1] where it says in step 7:  Transaction logs cannot be put in filegroups.

3) Also on page 50, you go on to say that:
&gt; you might decide to have more than one FILESTREAM filegroup  in a database ...  one of those filegroups must be marked as the default filegroup”. Listing 2-26 on page 84 shows T-SQL code for creating a database with 2 FILESTREAM filegroups. 

My observation is that I can create a database with 2 FILESTREAM filegroups without specifying a   default. That is, no error is generated. However, SQL Server will make the first filegroup the default if none is explicitly specified.

4) Listing 2-13:  Altering a VARBINARY(MAX)column to a FILESTREAM column.
The UPDATE statement fails because you cannot add a column and then reference it in the same batch. The listing should be:

ALTER TABLE ... ADD ItemImage_New ...

GO – need to start a new batch after ALTER TABLE

UPDATE ... SET ItemImage_New = ...

5) On page 71, you say that “we could ... use a default value, of 0x. This will create a zero-length file ...” Actually, the file size will be 1 byte.

6) You do not define a procedure for submitting feedback, so I was forced to (ab?)use the comments section for that purpose. What is the right way to send feedback about the book?


  [1]: http://msdn.microsoft.com/en-us/library/ms189253.aspx "Books Online"</description><guid isPermaLink="true">http://beyondrelational.com/modules/9/books/30/comments/19505/art-of-filestream-chapter-2.aspx</guid><pubDate>Mon, 03 Jun 2013 00:00:00 GMT</pubDate></item></channel></rss>
