<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>SQL with Manoj</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/manub22/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/manub22/feed.xml</link>
    <description>SQL Server (TSQL) Programming, DB concepts, Tips &amp;amp; Tricks… comments welcome!!!</description>
    <lastBuildDate>Thu, 30 Jul 2015 17:08:21 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Temporal Data with System Versioned Tables in SQL Server 2016</title>
      <link>https://docs.microsoft.com/archive/blogs/manub22/temporal-data-with-system-versioned-tables-in-sql-server-2016</link>
      <pubDate>Tue, 30 Jun 2015 06:28:00 GMT</pubDate>
      <dc:creator><![CDATA[Manoj Pandey (manub22)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/manub22/2015/06/30/temporal-data-with-system-versioned-tables-in-sql-server-2016/</guid>
      <description><![CDATA[SQL Server 2016&nbsp;will be coming with Temporal Data support following the ANSI SQL...]]></description>
      <content:encoded><![CDATA[<p><strong>SQL Server 2016</strong>&nbsp;will be coming with <strong>Temporal Data</strong> support following the <span><strong>ANSI SQL 2011</strong>&nbsp;standard</span>.&nbsp;<span>This will add support for <strong>Temporal Tables</strong> as a Database feature that will provide a built-in support to provide information about data stored in the table at <strong>any point in time</strong> rather than only the data that is correct at the current moment in time.</span></p>
<p><em><strong>(With the current release of CTP 2 version you can play with this feature)</strong></em></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/69/8156.SQL%20Server%202016%20Temporal%2001.PNG" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-69/8156.SQL-Server-2016-Temporal-01.PNG"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/69/8156.SQL%20Server%202016%20Temporal%2001.PNG" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-69/8156.SQL-Server-2016-Temporal-01.PNG" alt="" border="0" /></a></p>
<p>&nbsp;</p>
<p>A&nbsp;<strong>Temporal Data</strong>&nbsp;is tightly related to a Time period and used to handle the time-varying data. It provides the ability to look at data trends, types of data changes, and the overall data evolution within your database.</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/69/7282.SQL%20Server%202016%20Temporal%2012.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-69/7282.SQL-Server-2016-Temporal-12.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/69/7282.SQL%20Server%202016%20Temporal%2012.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-69/7282.SQL-Server-2016-Temporal-12.png" alt="" border="0" /></a></p>
<p>&nbsp;</p>
<p>A&nbsp;<strong>Temporal Table</strong>&nbsp;is a table for which a PERIOD definition exists and which contains system columns with a datatype of&nbsp;<strong>datetime2</strong>&nbsp;into which the period of validity is recorded by the system, and which has an associated&nbsp;<strong>History Table</strong>&nbsp;into which the system records all prior versions of each record with their period of validity.</p>
<p>&nbsp;</p>
<p><strong>&gt;&gt; To maintain Temporal data it require 2 tables:</strong></p>
<p>1. A parent <strong>Temporal</strong> or <strong>System Versioned Table</strong>, created by simple <strong>CREATE TABLE</strong> statements with few more options.</p>
<p>2. A child <strong>History Table</strong>, automatically created by the above <strong>CREATE TABLE</strong> statement and further maintained by the SQL DB Engine for all DML operations.</p>
<p>&nbsp;</p>
<p><strong>&gt;&gt; DML operations on Temporal Table:</strong></p>
<p>1. The <strong>INSERT</strong> operation will add a new record in the parent Temporal Table.</p>
<p>2. The <strong>UPDATE</strong> operation will copy the existing version of the row to the child History Table, and replaces it with new values in the parent Temporal Table.</p>
<p>3. The <strong>DELETE</strong> operation will&nbsp;copy the existing version of the row to the child History Table, and deleted the existing row in the parent Temporal Table.</p>
<p>4. While reading (<strong>SELECT</strong>) the rows you've to specify the datetime value and depending on it, it will check the parent Temporal or child History table to fetch the data for you.</p>
<p>&nbsp;</p>
<p><strong>&gt;&gt; With Temporal Data support you can do:</strong></p>
<p>1. Time Travel</p>
<p>2. Data Audit</p>
<p>3. maintain Slowly Changing Dimension (SCD)</p>
<p>4. recover from accidental data changes by repairing record-level corruptions (for DBAs).</p>
<p>&nbsp;</p>
<p><strong>&gt;&gt; I've talked on working with various option on Temporal Data/Tables with examples on my personal blog below:</strong></p>
<p><a href="https://sqlwithmanoj.com/2015/06/15/temporal-data-support-in-sql-server-2016-part-1/" target="_blank">1. CREATE a <strong>new</strong> set of Temporal Tables<strong>.</strong></a></p>
<p><a href="https://sqlwithmanoj.com/2015/06/17/time-travel-with-temporal-tables-in-sql-server-2016-part-2/" target="_blank">2.&nbsp;Enable Temporal or System Versioning&nbsp;on <strong>existing</strong> tables with data.</a></p>
<p><a href="https://www.youtube.com/watch?v=t2baJaomY4o" target="_blank">3. View the in-depth Demo.</a></p>
<p><iframe src="https://www.youtube.com/embed/t2baJaomY4o" frameborder="0" width="560" height="315"></iframe></p>
<p>&nbsp;</p>
<p><strong>&gt;&gt; More on Temporal Data/Tables on MSDN BoL:&nbsp;<a href="https://msdn.microsoft.com/en-us/library/dn935015.aspx" target="_blank">https://msdn.microsoft.com/en-us/library/dn935015.aspx</a></strong></p>]]></content:encoded>
    </item>
    <item>
      <title>Export SQL Table or a Query data to JSON string format | SQL Server 2016</title>
      <link>https://docs.microsoft.com/archive/blogs/manub22/export-sql-table-or-a-query-data-to-json-string-format-sql-server-2016</link>
      <pubDate>Sun, 14 Jun 2015 01:52:00 GMT</pubDate>
      <dc:creator><![CDATA[Manoj Pandey (manub22)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/manub22/2015/06/14/export-sql-table-or-a-query-data-to-json-string-format-sql-server-2016/</guid>
      <description><![CDATA[As many of you know that in SQL Server 2016 there will be support for JSON data, and with the...]]></description>
      <content:encoded><![CDATA[<p>As many of you know that in SQL Server 2016 there will be support for JSON data, and with the release of CTP2 you can play with the some of the features of JSON, but with CTP3/RTM JSON will be fully supported.</p>
<p>&nbsp;</p>
<p>&ndash; With this&nbsp;<strong>CTP2</strong>&nbsp;release you can&nbsp;<strong>only export</strong>&nbsp;data as JSON string.</p>
<p>&ndash; But with the release of&nbsp;<strong>CTP3</strong>&nbsp;you will also be able to&nbsp;<strong>read JSON data</strong>&nbsp;by T-SQL query and convert it into tabular (row/column) format, and will support indexes.</p>
<p>&nbsp;</p>
<p><strong>&ndash;&gt;&nbsp;JSON support is very similar to XML, so you can also:</strong></p>
<p>1. Store JSON data in SQL Server in table columns as NVARCHAR datatype.</p>
<p>2. Export SQL tables rows to JSON data.</p>
<p>3. Query external JSON data and store back in SQL tables.</p>
<p>&nbsp;</p>
<p><strong>&ndash;&gt;</strong>&nbsp;Just like XML for exporting JSON data you can use&nbsp;<strong>FOR JSON [AUTO | PATH]</strong>&nbsp;syntax:</p>
<p><strong>1. FOR JSON AUTO:</strong>&nbsp;option automatically creates a nested JSON data with sub arrays based on the table hierarchy used in the Query. The&nbsp;<strong>AUTO</strong>&nbsp;option must have a&nbsp;<strong>FROM</strong>&nbsp;clause.</p>
<p><strong>2. FOR JSON PATH:</strong>&nbsp;option enables you to define the structure of output of JSON data using the column names with aliases by using a dot separator.</p>
<p>&nbsp;</p>
<p><strong>&ndash;&gt; Let&rsquo;s see how export to JSON works:</strong></p>
<p>&ndash; I&rsquo;ll create a sample table and insert few rows in it:</p>
<pre class="scroll"><code class="mysql"> CREATE TABLE Students (<br /> ID INT IDENTITY(1,1) NOT NULL, <br /> FirstName VARCHAR(255), <br /> LastName VARCHAR(255), <br /> Class INT,<br /> Marks DECIMAL(3,1)<br /> )<br /> <br /> INSERT INTO Students (FirstName, LastName, Class, Marks)<br /> SELECT 'Manoj', 'Pandey', 10, 80.5<br /> UNION ALL<br /> SELECT 'Saurabh', 'Sharma', 11, 82.7<br /> UNION ALL<br /> SELECT 'Kanchan', 'Pandey', 10, 90.5</code></pre>
<p>&nbsp;</p>
<p><strong>1. Let&rsquo;s check the &ldquo;FOR JSON AUTO&rdquo; option:</strong></p>
<pre class="scroll"><code class="mysql"> SELECT ID, FirstName, LastName, Class, Marks <br /> FROM Students<br /> FOR JSON AUTO -- here</code></pre>
<p><strong>&ndash; Output with AUTO option:</strong></p>
<pre>[  
   {  
      "ID":1,
      "FirstName":"Manoj",
      "LastName":"Pandey",
      "Class":10,
      "Marks":80.5
   },
   {  
      "ID":2,
      "FirstName":"Saurabh",
      "LastName":"Sharma",
      "Class":11,
      "Marks":82.7
   },
   {  
      "ID":3,
      "FirstName":"Kanchan",
      "LastName":"Pandey",
      "Class":10,
      "Marks":90.5
   }
]</pre>
<p>This option as mentioned previously formats the JSON document automatically based upon the columns provided in the Query.<br />&nbsp;</p>
<p><strong>2. Now let&rsquo;s check the &ldquo;FOR JSON PATH&rdquo; option:</strong>&nbsp;with this option you can use the&nbsp;<strong>dot syntax</strong>&nbsp;as used in below Query to form a&nbsp;<strong>nested output</strong>.</p>
<pre class="scroll"><code class="mysql">SELECT<br /> ID,<br /> FirstName AS "StudentName.FirstName", <br /> LastName AS "StudentName.LastName", <br /> Marks<br /> FROM Students<br /> FOR JSON PATH -- here</code></pre>
<p><strong>&ndash; Output with PATH option:</strong></p>
<pre>[  
   {  
      "ID":1,
      "StudentName":{  
         "FirstName":"Manoj",
         "LastName":"Pandey"
      },
      "Marks":80.5
   },
   {  
      "ID":2,
      "StudentName":{  
         "FirstName":"Saurabh",
         "LastName":"Sharma"
      },
      "Marks":82.7
   },
   {  
      "ID":3,
      "StudentName":{  
         "FirstName":"Kanchan",
         "LastName":"Pandey"
      },
      "Marks":90.5
   }
]</pre>
<p>As you can see with&nbsp;<strong>PATH option</strong>&nbsp;you can&nbsp;<strong>create wrapper objects</strong>&nbsp;(here &ldquo;StudentName&rdquo;) and&nbsp;<strong>nest properties</strong>&nbsp;(here &ldquo;FirstName&rdquo; &amp; &ldquo;LastName&rdquo;).</p>
<p>&nbsp;</p>
<p><strong>--&gt; FOR JSON PATH without FROM &lt;table&gt; clause:</strong></p>
<pre class="scroll"><code class="mysql"> SELECT <br /> 1 as 'a',<br /> 2 as 'b'<br /> FOR JSON PATH</code></pre>
<p><strong><strong>&ndash; Output without FROM clause:</strong></strong></p>
<pre>{<br />  "a": 1,<br />  "b": 2<br />}</pre>
<pre><strong><br /></strong></pre>
<p><strong>--&gt; FOR JSON PATH without FROM clause and with ROOT option:</strong></p>
<pre class="scroll"><code class="mysql"> SELECT <br /> 1 as 'a',<br /> 2 as 'b'<br /> FOR JSON PATH, ROOT('root')</code></pre>
<p><strong>&ndash; Output without ROOT option:</strong></p>
<pre>{<br />  "root": {<br />    "a": 1,<br />    "b": 2<br />  }<br />}</pre>
<p><br /><strong>--&gt; As I mentioned above "FOR JSON AUTO without FROM" clause is not supported</strong></p>
<pre class="scroll"><code class="mysql"> SELECT <br /> 1 as 'a',<br /> 2 as 'b'<br /> FOR JSON AUTO</code></pre>
<p><strong>ERROR MESSAGE:</strong></p>
<p>Msg 13600, Level 16, State 1, Line 116<br />FOR JSON AUTO requires at least one table for generating JSON objects. <br />Use FOR JSON PATH or add a FROM clause with a table name.&nbsp;</p>
<p>&nbsp;</p>
<p>&ndash;&gt; You can also check the demo here:</p>
<p><iframe src="https://www.youtube.com/embed/91lO8Pp8Lk4" frameborder="0" width="560" height="315"></iframe></p>
<p>&nbsp;</p>
<p><em><strong>Source:</strong>&nbsp;from my personal blog <strong>SQLwithManoj:&nbsp;<a title="JSON with SQL Server - SQLwithManoj blog" href="https://sqlwithmanoj.com/2015/06/01/exportconvert-table-or-sql-query-data-to-json-string-format-sql-server-2016-part-1/" target="_blank">https://sqlwithmanoj.com/2015/06/01/working-with-json-data-and-sql-queries-sql-server-2016/</a></strong></em></p>]]></content:encoded>
    </item>
    <item>
      <title>Maintaining Uniqueness with Clustered ColumnStore Index | SQL Server 2014</title>
      <link>https://docs.microsoft.com/archive/blogs/manub22/maintaining-uniqueness-with-clustered-columnstore-index-sql-server-2014</link>
      <pubDate>Mon, 11 Aug 2014 01:49:56 GMT</pubDate>
      <dc:creator><![CDATA[Manoj Pandey (manub22)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/manub22/2014/08/11/maintaining-uniqueness-with-clustered-columnstore-index-sql-server-2014/</guid>
      <description><![CDATA[Column Store&nbsp;indexes were introduced in&nbsp;SQL Server 2012&nbsp;with a flavor of...]]></description>
      <content:encoded><![CDATA[<p><strong>Column Store</strong>&nbsp;indexes were introduced in&nbsp;<strong>SQL Server 2012</strong>&nbsp;with a flavor of Non-Clustered index i.e.&nbsp;<strong>&ldquo;Non-Clustered ColumnStore&rdquo; index</strong>. However there is a big limitation that the underlying table becomes&nbsp;<strong>read-only</strong>&nbsp;as soon as you create one.</p>
<p>In&nbsp;<strong>SQL Server 2014</strong>&nbsp;this behavior is unchanged and addition to this you can also create ColumnStore index as a Clustered index. And the good thing is that the table having<strong>&ldquo;Clustered ColumnStore&rdquo; index</strong>&nbsp;can also be updated. However there is one more big limitation here that there is&nbsp;<strong>no Clustered Key</strong>&nbsp;with this type if index, thus risking the Uniqueness in the table.</p>
<p><strong>&ndash;&gt;</strong>&nbsp;Here we will see this limitation and a workaround which can be used in some scenarios:</p>
<div class="line number1 index0 alt2"><code class="sql plain">USE tempdb</code></div>
<div class="line number2 index1 alt1"><code class="sql plain">GO</code></div>
<div class="line number3 index2 alt2">&nbsp;</div>
<div class="line number4 index3 alt1"><code class="sql comments">-- Create a simple table with 3 columns having 1st column to contain Unique values:</code></div>
<div class="line number5 index4 alt2"><code class="sql keyword">CREATE</code> <code class="sql keyword">TABLE</code> <code class="sql plain">dbo.TableWithCCI</code></div>
<div class="line number6 index5 alt1"><code class="sql plain">(</code></div>
<div class="line number7 index6 alt2"><code class="sql spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="sql plain">PKCol </code><code class="sql keyword">int</code> <code class="sql color1">NOT</code> <code class="sql color1">NULL</code><code class="sql plain">,</code></div>
<div class="line number8 index7 alt1"><code class="sql spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="sql plain">Foo </code><code class="sql keyword">int</code><code class="sql plain">,</code></div>
<div class="line number9 index8 alt2"><code class="sql spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="sql plain">Bar </code><code class="sql keyword">int</code></div>
<div class="line number10 index9 alt1"><code class="sql plain">)</code></div>
<div class="line number11 index10 alt2"><code class="sql plain">GO</code></div>
<div class="line number12 index11 alt1">&nbsp;</div>
<div class="line number13 index12 alt2"><code class="sql comments">-- Now create a "Clustered ColumnStore" index on this table:</code></div>
<div class="line number14 index13 alt1"><code class="sql keyword">CREATE</code> <code class="sql plain">CLUSTERED COLUMNSTORE </code><code class="sql keyword">INDEX</code> <code class="sql plain">CCI_TableWithCCI </code><code class="sql keyword">ON</code> <code class="sql plain">dbo.TableWithCCI</code></div>
<div class="line number15 index14 alt2"><code class="sql plain">GO</code></div>
<div class="line number15 index14 alt2">
<p><strong>&ndash;&gt; Notice:</strong>&nbsp;While creating this index there is no provision to provided the &ldquo;Clustering Key&rdquo;, as this index includes all of the columns in the table, and stores the entire table by compressing the data and store by column.</p>
<p>On checking the metadata (by ALT+F1) of the table, you will see&nbsp;<strong>NULL</strong>&nbsp;under the&nbsp;<strong>index_keys</strong>column:</p>
<p><img src="https://sqlwithmanoj.files.wordpress.com/2014/07/sqlserver2014_unique_cci.jpg?w=595&amp;h=310" alt="SQLServer2014_Unique_CCI" /></p>
</div>
<div class="line number15 index14 alt2"><span>Now let&rsquo;s check this feature of absence of Uniquenes. We will enter 2 records with same value:</span></div>
<div class="line number15 index14 alt2">
<div class="line number1 index0 alt2"><code class="sql keyword">insert</code> <code class="sql keyword">into</code> <code class="sql plain">dbo.TableWithCCI</code></div>
<div class="line number2 index1 alt1"><code class="sql keyword">select</code> <code class="sql plain">1,2,3</code></div>
<div class="line number3 index2 alt2">&nbsp;</div>
<div class="line number4 index3 alt1"><code class="sql keyword">insert</code> <code class="sql keyword">into</code> <code class="sql plain">dbo.TableWithCCI</code></div>
<div class="line number5 index4 alt2"><code class="sql keyword">select</code> <code class="sql plain">1,22,33</code></div>
<div class="line number6 index5 alt1"><code class="sql plain">GO</code></div>
<div class="line number7 index6 alt2">&nbsp;</div>
<div class="line number8 index7 alt1"><code class="sql keyword">SELECT</code> <code class="sql plain">* </code><code class="sql keyword">FROM</code> <code class="sql plain">dbo.TableWithCCI</code></div>
<div class="line number9 index8 alt2"><code class="sql plain">GO</code></div>
<div class="line number9 index8 alt2">You will see 2 records with same duplicate value.</div>
<p>Now, let&rsquo;s create another Unique index to enforce this constraint:</p>
<div class="line number1 index0 alt2"><code class="sql keyword">CREATE</code> <code class="sql keyword">UNIQUE</code> <code class="sql keyword">INDEX</code> <code class="sql plain">UX_TableWithCCI </code><code class="sql keyword">ON</code> <code class="sql plain">dbo.TableWithCCI(PKCol)</code></div>
<div class="line number2 index1 alt1"><code class="sql plain">GO</code></div>
<div class="line number2 index1 alt1">We get an error that you cannot create more indexes if you have a Clustered ColumnStore index:</div>
<div class="line number2 index1 alt1">
<p><strong><span>Msg 35303, Level 16, State 1, Line 25<br />CREATE INDEX statement failed because a nonclustered index cannot be created on a table that has a clustered columnstore index. Consider replacing the clustered columnstore index with a nonclustered columnstore index.</span></strong></p>
<p><strong>&ndash;&gt; Workaround:</strong>&nbsp;As a workaround we can create an Indexed/Materialized View on top this table, with Clustering Key as the PK (1st column of the table/view):</p>
<div class="line number1 index0 alt2"><code class="sql keyword">CREATE</code> <code class="sql keyword">VIEW</code> <code class="sql plain">dbo.vwTableWithCCI </code></div>
<div class="line number2 index1 alt1"><code class="sql spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="sql keyword">WITH</code> <code class="sql plain">SCHEMABINDING</code></div>
<div class="line number3 index2 alt2"><code class="sql keyword">AS</code></div>
<div class="line number4 index3 alt1"><code class="sql spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="sql keyword">SELECT</code> <code class="sql plain">PKCol, Foo, Bar</code></div>
<div class="line number5 index4 alt2"><code class="sql spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="sql keyword">FROM</code> <code class="sql plain">dbo.TableWithCCI</code></div>
<div class="line number6 index5 alt1"><code class="sql plain">GO</code></div>
<div class="line number7 index6 alt2">&nbsp;</div>
<div class="line number8 index7 alt1"><code class="sql comments">-- Delete duplicate records entered previously:</code></div>
<div class="line number9 index8 alt2"><code class="sql keyword">DELETE</code> <code class="sql keyword">FROM</code> <code class="sql plain">dbo.TableWithCCI</code></div>
<div class="line number10 index9 alt1"><code class="sql plain">GO</code></div>
<div class="line number11 index10 alt2">&nbsp;</div>
<div class="line number12 index11 alt1"><code class="sql comments">-- Create a Unique Clustered Index on top of the View to Materialize it:</code></div>
<div class="line number13 index12 alt2"><code class="sql keyword">CREATE</code> <code class="sql keyword">UNIQUE</code> <code class="sql plain">CLUSTERED </code><code class="sql keyword">INDEX</code> <code class="sql plain">IDX_vwTableWithCCI </code><code class="sql keyword">ON</code> <code class="sql plain">dbo.vwTableWithCCI(PKCol)</code></div>
<div class="line number14 index13 alt1"><code class="sql plain">GO</code></div>
<div class="line number14 index13 alt1"><span>Now let&rsquo;s try to enter duplicate records again and see if these can be entered or not:</span></div>
</div>
<div class="line number1 index0 alt2"><code class="sql keyword">insert</code> <code class="sql keyword">into</code> <code class="sql plain">dbo.TableWithCCI</code></div>
<div class="line number2 index1 alt1"><code class="sql keyword">select</code> <code class="sql plain">1,2,3</code></div>
<div class="line number3 index2 alt2">&nbsp;</div>
<div class="line number4 index3 alt1"><code class="sql keyword">insert</code> <code class="sql keyword">into</code> <code class="sql plain">dbo.TableWithCCI</code></div>
<div class="line number5 index4 alt2"><code class="sql keyword">select</code> <code class="sql plain">1,22,33</code></div>
<div class="line number6 index5 alt1"><code class="sql plain">GO</code></div>
<div class="line number6 index5 alt1">Now, as expected we get an error after we inserted 1st records and tried to insert the 2nd duplicate record:</div>
<div class="line number6 index5 alt1">
<p><strong><span>(1 row(s) affected)<br />Msg 2601, Level 14, State 1, Line 48<br />Cannot insert duplicate key row in object &lsquo;dbo.vwTableWithCCI&rsquo; with unique index &lsquo;IDX_vwTableWithCCI&rsquo;. The duplicate key value is (1).<br />The statement has been terminated.<br /></span></strong></p>
<p>While using this workaround you need to consider this approach if possible. Like in some scenarios where the table is very big and there are frequent updates (INSERT/UPDATE/DELETES) this approach of maintaining another Indexed-View would be expensive. So this approach should be evaluated before implementing.</p>
<div class="line number1 index0 alt2"><code class="sql comments">-- Final Cleanup:</code></div>
<div class="line number2 index1 alt1"><code class="sql keyword">DROP</code> <code class="sql keyword">VIEW</code> <code class="sql plain">dbo.vwTableWithCCI</code></div>
<div class="line number3 index2 alt2"><code class="sql plain">GO</code></div>
<div class="line number4 index3 alt1"><code class="sql keyword">DROP</code> <code class="sql keyword">TABLE</code> <code class="sql plain">dbo.TableWithCCI</code></div>
<div class="line number5 index4 alt2"><code class="sql plain">GO</code></div>
<div class="line number5 index4 alt2"><span>You can also refer to MSDN BOL&nbsp;</span><strong>[<a href="https://msdn.microsoft.com/en-IN/library/dn511016.aspx" target="_blank">here</a>]</strong><span>&nbsp;for checking all limitations with ColumnStore Indexes.</span></div>
<div class="line number5 index4 alt2"><span><br /></span></div>
</div>
<div class="line number5 index4 alt2"><em><strong>Source:</strong>&nbsp;from my personal blog SQLwithManoj:&nbsp;<a href="https://sqlwithmanoj.com/2014/07/24/maintaining-uniqueness-with-clustered-columnstore-index-sql-server-2014/">https://sqlwithmanoj.com/2014/07/24/maintaining-uniqueness-with-clustered-columnstore-index-sql-server-2014/</a></em></div>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Top SQL Blogs – Windows 8 App | from MSDN, MVPs and Top Bloggers</title>
      <link>https://docs.microsoft.com/archive/blogs/manub22/top-sql-blogs-windows-8-app-from-msdn-mvps-and-top-bloggers</link>
      <pubDate>Thu, 13 Mar 2014 21:53:30 GMT</pubDate>
      <dc:creator><![CDATA[Manoj Pandey (manub22)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/manub22/2014/03/13/top-sql-blogs-windows-8-app-from-msdn-mvps-and-top-bloggers/</guid>
      <description><![CDATA[After I published my first App&nbsp;[SQL with Manoj]&nbsp;on Windows 8 Store, I thought to create an...]]></description>
      <content:encoded><![CDATA[<p>After I published my first App&nbsp;<strong>[<a href="https://sqlwithmanoj.wordpress.com/2013/04/20/sqlwithmanoj-now-on-windows-8-store/" target="_blank">SQL with Manoj</a>]</strong>&nbsp;on Windows 8 Store, I thought to create an another App at a broader level, which will cover latest <strong>SQL Server</strong>&nbsp;and <strong>TSQL</strong> topics from <strong>MSDN blogs</strong>, <strong>MVPs</strong> and other famous Bloggers, like Paul S. Randal, Kimberly Trip, Sam Lester, Brent Ozar, etc.</p>
<p>And today I&rsquo;m very happy to announce the release of my 2nd Windows 8 App for and its availability on Windows 8 store.</p>
<div style="text-align: center;" align="center"><strong>[<a href="https://apps.microsoft.com/windows/en-us/app/topsqlblogs/9e2712e9-7f9c-418b-bc17-1da8e47de436" target="_blank"><span>DOWNLOAD "Top SQL Blogs" APP HERE</span></a>]</strong></div>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/69/5228.TopSQLBlogs_Store.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-69/5228.TopSQLBlogs_5F00_Store.png"><img style="display: block; margin-left: auto; margin-right: auto;" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/69/5228.TopSQLBlogs_Store.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-69/5228.TopSQLBlogs_5F00_Store.png" alt="" border="0" /></a></p>
<p>With this App you can view and read SQL Server related topics from various sources (like MSDN blogs, MVPs and other famous Bloggers) at one place.</p>
<p>Please download this App on your Windows 8 PC or Tablet and let me know your feedback.</p>
<p>&nbsp;</p>
<p>Thanks!!!</p>
<p>&nbsp;</p>
<p><em><strong>Disclaimer:</strong>&nbsp;This is my <strong>personal</strong> Win8 App. The items/blogs expressed here are represented by the respective Blog owners and not from Microsoft. For accuracy and official reference refer to MS Books On Line and/or MSDN/TechNet.</em></p>]]></content:encoded>
    </item>
    <item>
      <title>Another reason to use THROW clause instead of RAISERROR</title>
      <link>https://docs.microsoft.com/archive/blogs/manub22/another-reason-to-use-throw-clause-instead-of-raiserror</link>
      <pubDate>Mon, 03 Feb 2014 21:15:00 GMT</pubDate>
      <dc:creator><![CDATA[Manoj Pandey (manub22)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/manub22/2014/02/03/another-reason-to-use-throw-clause-instead-of-raiserror/</guid>
      <description><![CDATA[In my previous post [link] I talked about the new THROW clause introduced in SQL Server 2012 and how...]]></description>
      <content:encoded><![CDATA[<p>In my previous post <strong>[<a href="https://sqlwithmanoj.wordpress.com/2012/12/20/new-throw-statement-in-sql-server-2012-vs-raiserror/" target="_blank">link</a>]</strong> I talked about the new <strong>THROW</strong> clause introduced in SQL Server 2012 and how it is different from the existing <strong>RAISERROR</strong> function.<br /><br /><em>I just stumbled on one more reason to stop using RAISERROR function and start using the new THROW clause.</em><br /><br />There are some SQL statements that throws more than one error message when they go wrong due to some reason.<br /><br /><strong>&gt;&gt;</strong> When using <strong>RAISERROR</strong> function it just returns the last (single) error message and its details, but the previous error message details are not returned by this function.<br /><br /><strong>&gt;&gt;</strong> With the new <strong>THROW</strong> clause you won&rsquo;t see any issue of omitting the previous errors. And it returns all error details as thrown by the SQL statement itself.<br /><br />Let&rsquo;s check this with a small example where we want to take backup of a database, but the folder provided does not exist, and hence it errors out:<br /><br /><strong>&gt;&gt; Example #1:</strong><br />On executing the below BACKUP statement we can see we get 2 errors:</p>
<pre class="scroll"><code class="mysql">BACKUP DATABASE [AdventureWorks2012] <br />TO DISK='E:\FOLDER_NOT_EXISTS\test.bak' </code></pre>
<p>The above code throws 2 errors with Error-Message IDs 3201 &amp; 3013, as shown below:<br /><br /><strong>Error messages:</strong><br /><strong><span style="color: #ff0000;">Msg 3201, Level 16, State 1, <span style="background-color: #ffff00;">Line 2</span></span></strong><br /><strong><span style="color: #ff0000;">Cannot open backup device &lsquo;E:\FOLDER_NOT_EXISTS\test.bak&rsquo;. Operating system error 3(The system cannot find the path specified.).</span></strong><br /><strong><span style="color: #ff0000;">Msg 3013, Level 16, State 1, <span style="background-color: #ffff00;">Line 2</span></span></strong><br /><strong><span style="color: #ff0000;">BACKUP DATABASE is terminating abnormally.</span></strong><br /><br /><strong>&gt;&gt; Example #2:</strong><br />And when you try to use error-handling by using TRY-CATCH and RAISERROR(), it fetches us only 1 error:</p>
<pre class="scroll"><code class="mysql">BEGIN TRY<br />BACKUP DATABASE [AdventureWorks2012] <br />TO DISK='E:\FOLDER_NOT_EXISTS\test.bak'<br />END TRY<br />BEGIN CATCH<br />DECLARE @msg VARCHAR(1000)<br />SET @msg = ERROR_MESSAGE()<br />RAISERROR(@msg,16,0)<br />END CATCH<br /></code></pre>
<p>Here, only 1 error message will be returned, and the message does not show the actual line where error occurred:<br /><br /><strong>Error messages:</strong><br /><strong><span style="color: #ff0000;">Msg 50000, Level 16, State 0, <span style="background-color: #ffff00;">Line 7</span></span></strong><br /><strong><span style="color: #ff0000;">BACKUP DATABASE is terminating abnormally.</span></strong><br /><br /><strong>&gt;&gt; Example #3:</strong><br />But this is not the case with the new THROW clause, as I mentioned previously.<br />It throws all the errors that are originally thrown by the original SQL statement, like below:</p>
<pre class="scroll"><code class="mysql">BEGIN TRY<br />BACKUP DATABASE [AdventureWorks2012] <br />TO DISK='E:\FOLDER_NOT_EXISTS\test.bak'<br />END TRY<br />BEGIN CATCH<br />THROW;<br />END CATCH<br /></code></pre>
<p>The above statement throws both the error details as we saw in the first example, and this message show the exact line number where the error occurred:<br /><strong></strong></p>
<p><strong>Error messages:</strong><br /><span style="color: #ff0000;"><strong>Msg 3201, Level 16, State 1, <span style="background-color: #ffff00;">Line 2</span></strong></span><br /><span style="color: #ff0000;"><strong>Cannot open backup device &lsquo;E:\FOLDER_NOT_EXISTS\test.bak&rsquo;. Operating system error 3(The system cannot find the path specified.).</strong></span><br /><span style="color: #ff0000;"><strong>Msg 3013, Level 16, State 1, <span style="background-color: #ffff00;">Line 2</span></strong></span><br /><span style="color: #ff0000;"><strong>BACKUP DATABASE is terminating abnormally.</strong></span><br /><br />Thus, you must consider using <strong>THROW</strong> clause instead of the <strong>RAISERROR</strong> function if you are in SQL Server 2012 and above.</p>
<p><br />But, it may depend on different conditions and scenarios where you would need either of both the features.</p>
<p>&nbsp;</p>
<p><em style="font-size: 12px;"><strong>Source:</strong>&nbsp;from my personal blog SQLwithManoj:&nbsp;<a href="https://sqlwithmanoj.wordpress.com/2013/01/24/another-reason-to-use-throw-clause-instead-of-raiserror-sql-server-2012/">https://sqlwithmanoj.wordpress.com/2013/01/24/another-reason-to-use-throw-clause-instead-of-raiserror-sql-server-2012/</a></em></p>]]></content:encoded>
    </item>
    <item>
      <title>New THROW statement in SQL Server 2012 (vs RAISERROR)</title>
      <link>https://docs.microsoft.com/archive/blogs/manub22/new-throw-statement-in-sql-server-2012-vs-raiserror</link>
      <pubDate>Mon, 30 Dec 2013 21:51:00 GMT</pubDate>
      <dc:creator><![CDATA[Manoj Pandey (manub22)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/manub22/2013/12/30/new-throw-statement-in-sql-server-2012-vs-raiserror/</guid>
      <description><![CDATA[The new THROW keyword introduced in SQL server 2012 is an improvement over the existing RAISERROR()...]]></description>
      <content:encoded><![CDATA[<p>The new <strong>THROW</strong> keyword introduced in SQL server 2012 is an improvement over the existing <strong>RAISERROR()</strong> statement.&nbsp;<span style="font-size: 12px;">Yes, it&rsquo;s single </span><strong style="font-size: 12px;">&lsquo;E&rsquo;</strong><span style="font-size: 12px;"> in </span><strong style="font-size: 12px;"><span style="color: #ff0000;">RAIS</span>ERROR</strong><span style="font-size: 12px;">.</span></p>
<p>Both RAISERROR &amp; THROW can be used in T-SQL code/script to raise and throw error within a TRY-CATCH block. Check my previous post for TRY-CATCH block, <strong>[<a title="TRY-CATCH" href="https://sqlwithmanoj.wordpress.com/2010/06/16/try-catch-exception-handling/" target="_blank">link</a>]</strong>.<br /><br /><strong>&gt;&gt; With RAISERROR</strong> developers had to use different ERROR_xxxx() system functions to get the error details to pass through the RAISERROR() statement, like:<br />- ERROR_NUMBER()<br />- ERROR_MESSAGE()<br />- ERROR_SEVERITY()<br />- ERROR_STATE()<br /><br /><strong>let&rsquo;s see an example:</strong></p>
<pre class="scroll"><code class="mysql">-- Using RAISERROR()<br />DECLARE <br /> @ERR_MSG AS NVARCHAR(4000)<br /> ,@ERR_SEV AS SMALLINT<br /> ,@ERR_STA AS SMALLINT<br /> <br />BEGIN TRY<br /> SELECT 1/0 as DivideByZero<br />END TRY<br />BEGIN CATCH<br /> SELECT @ERR_MSG = ERROR_MESSAGE(),<br /> @ERR_SEV =ERROR_SEVERITY(),<br /> @ERR_STA = ERROR_STATE()<br /></code></pre>
<pre class="scroll"><code class="mysql"> SET @ERR_MSG= 'Error occurred while retrieving the data from database: ' + @ERR_MSG<br /> <br /> RAISERROR (@ERR_MSG, @ERR_SEV, @ERR_STA) WITH NOWAIT<br />END CATCH<br />GO</code></pre>
<p><strong><span style="text-decoration: underline;">Output</span>:</strong><br /><strong>(0 row(s) affected)</strong><br /><span style="color: #ff0000;"><strong>Msg 50000, Level 16, State 1, <span style="background-color: #ffff00;">Line 15</span></strong></span><br /><span style="color: #ff0000;"><strong>Error occurred while retrieving the data from database: Divide by zero error encountered.</strong></span><br /><br />The RAISERROR() can take first argument as <strong>message_id</strong> also instead of the message. But if you want to pass the message_id then it has to be in <strong>sys.messages</strong><br /><br /><strong>&gt;&gt;&nbsp;With THROW</strong> the benefit is: it is not mandatory to pass any parameter to raise an exception.<br />Just using the THROW; statement will get the error details and raise it, as shown below:</p>
<pre class="scroll"><code class="mysql">-- Using THROW - 1<br />BEGIN TRY<br /> SELECT 1/0 as DivideByZero<br />END TRY<br />BEGIN CATCH<br /> THROW;<br />END CATCH<br />GO</code></pre>
<p><strong><span style="text-decoration: underline;">Output</span>:</strong><br /><strong>(0 row(s) affected)</strong><br /><span style="color: #ff0000;"><strong>Msg 8134, Level 16, State 1, <span style="background-color: #00ff00;">Line 2</span></strong></span><br /><span style="color: #ff0000;"><strong>Divide by zero error encountered.</strong></span><br /><br />As you see in the Output above, the error message thrown is the default one. But you can also add your customized message, we will see below.</p>
<p><strong style="font-size: 12px;"><span style="color: #ff0000;">IMP NOTE:</span>&nbsp;</strong>Default<strong style="font-size: 12px;"> THROW</strong><span style="font-size: 12px;">&nbsp;statement will show the exact line where the exception was occurred, here the line number is 2 (highlighted GREEN above). But </span><strong style="font-size: 12px;">RAISERROR()</strong><span style="font-size: 12px;"> will show the line number where the RAISERROR statement was executed i.e. Line 15 (highlighted YELLOW above)&nbsp;and not the actual exception.</span></p>
<p>&nbsp;</p>
<p>Also passing the <strong>message_id</strong> won&rsquo;t require it to be stored in <strong>sys.messages</strong>, let&rsquo;s check this:</p>
<pre class="scroll"><code class="mysql">-- Using THROW - 2<br />DECLARE <br /> @ERR_MSG AS NVARCHAR(4000) <br /> ,@ERR_STA AS SMALLINT <br /> <br />BEGIN TRY<br /> SELECT 1/0 as DivideByZero<br />END TRY<br />BEGIN CATCH<br /> SELECT @ERR_MSG = ERROR_MESSAGE(),<br /> @ERR_STA = ERROR_STATE()<br /> <br /> SET @ERR_MSG= 'Error occurred while retrieving the data from database: ' + @ERR_MSG;<br /> <br /> THROW 50001, @ERR_MSG, @ERR_STA;<br />END CATCH<br />GO</code></pre>
<p><strong><span style="text-decoration: underline;">Output</span>:</strong><br /><strong>(0 row(s) affected)</strong><br /><span style="color: #ff0000;"><strong>Msg 50001, Level 16, State 1, <span style="background-color: #00ff00;">Line 14</span></strong></span><br /><span style="color: #ff0000;"><strong>Error occurred while retrieving the data from database: Divide by zero error encountered.</strong></span></p>
<p>But if you parameterize the&nbsp;<strong>THROW</strong><span>&nbsp;statement as above it will not show the actual position of&nbsp;exception occurrence, and the behavior will be same as RAISERROR(). As with <strong>RAISERROR()</strong> you've to provide mandatory params, so there is no way to get the actual position of Line where the error occurred.</span></p>
<p><br />As per MSBOL following are the difference between RAISERROR &amp; THROW:</p>
<table>
<tbody>
<tr><th>
<p>RAISERROR statement</p>
</th><th>
<p>THROW statement</p>
</th></tr>
<tr>
<td>
<p>If a msg_id is passed to RAISERROR, the ID must be defined in sys.messages.</p>
</td>
<td>
<p>The error_number parameter does not have to be defined in sys.messages.</p>
</td>
</tr>
<tr>
<td>
<p>The msg_str parameter can contain printf formatting styles.</p>
</td>
<td>
<p>The message parameter does not accept printf style formatting.</p>
</td>
</tr>
<tr>
<td>
<p>The severity parameter specifies the severity of the exception.</p>
</td>
<td>
<p>There is no severity parameter. The exception severity is always set to 16.</p>
</td>
</tr>
</tbody>
</table>
<p><em><strong>NOTE:</strong>&nbsp;As per MS BOL for exception handling in new development work THROW must be used instead of RAISERROR.</em></p>
<p><em><br /></em></p>
<p><em><strong>Source:</strong>&nbsp;from my personal blog SQLwithManoj:&nbsp;<a style="font-size: 12px;" href="https://sqlwithmanoj.wordpress.com/2012/12/20/new-throw-statement-in-sql-server-2012-vs-raiserror/">https://sqlwithmanoj.wordpress.com/2012/12/20/new-throw-statement-in-sql-server-2012-vs-raiserror/</a></em></p>]]></content:encoded>
    </item>
    <item>
      <title>Use new TRY_PARSE() instead of ISNUMERIC() | SQL Server 2012</title>
      <link>https://docs.microsoft.com/archive/blogs/manub22/use-new-try_parse-instead-of-isnumeric-sql-server-2012</link>
      <pubDate>Mon, 23 Dec 2013 22:29:00 GMT</pubDate>
      <dc:creator><![CDATA[Manoj Pandey (manub22)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/manub22/2013/12/23/use-new-try_parse-instead-of-isnumeric-sql-server-2012/</guid>
      <description><![CDATA[I was working on a legacy T-SQL script written initially on SQL Server 2005 and I was facing an...]]></description>
      <content:encoded><![CDATA[<p>I was working on a legacy T-SQL script written initially on SQL Server 2005 and I was facing an unexpected behavior. The code was giving me unexpected records, I tried to dig into it and found that <strong>ISNUMERIC()</strong> function applied to a column was giving me extra records with value like <strong>"," (comma) &amp;&nbsp;"." (period)</strong>.</p>
<p><strong>=&gt;</strong> So, to validate it I executed following code and found that ISNUMERIC() function also passes these characters as numbers:</p>
<pre class="scroll"><code class="mysql">SELECT <br /> ISNUMERIC('123') as '123'<br /> ,ISNUMERIC('.') as '.' --Period<br /> ,ISNUMERIC(',') as ',' --Comma</code></pre>
<p>Function ISNUMERIC() returns "1" when the input expression evaluates to a valid numeric data type; otherwise it returns "0". But the above query will return value "1" for all 3 column values, validating them as numeric values, but that's not correct for last 2 columns.<br /><br /><strong>=&gt;</strong>&nbsp;And not only this, ISNUMERIC() function treats few more characters as numeric, like: - (minus), + (plus), $ (dollar), \ (back slash), check this:</p>
<pre class="scroll"><code class="mysql">SELECT <br /> ISNUMERIC('123') as '123'<br /> ,ISNUMERIC('abc') as 'abc'<br /> ,ISNUMERIC('-') as '-'<br /> ,ISNUMERIC('+') as '+'<br /> ,ISNUMERIC('$') as '$'<br /> ,ISNUMERIC('.') as '.'<br /> ,ISNUMERIC(',') as ','<br /> ,ISNUMERIC('\') as '\'<br /></code></pre>
<p>This will return "0" for second column containing value "abc", and value "1" for rest of the column values.</p>
<p><br />So, you will need to be very careful while using ISNUMERIC() function and have to consider all these possible validations on your T-SQL logic.<br /><br /><strong>- OR -</strong><br /><br />Switch to new <strong>TRY_PARSE()</strong> function introduced in <strong>SQL Server 2012</strong>.<br /><br /><strong>=&gt;</strong> The TRY_PARSE() function returns the result of an expression, translated to the requested Data-Type, or NULL if the Cast fails. Let's check how TRY_PARSE() validates above character values as numeric:</p>
<pre class="scroll"><code class="mysql">SELECT <br /> TRY_PARSE('123' as int) as '123'<br /> ,TRY_PARSE('abc' as int) as 'abc'<br /> ,TRY_PARSE('-' as int) as '-'<br /> ,TRY_PARSE('+' as int) as '+'<br /> ,TRY_PARSE('$' as int) as '$'<br /> ,TRY_PARSE('.' as int) as '.'<br /> ,TRY_PARSE(',' as int) as ','<br /> ,TRY_PARSE('\' as int) as '\'<br /></code></pre>
<p>So, the above query gives me expected results by validating first column value as numeric and rest as invalid and returns NULL for those.</p>
<p><br /><strong>=&gt;</strong> TRY_PARSE() can be used with other NUMERIC &amp; DATETIME data-types for validation, like:</p>
<pre class="scroll"><code class="mysql">SELECT <br /> TRY_PARSE('123' as int) as '123'<br /> ,TRY_PARSE('123.0' as float) as '123.0'<br /> ,TRY_PARSE('123.1' as decimal(4,1)) as '123.1'<br /> ,TRY_PARSE('$123.55' as money) as '$123.55'<br /> ,TRY_PARSE('2013/09/20' as datetime) as '2013/09/20'<br /> </code></pre>
<p>... will give expected results :)</p>
<p>&nbsp;</p>
<p><em><strong>Source:</strong>&nbsp;from my personal blog SQLwithManoj:&nbsp;<a href="https://sqlwithmanoj.wordpress.com/2013/09/20/use-new-try_parse-instead-of-isnumeric-sql-server-2012/">https://sqlwithmanoj.wordpress.com/2013/09/20/use-new-try_parse-instead-of-isnumeric-sql-server-2012/</a></em></p>]]></content:encoded>
    </item>
    <item>
      <title>Using FullText search with FileTables in SQL Server 2012</title>
      <link>https://docs.microsoft.com/archive/blogs/manub22/using-fulltext-search-with-filetables-in-sql-server-2012</link>
      <pubDate>Fri, 21 Dec 2012 06:11:00 GMT</pubDate>
      <dc:creator><![CDATA[Manoj Pandey (manub22)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/manub22/2012/12/21/using-fulltext-search-with-filetables-in-sql-server-2012/</guid>
      <description><![CDATA[In my previous post sometime back I talked about&nbsp;FILETABLES,&nbsp;[link]. This is a new feature...]]></description>
      <content:encoded><![CDATA[<p>In my previous post sometime back I talked about&nbsp;<strong>FILETABLES</strong>,&nbsp;<strong>[<a href="https://blogs.msdn.com/b/manub22/archive/2012/03/01/sql-server-2012-a-k-a-denali-new-feature-filetables.aspx" target="_blank">link</a>]</strong>. This is a new feature introduced in SQL Server 2012, which is built on top of&nbsp;<strong>FILESTREAM</strong>.</p>
<p>I also talked about how we can use them to store files and retrieve the information from them.</p>
<p>&nbsp;</p>
<p>Here, in this post we will see how we can search in the files stored in FileTables using an existing feature i.e.&nbsp;<strong>&ldquo;FullText Search&rdquo;</strong>.</p>
<p>So, let&rsquo;s check this by an example. I&rsquo;ll be using the same code from my previous post to create a new Database and Filetables.</p>
<p>&nbsp;</p>
<p><em><strong><a href="https://sqlwithmanoj.com/2012/12/21/using-fulltext-search-with-filetables-in-sql-server-2012/" target="_blank">Check here for full details</a>.</strong></em></p>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server 2012 (a.k.a Denali) – New feature | FileTables</title>
      <link>https://docs.microsoft.com/archive/blogs/manub22/sql-server-2012-a-k-a-denali-new-feature-filetables</link>
      <pubDate>Thu, 01 Mar 2012 01:24:00 GMT</pubDate>
      <dc:creator><![CDATA[Manoj Pandey (manub22)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/manub22/2012/03/01/sql-server-2012-a-k-a-denali-new-feature-filetables/</guid>
      <description><![CDATA[new kid on the blog... this is my first post on MSDN Blogs after joining Microsoft very recently...]]></description>
      <content:encoded><![CDATA[<p>new kid on the blog... this is my first post on MSDN Blogs after joining Microsoft very recently (Jan-2012).</p>
<p>I also used to blog on my personal bog site i.e. <a href="https://sqlwithmanoj.com" target="_blank">https://sqlwithmanoj.com</a>&nbsp;about SQL Server (TSQL) and I'll start my 1st blog post here by referring to my latest article.</p>
<p>&nbsp;</p>
<p>SQL Server 2012&nbsp;(a.k.a Denali) is yet to be launched and entire Microsoft community is very excited for this event to occur, so am I. There are lot of articles comming up on various forums and blogs about new features and capabilities of SQL Server 2012.</p>
<p>Here I'll discuss about a new feature of SQL Server 2012 that came to my notice and grabbed my attention a few days back,&nbsp;It's called <strong>FileTables</strong>.</p>
<p>FilesTables is kind of an extention to <strong>FILESTREAM</strong> introduced with SQL Server 2008 to support files in Windows file system instead of storing them in SQL tables. This new feature brings support for the windows file namespace and compatibality with Windows Apps to the data files stored in SQL Server.</p>
<p>As per MS BOL, <strong>FileTable</strong> lets an application integrate its storage and data management components, and provides integrated SQL Server services,&nbsp;including: full-text search and semantic search&nbsp;- over unstructured data and metadata. In other words, you can store files and documents in special tables in SQL Server called <strong>FileTables</strong>, but access them from Windows applications as if they were stored in the file system, without making any changes to your client applications. Or can store directly in Windows file system and can access, query and&nbsp;update the files directly from SQL Server by issuing simple DML statements.</p>
<p>&nbsp;</p>
<p>I've posted about this article with more details and a&nbsp;simple example can be <a href="https://sqlwithmanoj.com/2012/02/28/sql-server-2012-a-k-a-denali-new-feature-filetables/" target="_blank">viewed here</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>DYNAMIC PIVOT</title>
      <link>https://docs.microsoft.com/archive/blogs/manub22/dynamic-pivot</link>
      <pubDate>Mon, 30 Jan 2012 04:24:00 GMT</pubDate>
      <dc:creator><![CDATA[Manoj Pandey (manub22)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/manub22/2012/01/30/dynamic-pivot/</guid>
      <description><![CDATA[My previous&nbsp;PIVOT UNPIVOT&nbsp;post describes to organize data in a cross tab fashion or to...]]></description>
      <content:encoded><![CDATA[<p>My previous&nbsp;<strong><a href="https://sqlwithmanoj.wordpress.com/2009/04/12/ms-sql-server-2005-new-feature-pivot-and-unpivot/" target="_blank">PIVOT UNPIVOT</a></strong>&nbsp;post describes to organize data in a cross tab fashion or to transpose columns into rows and vice-versa.<p>This is fine only when you know how many columns you need. But when columns vary according to the query then how could you apply them on your scripts. The only way is to store them in a string variable at runtime and apply them in a dynamic SQL query, shown below.</p><p>This problem was also discussed on MSDN&rsquo;s following link:<a href="https://social.msdn.microsoft.com/Forums/en/transactsql/thread/26f86fd6-6d06-4cc5-9723-9ee4685bd48a" target="_blank">https://social.msdn.microsoft.com/Forums/en/transactsql/thread/26f86fd6-6d06-4cc5-9723-9ee4685bd48a</a>&nbsp;where I proposed an answer also described below:</p><p class="scroll"><code class="mysql">USE [tempdb]<br> GO<br> <br> -- Create test tables<br> create table #studMarks (<br> studId int, <br> subjekt varchar(20), <br> marks int<br> )<br> <br> -- Insert test data<br> insert into #studMarks values (1, 'math', 90)<br> insert into #studMarks values (1, 'science', 80)<br> insert into #studMarks values (1, 'english', 70)<br> insert into #studMarks values (1, 'history', 60)<br> <br> insert into #studMarks values (2, 'math', 80)<br> insert into #studMarks values (2, 'science', 60)<br> insert into #studMarks values (2, 'english', 90)<br> insert into #studMarks values (2, 'history', 70)<br> <br> -- Static PIVOT<br> select StudId, [math], [science], [english], [history]<br> from (select StudId, subjekt, marks <br> from #StudMarks)p<br> PIVOT(MAX (marks) FOR subjekt IN ([math], [science], [english], [history])<br> ) AS pvt<br> ORDER BY StudId</code></p><p class="scroll"><strong>Output:</strong></p><table border="0">
<tbody>
<tr>
<td><strong>StudId</strong></td>
<td><strong>math</strong></td>
<td><strong>science</strong></td>
<td><strong>english</strong></td>
<td><strong>history</strong></td>
</tr>
<tr>
<td>1</td>
<td>90</td>
<td>80</td>
<td>70</td>
<td>60</td>
</tr>
<tr>
<td>2</td>
<td>80</td>
<td>60</td>
<td>90</td>
<td>70</td>
</tr>
</tbody>
</table><p class="scroll">&nbsp;</p><p class="scroll"><strong>- Dynamic PIVOT:</strong></p><p class="scroll"><code class="mysql">-- Lets add one more record on both the tables to check the results<br> insert into #studMarks values (1, 'economics', 95)<br> insert into #studMarks values (2, 'economics', 85)<br> <br> declare @col varchar(1000)<br> declare @sql varchar(2000)<br> <br> select @col = COALESCE(@col + ', ','') + QUOTENAME(subjekt)<br> from (select distinct subjekt as subjekt from #StudMarks) K<br> <br>--select @col<br> <br> set @sql = '<br> select StudId, ' + @col + '<br> from (select StudId, subjekt, marks <br> from #StudMarks)p<br> PIVOT(MAX (marks) FOR subjekt IN ( ' + @col + ' )<br> ) AS pvt<br> ORDER BY StudId'<br> <br>-- print @sql<br> <br> exec (@sql)</code></p><p class="scroll"><strong>Output:</strong></p><table border="0">
<tbody>
<tr>
<td><strong>StudId</strong></td>
<td><strong>economics</strong></td>
<td><strong>english</strong></td>
<td><strong>history</strong></td>
<td><strong>math</strong></td>
<td><strong>science</strong></td>
</tr>
<tr>
<td>1</td>
<td>95</td>
<td>70</td>
<td>60</td>
<td>90</td>
<td>80</td>
</tr>
<tr>
<td>2</td>
<td>85</td>
<td>90</td>
<td>70</td>
<td>80</td>
<td>60</td>
</tr>
</tbody>
</table><p>So, whenever any new subject &amp; marks are added in the table against any student the above Dynamic PIVOT statement will take care of it and add a new column for it.</p><p>&nbsp;</p><p><strong>- Final Cleanup</strong></p><p class="scroll"><code class="mysql">drop table #studMarks</code></p><p class="scroll">&nbsp;</p><p class="scroll"><span style="font-family: verdana, geneva;"><em><code class="mysql"><strong>Source:</strong> from my personal blog SQLwithManoj:&nbsp;<a href="https://sqlwithmanoj.wordpress.com/2011/01/25/dynamic-pivot/">https://sqlwithmanoj.wordpress.com/2011/01/25/dynamic-pivot/</a> </code></em></span></p></p>
]]></content:encoded>
    </item>
  </channel>
</rss>