<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Jacob's Blog</title><link>http://beyondrelational.com/blogs/jacob/default.aspx</link><description>My technology blog on SQL Server, TSQL, XML, FILESTREAM and other areas of SQL Server. </description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ExploringBeyondRelational" /><feedburner:info uri="exploringbeyondrelational" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>XQuery Lab 65 – Restructuring an XML document using FLWOR</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/vw5nQFO9oVs/xquery-lab-65-restructuring-an-xml-document-using-flwor.aspx</link><pubDate>Fri, 09 Dec 2011 11:33:07 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:14869</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=14869</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=14869</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/12/09/xquery-lab-65-restructuring-an-xml-document-using-flwor.aspx#comments</comments><description>&lt;p&gt;I found this question in &lt;a href="http://www.sqlservercentral.com/Forums/Topic885210-356-2.aspx#bm1219220"&gt;this&lt;/a&gt; SSC forum thread requesting help to shape the XML document. Here is the input XML document.&lt;/p&gt;  &lt;pre class="brush: xml"&gt;&amp;lt;Root&amp;gt;
	&amp;lt;Student&amp;gt;Jhon &amp;lt;/Student&amp;gt;
	&amp;lt;Student&amp;gt; Luka &amp;lt;/Student&amp;gt;
	&amp;lt;Post&amp;gt;1&amp;lt;/Post&amp;gt;
	&amp;lt;Post&amp;gt;2&amp;lt;/Post&amp;gt;
&amp;lt;/Root&amp;gt;&lt;/pre&gt;

&lt;p&gt;The expected output is as follows.&lt;/p&gt;

&lt;pre class="brush: xml"&gt;&amp;lt;Root&amp;gt;
  &amp;lt;Students&amp;gt;
    &amp;lt;Student&amp;gt;Jhon &amp;lt;/Student&amp;gt;
    &amp;lt;Student&amp;gt; Luka &amp;lt;/Student&amp;gt;
  &amp;lt;/Students&amp;gt;
  &amp;lt;Posts&amp;gt;
    &amp;lt;Post&amp;gt;1&amp;lt;/Post&amp;gt;
    &amp;lt;Post&amp;gt;2&amp;lt;/Post&amp;gt;
  &amp;lt;/Posts&amp;gt;
&amp;lt;/Root&amp;gt;&lt;/pre&gt;

&lt;p&gt;This type of formatting can be achieved through a simple FLWOR operation. &lt;/p&gt;

&lt;pre class="brush: sql"&gt;DECLARE @x XML = &amp;#39;
&amp;lt;Root&amp;gt;
	&amp;lt;Student&amp;gt;Jhon &amp;lt;/Student&amp;gt;
	&amp;lt;Student&amp;gt; Luka &amp;lt;/Student&amp;gt;
	&amp;lt;Post&amp;gt;1&amp;lt;/Post&amp;gt;
	&amp;lt;Post&amp;gt;2&amp;lt;/Post&amp;gt;
&amp;lt;/Root&amp;gt;&amp;#39;

SELECT @x.query (&amp;#39;
	for $i in (Root)
	let $s := $i/Student
	let $p := $i/Post
	return
		&amp;lt;Root&amp;gt;
			&amp;lt;Students&amp;gt; {$s} &amp;lt;/Students&amp;gt;
			&amp;lt;Posts&amp;gt;{$p}&amp;lt;/Posts&amp;gt;
		&amp;lt;/Root&amp;gt;
&amp;#39;)

/*
Produces: 
&amp;lt;Root&amp;gt;
  &amp;lt;Students&amp;gt;
    &amp;lt;Student&amp;gt;Jhon &amp;lt;/Student&amp;gt;
    &amp;lt;Student&amp;gt; Luka &amp;lt;/Student&amp;gt;
  &amp;lt;/Students&amp;gt;
  &amp;lt;Posts&amp;gt;
    &amp;lt;Post&amp;gt;1&amp;lt;/Post&amp;gt;
    &amp;lt;Post&amp;gt;2&amp;lt;/Post&amp;gt;
  &amp;lt;/Posts&amp;gt;
&amp;lt;/Root&amp;gt;
*/&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;View All Labs: &lt;/b&gt;&lt;a href="http://beyondrelational.com/blogs/jacob/archive/2008/06/26/xquery-labs-a-collection-of-xquery-sample-scripts.aspx"&gt;XQuery Labs - A Collection of XQuery Sample Scripts and Tutorials&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=14869" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/vw5nQFO9oVs" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery/default.aspx">XQuery</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery+Tutorials/default.aspx">XQuery Tutorials</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery+Lab/default.aspx">XQuery Lab</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery+Functions/default.aspx">XQuery Functions</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery+in+TSQL/default.aspx">XQuery in TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery+Training/default.aspx">XQuery Training</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery+Tutorial/default.aspx">XQuery Tutorial</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/12/09/xquery-lab-65-restructuring-an-xml-document-using-flwor.aspx</feedburner:origLink></item><item><title>SQL Server book from Pinal Dave</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/2tmgzEWmDP4/sql-server-book-from-pinal-dave.aspx</link><pubDate>Mon, 08 Aug 2011 06:51:54 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:13070</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=13070</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=13070</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/08/08/sql-server-book-from-pinal-dave.aspx#comments</comments><description>&lt;p&gt;&lt;img style="margin:0px 6px 0px 0px;display:inline;float:left;" align="left" src="http://www.pinaldave.com/bimg/joes2pros4.jpg" width="150" height="204" alt="" /&gt;&lt;a href="http://blog.sqlauthority.com/" target="_blank"&gt;Pinal Dave&lt;/a&gt; is an inspiration for a large number of SQL Server professionals all over the world. He is a great teacher who knows how to explain any complex stuff in very simple words and examples that everyone understands. That is the reason why his &lt;a href="http://blog.sqlauthority.com/" target="_blank"&gt;blog&lt;/a&gt; is considered to be one of the best source of reference for SQL Server related stuff.&lt;/p&gt;  &lt;p&gt;Pinal’s blog has helped thousands of people learn SQL Server. Very often I end up on his blog when searching for some SQL Server stuff online. He is a great teacher, who is always willing to travel to any extend if requested to present in a SQL Server group. He has done a large number of SQL Server training sessions and workshops all over India and US. &lt;/p&gt;  &lt;p&gt;I was not surprised when Microsoft picked him and gave him the role of SQL Server Evangelist. They are known for acquiring the ‘best’, no matter whether it is a company, product or a person. Vinod Kumar, Microsoft evangelist and a mentor and role model for many of us, has already set up a very high standard for anyone following his foot steps. And then the experts at MS picked the right person and put him in the right place for the benefit or the entire SQL Server community in India. That gives us a lot of reasons to smile.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;SQL Programming Joes 2 Pros&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Pinal has been teaching the SQL Server community in a number of ways. In addition to regular blog posts, he has been contributing a lot in the form of Web casts, Presentations, workshops etc. And finally, to add sweet to the dessert, he announced a SQL Server book which has made many of us quite happy and proud. I am very excited and waiting for my copy of the book, which he promised is on the way!&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Get your free copy of “SQL Programming Joes 2 Pros”&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Pinal has announced a &lt;a href="http://blog.sqlauthority.com/2011/08/01/sql-server-win-a-book-a-day-contest-rules-day-0-of-35/" target="_blank"&gt;contest&lt;/a&gt; on his blog where he will give away 70 copies of his book for free. He is writing a 35 days series of blog posts where he shares a number of SQL Server tips and tricks that you can apply in your day-to-day SQL Server life. To get a copy of the book, all you need to do is to read his posts carefully and answer a few simple questions. Once done, wait for the postman or courier boy to knock your door and deliver you a printed copy of the book. &lt;/p&gt;  &lt;p&gt;I would like to invite everyone to &lt;a href="http://blog.sqlauthority.com/2011/08/01/sql-server-win-a-book-a-day-contest-rules-day-0-of-35/" target="_blank"&gt;read the series&lt;/a&gt;. Whether you win a free copy of the book or not, it is guaranteed that you will certainly learn quite a lot from the series. Thank you Pinal for writing this book and giving us yet another reason to be proud of your achievements!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=13070" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/2tmgzEWmDP4" height="1" width="1"/&gt;</description><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/08/08/sql-server-book-from-pinal-dave.aspx</feedburner:origLink></item><item><title>XQuery Lab 64 – Reading values from an XML column</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/btkXNtJ08Y8/xquery-lab-64-reading-values-from-an-xml-column.aspx</link><pubDate>Mon, 18 Jul 2011 07:19:02 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:12880</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=12880</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=12880</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/07/18/xquery-lab-64-reading-values-from-an-xml-column.aspx#comments</comments><description>&lt;p&gt;I got a question in my &lt;a href="http://beyondrelational.com/ask/jacob/questions/913/sql-using-xquery.aspx" target="_blank"&gt;personal forum&lt;/a&gt; this morning requesting help to read values from an XML column. My first reaction was “Well, there is an XQuery lab demonstrating this!”. However, after reviewing the existing XQuery labs, I realized there are no posts demonstrating this. &lt;/p&gt;  &lt;p&gt;Here is a simple example that demonstrates how to read values from an XML column.&lt;/p&gt;  &lt;pre class="brush: sql"&gt;DECLARE @t TABLE (
	ID INT IDENTITY,
	Data XML
)

INSERT INTO @t (Data)
SELECT &amp;#39;&amp;lt;employee name=&amp;quot;Jacob&amp;quot; /&amp;gt;&amp;#39; UNION ALL
SELECT &amp;#39;&amp;lt;employee name=&amp;quot;Michael&amp;quot; /&amp;gt;&amp;#39;

SELECT
	x.value(&amp;#39;@Name[1]&amp;#39;, &amp;#39;VARCHAR(20)&amp;#39;) AS Name
FROM @t t
CROSS APPLY Data.nodes(&amp;#39;/Employee&amp;#39;) a(x)
/*
Name
--------------------
Jacob
Michael
*/&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;View All Labs: &lt;/b&gt;&lt;a href="http://beyondrelational.com/blogs/jacob/archive/2008/06/26/xquery-labs-a-collection-of-xquery-sample-scripts.aspx"&gt;XQuery Labs - A Collection of XQuery Sample Scripts and Tutorials&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=12880" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/btkXNtJ08Y8" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XML/default.aspx">XML</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery/default.aspx">XQuery</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQL+SERVER/default.aspx">SQL SERVER</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/07/18/xquery-lab-64-reading-values-from-an-xml-column.aspx</feedburner:origLink></item><item><title>SQL Server–Partitioning FILESTREAM data with RANGE LEFT does not work</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/3968T-J1760/sql-server-partitioning-filestream-data-with-range-left-does-not-work.aspx</link><pubDate>Sun, 12 Jun 2011 17:15:10 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:12565</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=12565</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=12565</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/06/12/sql-server-partitioning-filestream-data-with-range-left-does-not-work.aspx#comments</comments><description>&lt;p&gt;One of the problems I came across while writing the partitioning chapter for my FILESTREAM book is that the partitioning does not work correctly with RANGE LEFT. It works as expected when using RANGE RIGHT. Something is wrong with RANGE LEFT and the problem exists in SQL Server 2008, R2 and Denali CTP1.&lt;/p&gt;  &lt;p&gt;I created a repro script and wanted to submit a connect bug. However, the connect page does not allow me to post scripts longer than 2000 characters. So I thought of posting the script here and add a link to this post in the connect item. Here is the repro script for those of you who are interested to try it, and here is the &lt;a href="https://connect.microsoft.com/SQLServer/feedback/details/675124/filestream-partitioning-does-not-work-when-using-range-left" target="_blank"&gt;connect item I submitted&lt;/a&gt;.&lt;/p&gt;  &lt;pre class="brush: sql"&gt;-- -----------------------------------------------
-- Create the database
-- -----------------------------------------------
USE master
GO

IF DB_ID(&amp;#39;NorthPole&amp;#39;) IS NOT NULL 
	DROP DATABASE NorthPole 
GO

CREATE DATABASE NorthPole ON
PRIMARY ( 
    NAME = NorthPoleData1, 
    FILENAME = &amp;#39;C:\Demos\Data\NorthPoleData1.mdf&amp;#39;),
FILEGROUP NorthPoleDB2(
    NAME = NorthPoleData2, 
    FILENAME = &amp;#39;C:\Demos\Data\NorthPoleData2.ndf&amp;#39;),
FILEGROUP NorthPoleFS1 CONTAINS FILESTREAM DEFAULT( 
    NAME = NorthPoleFS1,
    FILENAME = &amp;#39;C:\Demos\FS\NorthPoleFS1&amp;#39;),
FILEGROUP NorthPoleFS2 CONTAINS FILESTREAM( 
    NAME = NorthPoleFS2,
    FILENAME = &amp;#39;C:\Demos\FS\NorthPoleFS2&amp;#39;)
LOG ON ( 
    NAME = NorthPoleLOG,
    FILENAME = &amp;#39;C:\Demos\Data\NorthPoleLOG.ldf&amp;#39;)
GO

-- -----------------------------------------------
-- Create Partition Function and Scheme
-- -----------------------------------------------
USE NorthPole 
GO

CREATE PARTITION FUNCTION NPPartFN (INT) AS 
RANGE LEFT FOR VALUES (3)

CREATE PARTITION SCHEME NPPartDBSch AS 
PARTITION NPPartFN TO([PRIMARY],[NorthPoleDB2]) 
GO

CREATE PARTITION SCHEME NPPartFSSch AS 
PARTITION NPPartFN TO(NorthPoleFS1, NorthPoleFS2) 
GO

-- -----------------------------------------------
-- Create Table
-- -----------------------------------------------
CREATE TABLE [dbo].[Items](
	[ItemID] [int] IDENTITY(1,1) PRIMARY KEY ON NPPartDBSch(ItemID),
	[ItemGuid] [uniqueidentifier] ROWGUIDCOL  NOT NULL 
		UNIQUE ON [PRIMARY],
	[ItemNumber] [varchar](20) NULL,
	[ItemDescription] [varchar](50) NULL,
	[ItemImage] [varbinary](max) FILESTREAM  NULL
) ON NPPartDBSch(ItemID)
FILESTREAM_ON NPPartFSSch

-- -----------------------------------------------
-- Insert 6 Rows. 1-3 will go to FS1 and 4-6 will
--   go to FS2
-- -----------------------------------------------
INSERT INTO Items(itemguid, itemnumber, itemdescription, ItemImage)
SELECT NEWID(), &amp;#39;ITM001&amp;#39;, &amp;#39;Item 1&amp;#39;, CAST(1 AS VARBINARY(MAX))
UNION ALL
SELECT NEWID(), &amp;#39;ITM002&amp;#39;, &amp;#39;Item 2&amp;#39;, CAST(2 AS VARBINARY(MAX))
UNION ALL
SELECT NEWID(), &amp;#39;ITM003&amp;#39;, &amp;#39;Item 3&amp;#39;, CAST(3 AS VARBINARY(MAX))
UNION ALL
SELECT NEWID(), &amp;#39;ITM004&amp;#39;, &amp;#39;Item 4&amp;#39;, CAST(4 AS VARBINARY(MAX))
UNION ALL
SELECT NEWID(), &amp;#39;ITM005&amp;#39;, &amp;#39;Item 5&amp;#39;, CAST(5 AS VARBINARY(MAX))
UNION ALL
SELECT NEWID(), &amp;#39;ITM006&amp;#39;, &amp;#39;Item 6&amp;#39;, CAST(6 AS VARBINARY(MAX))


-- -----------------------------------------------
-- Add a new file group (DB and FS)
-- -----------------------------------------------
ALTER DATABASE NorthPole 
ADD FILEGROUP NorthPoleFS3 CONTAINS FILESTREAM

ALTER database NorthPole 
ADD FILE 
( 
    NAME = &amp;#39;NorthPoleFS3&amp;#39;, 
    FILENAME = &amp;#39;C:\Demos\FS\NorthPoleFS3&amp;#39; 
) 
TO FILEGROUP NorthPoleFS3

ALTER DATABASE NorthPole 
ADD FILEGROUP NorthPoleDB3

ALTER database NorthPole 
ADD FILE 
( 
    NAME = &amp;#39;NorthPoleDB3&amp;#39;, 
    FILENAME = &amp;#39;C:\Demos\Data\NorthPoleData3.ndf&amp;#39; 
) 
TO FILEGROUP NorthPoleDB3


-- -----------------------------------------------
-- Insert 3 more records. This will go to FS2
-- -----------------------------------------------
INSERT INTO Items(itemguid, itemnumber, itemdescription, ItemImage)
SELECT NEWID(), &amp;#39;ITM007&amp;#39;, &amp;#39;Item 7&amp;#39;, CAST(7 AS VARBINARY(MAX))
UNION ALL
SELECT NEWID(), &amp;#39;ITM008&amp;#39;, &amp;#39;Item 8&amp;#39;, CAST(8 AS VARBINARY(MAX))
UNION ALL
SELECT NEWID(), &amp;#39;ITM009&amp;#39;, &amp;#39;Item 9&amp;#39;, CAST(9 AS VARBINARY(MAX))


-- -----------------------------------------------
-- Switch partitions. Alter the partition function
--   so that rows 7 to 9 will go to the new 
--   file group
-- -----------------------------------------------
ALTER PARTITION SCHEME NPPartFSSch  
NEXT USED NorthPoleFS3

ALTER PARTITION SCHEME NPPartDBSch 
NEXT USED NorthPoleDB3

ALTER PARTITION FUNCTION NPPartFN() 
SPLIT RANGE (6);

-- -----------------------------------------------
-- After the above, a new FILESTREAM folder is
--   created in FS1. No data goes to FS3
-- -----------------------------------------------&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=12565" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/3968T-J1760" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/FILESTREAM/default.aspx">FILESTREAM</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/TSQL/default.aspx">TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQL+SERVER/default.aspx">SQL SERVER</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_TSQL/default.aspx">#TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/06/12/sql-server-partitioning-filestream-data-with-range-left-does-not-work.aspx</feedburner:origLink></item><item><title>Getting started with SQL Server Wait Types</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/RG1BswNPFRE/getting-started-with-sql-server-wait-types.aspx</link><pubDate>Wed, 16 Mar 2011 10:27:32 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:11782</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=11782</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=11782</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/03/16/getting-started-with-sql-server-wait-types.aspx#comments</comments><description>&lt;p&gt;SQL Server Wait Types are important factors to consider while analyzing performance problems of SQL Server databases. If you notice a particular wait type is occurring too often or for too long, it indicates a problem in most cases.&lt;/p&gt;  &lt;p&gt;There are several dozens of different wait types and it is quite important that every Database Administrator understand them well. Luckily, star blogger &lt;a href="http://blog.sqlauthority.com/" target="_blank"&gt;Pinal Dave&lt;/a&gt; (&lt;a href="http://twitter.com/pinaldave" target="_blank"&gt;@pinaldave&lt;/a&gt; | &lt;a href="http://blog.sqlauthority.com/" target="_blank"&gt;blog.sqlauthority.com&lt;/a&gt;) has written a long series of blog posts on various wait types. What I found very interesting about this series is the way each wait type is explained. Just like every other post on his blog, every post in this series is quite easy to understand and straight to the point. &lt;/p&gt;  &lt;p&gt;I strongly believe that this series is a ‘must-read’ piece for every SQL Server Database Administrator and Developer. So start right now: &lt;a href="http://blog.sqlauthority.com/2011/02/28/sql-server-summary-of-month-wait-type-day-28-of-28/" target="_blank"&gt;SQL SERVER – Summary of Month – Wait Type&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=11782" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/RG1BswNPFRE" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/TSQL/default.aspx">TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQLSERVER/default.aspx">SQLSERVER</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_TSQL/default.aspx">#TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/03/16/getting-started-with-sql-server-wait-types.aspx</feedburner:origLink></item><item><title>T-SQL Tuesday #016 - Summarizing data using GROUPING SETS()</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/mlYpOank_30/t-sql-tuesday-016-summarizing-data-using-grouping-sets.aspx</link><pubDate>Tue, 08 Mar 2011 03:20:33 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:11725</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=11725</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=11725</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/03/08/t-sql-tuesday-016-summarizing-data-using-grouping-sets.aspx#comments</comments><description>&lt;p&gt;&lt;a&gt;&lt;img style="margin:0px 15px 0px 0px;display:inline;" align="left" src="http://blogs.lessthandot.com/media/blogs/DataMgmt/olap_1.gif" alt="" /&gt;&lt;/a&gt; I have been watching the &lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2010/12/07/a-year-of-tuesdays-t-sql-tuesday-meta-roundup.aspx" target="_blank"&gt;TSQL Tuesday Blog Parties&lt;/a&gt; for quite some time and this is the first time I am participating in it. &lt;a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/come-one-come-all-to" target="_blank"&gt;T-SQL Tuesday #16&lt;/a&gt; is hosted by &lt;a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/come-one-come-all-to"&gt;Jes Schultz Borland&lt;/a&gt; and the topic is &lt;em&gt;Aggregation&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;Aggregating and summarizing data is a common business requirement. Very often we come across requirements to calculate the total values presented in one or more columns on a web page. Some times the requirement may be bit more complicated such as to calculate multiple levels of sub-totals along with a grand total. &lt;/p&gt;  &lt;p&gt;Usually this type of tasks are efficiently done by reporting tools. Most reporting tools are equipped with the functionality to partition and summarize data based on custom user requirements. Very often I see questions asking for help to write TSQL queries that returns data in specific shape and format so that the client application can directly display the information on a web page. My first answer used to be an advice to handle this type of requirements in the presentation layer of the application, until I came across a real requirement myself, a few years back. &lt;/p&gt;  &lt;p&gt;The application had a few web pages which display various sales data in a grid control with multiple levels of sub-totals and totals. The web page had a huge chunk of code written to correctly calculate the sub totals of each levels and display them at the right position within the grid control. The page was very slow and the task was to optimize it. Moving the calculation logic into the database helped to improve performance tremendously. &lt;/p&gt;  &lt;p&gt;There are a number of TSQL keywords available that we can use to produce sub-totals and totals along with the query results. The simplest of them is &lt;strong&gt;COMPUTE BY&lt;/strong&gt; which produces a second result set with the totals of the query as given in &lt;a href="http://beyondrelational.com/blogs/jacob/archive/2008/09/02/tsql-lab-4-how-to-add-a-total-line-to-the-query-result.aspx" target="_blank"&gt;this example&lt;/a&gt;. But a second result set may not be desirable on certain situations. We might need a single result set with a total row. This can be easily achieved by using using WITH ROLLUP or WITH CUBE as demonstrated &lt;a href="http://beyondrelational.com/blogs/jacob/archive/2008/09/03/tsql-lab-5-using-with-rollup-to-generate-subtotals-and-grand-total-rows.aspx" target="_blank"&gt;here&lt;/a&gt;, &lt;a href="http://beyondrelational.com/blogs/jacob/archive/2008/09/04/tsql-lab-6-using-with-cube-to-generate-subtotal-and-grand-total-rows.aspx" target="_blank"&gt;here&lt;/a&gt; and &lt;a href="http://beyondrelational.com/blogs/jacob/archive/2008/09/05/tsql-lab-7-enhancements-to-rollup-and-cube-in-sql-server-2008.aspx" target="_blank"&gt;here&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Enter GROUPING SETS&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;SQL Server 2008 introduced a new function &lt;em&gt;GROUPING SETS()&lt;/em&gt; which gives more control over the total rows generated along with the query result. We will see a few examples to understand this. Run the following script to generate the sample table for the examples we will use in this post.&lt;/p&gt;  &lt;pre class="brush: sql"&gt;IF OBJECT_ID(&amp;#39;Orders&amp;#39;) IS NOT NULL DROP TABLE Orders
GO
CREATE TABLE Orders (
    OrderID INT,
    OrderDate DATETIME,
    CustomerName VARCHAR(20),
    ItemName VARCHAR(20),
    Quantity INT,
    PricePerCase MONEY )
GO

INSERT INTO Orders( OrderID, OrderDate, CustomerName, ItemName, Quantity, PricePerCase )
    SELECT 1, &amp;#39;2007-08-01&amp;#39;, &amp;#39;Jacob&amp;#39;, &amp;#39;Item 1&amp;#39;, 10, 12.5
INSERT INTO Orders( OrderID, OrderDate, CustomerName, ItemName, Quantity, PricePerCase )
    SELECT 1, &amp;#39;2007-08-01&amp;#39;, &amp;#39;Jacob&amp;#39;, &amp;#39;Item 2&amp;#39;, 12, 15.0
INSERT INTO Orders( OrderID, OrderDate, CustomerName, ItemName, Quantity, PricePerCase )
    SELECT 2, &amp;#39;2008-08-02&amp;#39;, &amp;#39;Jacob&amp;#39;, &amp;#39;Item 1&amp;#39;, 15, 12.5
INSERT INTO Orders( OrderID, OrderDate, CustomerName, ItemName, Quantity, PricePerCase )
    SELECT 2, &amp;#39;2008-08-02&amp;#39;, &amp;#39;Jacob&amp;#39;, &amp;#39;Item 2&amp;#39;, 20, 15.0
INSERT INTO Orders( OrderID, OrderDate, CustomerName, ItemName, Quantity, PricePerCase )
    SELECT 1, &amp;#39;2008-08-01&amp;#39;, &amp;#39;Mike&amp;#39;, &amp;#39;Item 1&amp;#39;, 6, 12.5
INSERT INTO Orders( OrderID, OrderDate, CustomerName, ItemName, Quantity, PricePerCase )
    SELECT 1, &amp;#39;2008-08-01&amp;#39;, &amp;#39;Mike&amp;#39;, &amp;#39;Item 2&amp;#39;, 4, 11.0&lt;/pre&gt;

&lt;p&gt;Within the GROUPING SETS() function, you can define set of columns on which you need a total row to be generated. The following example shows a query using GROUPING SETS(). It does not generate any total/subtotal rows and produces the same result as a GROUP BY clause could generate.&amp;#160; &lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT
    CASE 
        WHEN GROUPING(CustomerName) = 1 THEN &amp;#39;All Customers&amp;#39; 
        ELSE CustomerName 
    END AS CustomerName,
    CASE WHEN GROUPING(ItemName) = 1 THEN &amp;#39;All Items&amp;#39;
        ELSE ItemName
    END AS ItemName,
    SUM(Quantity * PricePerCase) AS Amount
FROM Orders
GROUP BY GROUPING SETS((CustomerName, ItemName))
/*
CustomerName         ItemName             Amount
-------------------- -------------------- ---------------------
Jacob                Item 1               312.50
Mike                 Item 1               75.00
Jacob                Item 2               480.00
Mike                 Item 2               44.00
*/&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;Generating only Subtotals and Grand Total Row&lt;/b&gt;&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT
    CASE 
        WHEN GROUPING(CustomerName) = 1 THEN &amp;#39;All Customers&amp;#39; 
        ELSE CustomerName 
    END AS CustomerName,
    CASE WHEN GROUPING(ItemName) = 1 THEN &amp;#39;All Items&amp;#39;
        ELSE ItemName
    END AS ItemName,
    SUM(Quantity * PricePerCase) AS Amount
FROM Orders
GROUP BY GROUPING SETS((ItemName), (CustomerName),())
/*
CustomerName         ItemName             Amount
-------------------- -------------------- ---------------------
Jacob                All Items            792.50
Mike                 All Items            119.00
All Customers        All Items            911.50
All Customers        Item 1               387.50
All Customers        Item 2               524.00
*/&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;Generating a Total Row per Customer&lt;/b&gt;&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT
    CASE 
        WHEN GROUPING(CustomerName) = 1 THEN &amp;#39;All Customers&amp;#39; 
        ELSE CustomerName 
    END AS CustomerName,
    CASE WHEN GROUPING(ItemName) = 1 THEN &amp;#39;All Items&amp;#39;
        ELSE ItemName
    END AS ItemName,
    SUM(Quantity * PricePerCase) AS Amount
FROM Orders
GROUP BY GROUPING SETS((CustomerName, ItemName), (CustomerName))
/*
CustomerName         ItemName             Amount
-------------------- -------------------- ---------------------
Jacob                Item 1               312.50
Jacob                Item 2               480.00
Jacob                All Items            792.50
Mike                 Item 1               75.00
Mike                 Item 2               44.00
Mike                 All Items            119.00
*/&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;Generating a Total Row per Item&lt;/b&gt;&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT
    CASE 
        WHEN GROUPING(CustomerName) = 1 THEN &amp;#39;All Customers&amp;#39; 
        ELSE CustomerName 
    END AS CustomerName,
    CASE WHEN GROUPING(ItemName) = 1 THEN &amp;#39;All Items&amp;#39;
        ELSE ItemName
    END AS ItemName,
    SUM(Quantity * PricePerCase) AS Amount
FROM Orders
GROUP BY GROUPING SETS((CustomerName, ItemName), (ItemName))
/*
CustomerName         ItemName             Amount
-------------------- -------------------- ---------------------
Jacob                Item 1               312.50
Mike                 Item 1               75.00
All Customers        Item 1               387.50
Jacob                Item 2               480.00
Mike                 Item 2               44.00
All Customers        Item 2               524.00
*/&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;Generating a Grand Total row&lt;/b&gt;&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT
    CASE 
        WHEN GROUPING(CustomerName) = 1 THEN &amp;#39;All Customers&amp;#39; 
        ELSE CustomerName 
    END AS CustomerName,
    CASE WHEN GROUPING(ItemName) = 1 THEN &amp;#39;All Items&amp;#39;
        ELSE ItemName
    END AS ItemName,
    SUM(Quantity * PricePerCase) AS Amount
FROM Orders
GROUP BY GROUPING SETS((CustomerName, ItemName), ())
/*
CustomerName         ItemName             Amount
-------------------- -------------------- ---------------------
Jacob                Item 1               312.50
Jacob                Item 2               480.00
Mike                 Item 1               75.00
Mike                 Item 2               44.00
All Customers        All Items            911.50
*/&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;Generating Subtotal rows for Customers and a Grand Total row&lt;/b&gt;&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT
    CASE 
        WHEN GROUPING(CustomerName) = 1 THEN &amp;#39;All Customers&amp;#39; 
        ELSE CustomerName 
    END AS CustomerName,
    CASE WHEN GROUPING(ItemName) = 1 THEN &amp;#39;All Items&amp;#39;
        ELSE ItemName
    END AS ItemName,
    SUM(Quantity * PricePerCase) AS Amount
FROM Orders
GROUP BY GROUPING SETS((CustomerName, ItemName), (CustomerName), ())
/*
CustomerName         ItemName             Amount
-------------------- -------------------- ---------------------
Jacob                Item 1               312.50
Jacob                Item 2               480.00
Jacob                All Items            792.50
Mike                 Item 1               75.00
Mike                 Item 2               44.00
Mike                 All Items            119.00
All Customers        All Items            911.50
*/&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;Generating Subtotal rows for Items and a Grand Total Row&lt;/b&gt;&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT
    CASE 
        WHEN GROUPING(CustomerName) = 1 THEN &amp;#39;All Customers&amp;#39; 
        ELSE CustomerName 
    END AS CustomerName,
    CASE WHEN GROUPING(ItemName) = 1 THEN &amp;#39;All Items&amp;#39;
        ELSE ItemName
    END AS ItemName,
    SUM(Quantity * PricePerCase) AS Amount
FROM Orders
GROUP BY GROUPING SETS((CustomerName, ItemName), (ItemName), ())
/*
CustomerName         ItemName             Amount
-------------------- -------------------- ---------------------
Jacob                Item 1               312.50
Mike                 Item 1               75.00
All Customers        Item 1               387.50
Jacob                Item 2               480.00
Mike                 Item 2               44.00
All Customers        Item 2               524.00
All Customers        All Items            911.50
*/&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;Generating Sub total rows for Customers and Items&lt;/b&gt;&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT
    CASE 
        WHEN GROUPING(CustomerName) = 1 THEN &amp;#39;All Customers&amp;#39; 
        ELSE CustomerName 
    END AS CustomerName,
    CASE WHEN GROUPING(ItemName) = 1 THEN &amp;#39;All Items&amp;#39;
        ELSE ItemName
    END AS ItemName,
    SUM(Quantity * PricePerCase) AS Amount
FROM Orders
GROUP BY GROUPING SETS((CustomerName, ItemName), (ItemName), (CustomerName))
/*
CustomerName         ItemName             Amount
-------------------- -------------------- ---------------------
Jacob                Item 1               312.50
Mike                 Item 1               75.00
All Customers        Item 1               387.50
Jacob                Item 2               480.00
Mike                 Item 2               44.00
All Customers        Item 2               524.00
Jacob                All Items            792.50
Mike                 All Items            119.00
*/&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;Generating Sub total rows for Customers and Items along with a Grand Total Row&lt;/b&gt;&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT
    CASE 
        WHEN GROUPING(CustomerName) = 1 THEN &amp;#39;All Customers&amp;#39; 
        ELSE CustomerName 
    END AS CustomerName,
    CASE WHEN GROUPING(ItemName) = 1 THEN &amp;#39;All Items&amp;#39;
        ELSE ItemName
    END AS ItemName,
    SUM(Quantity * PricePerCase) AS Amount
FROM Orders
GROUP BY GROUPING SETS((CustomerName, ItemName), (ItemName), (CustomerName),())
/*
CustomerName         ItemName             Amount
-------------------- -------------------- ---------------------
Jacob                Item 1               312.50
Mike                 Item 1               75.00
All Customers        Item 1               387.50
Jacob                Item 2               480.00
Mike                 Item 2               44.00
All Customers        Item 2               524.00
All Customers        All Items            911.50
Jacob                All Items            792.50
Mike                 All Items            119.00
*/&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;Ordering Results&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The above result set gives us sub totals by customer and by item and again a grand total row. However, the order of the rows is not good. If you want to retrieve the results in a specific order, you need to specify an ordering clause. The following query produces the results ordered by the grouping level. &lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT
    CASE 
        WHEN GROUPING(CustomerName) = 1 THEN &amp;#39;All Customers&amp;#39; 
        ELSE CustomerName 
    END AS CustomerName,
    CASE WHEN GROUPING(ItemName) = 1 THEN &amp;#39;All Items&amp;#39;
        ELSE ItemName
    END AS ItemName,
    SUM(Quantity * PricePerCase) AS Amount
FROM Orders
GROUP BY GROUPING SETS((CustomerName, ItemName), (ItemName), (CustomerName),())
ORDER BY GROUPING(CustomerName), GROUPING(ItemName)
/*
CustomerName         ItemName             Amount
-------------------- -------------------- ---------------------
Jacob                Item 2               480.00
Mike                 Item 2               44.00
Jacob                Item 1               312.50
Mike                 Item 1               75.00
Jacob                All Items            792.50
Mike                 All Items            119.00
All Customers        Item 1               387.50
All Customers        Item 2               524.00
All Customers        All Items            911.50
*/&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=11725" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/mlYpOank_30" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/TSQL/default.aspx">TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQL+SERVER/default.aspx">SQL SERVER</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_TSQL/default.aspx">#TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/TSQL+TUESDAY/default.aspx">TSQL TUESDAY</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/03/08/t-sql-tuesday-016-summarizing-data-using-grouping-sets.aspx</feedburner:origLink></item><item><title>SQL Server – TSQL – Quiz 2011 is here, your chance to win an Apple iPad!</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/qEFx68QOB3c/sql-server-tsql-quiz-2011-is-here-your-chance-to-win-an-apple-ipad.aspx</link><pubDate>Sun, 06 Mar 2011 15:44:48 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:11716</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=11716</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=11716</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/03/06/sql-server-tsql-quiz-2011-is-here-your-chance-to-win-an-apple-ipad.aspx#comments</comments><description>&lt;p&gt;We are back with the first SQL Server Quiz of year 2011 – &lt;a href="http://beyondrelational.com/quiz/SQLServer/TSQL/2011/default.aspx" target="_blank"&gt;TSQL Quiz 2011&lt;/a&gt;. The quiz started on 1st March and will run until 31 March 2011. There are 31 questions in this series and a question is published every day.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Congratulations to the Winners of SQL Server Quiz 2010&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We did a similar quiz a few months ago and it was a great experience. A large number of SQL Server enthusiasts participated actively in the discussions. We take this opportunity to congratulate the winners of &lt;a href="http://beyondrelational.com/quiz/sqlserver/general/2010/default.aspx" target="_blank"&gt;SQL Server Quiz 2010&lt;/a&gt;. &lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="42"&gt;&lt;img border="0" alt="" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Components.Avatars/00.00.00.30.45/4THI6ZVT0T7L.png" width="40" height="40" /&gt;&lt;/td&gt;        &lt;td valign="top" width="194"&gt;Mike Lewis &lt;/td&gt;        &lt;td valign="top" width="229"&gt;&lt;strong&gt;Apple iPad&lt;/strong&gt; (Sponsored by &lt;a href="http://bit.ly/8YWN3t"&gt;Redgate&lt;/a&gt;)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="42"&gt;&lt;img border="0" alt="" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Components.Avatars/00.00.00.58.06/4TGYXQHYWRWB.jpg" width="40" height="40" /&gt;&lt;/td&gt;        &lt;td valign="top" width="194"&gt;Docker &lt;/td&gt;        &lt;td valign="top" width="229"&gt;&lt;strong&gt;Amazon Kindle&lt;/strong&gt; (Sponsored by &lt;a href="http://bit.ly/cV9P8Q"&gt;Idera&lt;/a&gt;)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="42"&gt;&lt;img border="0" alt="" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Components.Avatars/00.00.00.47.25/4THUYOBBFYXR.jpg" width="40" height="40" /&gt;&lt;/td&gt;        &lt;td valign="top" width="194"&gt;IGO &lt;/td&gt;        &lt;td valign="top" width="229"&gt;&lt;strong&gt;iPod Nano&lt;/strong&gt; (Sponsored by &lt;a href="http://bit.ly/cnuqQI"&gt;Quest&lt;/a&gt;)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="42"&gt;&lt;img border="0" alt="" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Components.Avatars/00.00.00.51.12/4TG7T2FQXXI1.jpg" width="40" height="40" /&gt;&lt;/td&gt;        &lt;td valign="top" width="194"&gt;Sivaprasad S - SIVA &lt;/td&gt;        &lt;td valign="top" width="229"&gt;&lt;strong&gt;iPod Nano&lt;/strong&gt; (Sponsored by &lt;a href="http://bit.ly/cnuqQI"&gt;Quest&lt;/a&gt;)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="42"&gt;&lt;img border="0" alt="" src="http://beyondrelational.com/utility/anonymous.gif" width="40" height="40" /&gt;&lt;/td&gt;        &lt;td valign="top" width="194"&gt;Abi Chapagai &lt;/td&gt;        &lt;td valign="top" width="229"&gt;&lt;strong&gt;iPod Nano&lt;/strong&gt; (Sponsored by &lt;a href="http://bit.ly/cnuqQI"&gt;Quest&lt;/a&gt;)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="42"&gt;&lt;img border="0" alt="" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Components.Avatars/00.00.00.58.05/4TGQQUK85JEZ.jpg" width="40" height="40" /&gt;&lt;/td&gt;        &lt;td valign="top" width="194"&gt;Nupur Dave &lt;/td&gt;        &lt;td valign="top" width="229"&gt;&lt;strong&gt;iPod Nano&lt;/strong&gt; (Sponsored by &lt;a href="http://bit.ly/cnuqQI"&gt;Quest&lt;/a&gt;)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="42"&gt;&lt;img border="0" alt="" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Components.Avatars/00.00.00.27.74/4TE9F0EAS1TJ.jpg" width="40" height="40" /&gt;&lt;/td&gt;        &lt;td valign="top" width="194"&gt;Ramireddy &lt;/td&gt;        &lt;td valign="top" width="229"&gt;&lt;strong&gt;iPod Nano&lt;/strong&gt; (Sponsored by &lt;a href="http://bit.ly/cnuqQI"&gt;Quest&lt;/a&gt;)&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;In addition to the winners listed above, 44 other people won free software licenses worth over 17,000$. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Inviting you to TSQL Quiz 2011&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;TSQL Quiz 2011 started on 1st of March and will run until March 31, 2011. Each question will stay open for 30 days and you can post an answer within 30 days of the publication date. After 30 days the quiz master will evaluate your answers and will assign a score to each answer (between 0 and 10). The winners will be decided based on the total score you get from all the 31 questions. &lt;/p&gt; &lt;img src="http://beyondrelational.com/images/quiz/ipadleft.png" alt="" /&gt;   &lt;p&gt;I invite all of you to participate in &lt;a href="http://beyondrelational.com/quiz/sqlserver/tsql/2011/questions/all.aspx" target="_blank"&gt;TSQL Quiz 2011&lt;/a&gt;. The winner will get an &lt;a href="http://beyondrelational.com/quiz/sqlserver/tsql/2011/prizes.aspx" target="_blank"&gt;Apple iPad&lt;/a&gt; from &lt;a href="http://bit.ly/dvuHga" target="_blank"&gt;Redgate Software&lt;/a&gt;. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=11716" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/qEFx68QOB3c" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/TSQL/default.aspx">TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQL+SERVER/default.aspx">SQL SERVER</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_TSQL/default.aspx">#TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/quiz/default.aspx">quiz</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/03/06/sql-server-tsql-quiz-2011-is-here-your-chance-to-win-an-apple-ipad.aspx</feedburner:origLink></item><item><title>Happy Birthday to TSQL Challenges and its younger sibling!</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/oIoPbUsrWX0/happy-birthday-to-tsql-challenges-and-its-younger-sibling.aspx</link><pubDate>Sun, 27 Feb 2011 21:01:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:11672</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=11672</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=11672</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/02/27/happy-birthday-to-tsql-challenges-and-its-younger-sibling.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;TSQL Challenges – 2nd Birthday Party!&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/puzzles/tsql/default.aspx" target="_blank"&gt;TSQL Challenges&lt;/a&gt; is turning two years old today. We did the first TSQL Challenge two years ago - on 27th February 2009. In two years, TSQL Challenge has grown up with the help of several volunteers and TSQL enthusiasts who stepped in and selflessly helped. I have written a detailed post about this journey in one of my &lt;a href="http://beyondrelational.com/blogs/tc/archive/2011/02/21/tsql-challenges-is-turning-2-years-old.aspx" target="_blank"&gt;previous posts&lt;/a&gt;. It has been a wonderful journey with 50 challenges, 700 unique participants and over 3,500 solutions.&lt;/p&gt;  &lt;p&gt;We invite all of you to the Birthday Party on &lt;a href="http://beyondrelational.com/puzzles/tsql/default.aspx" target="_blank"&gt;beyondrelational.com&lt;/a&gt;. The first course is a re-launched version of &lt;a href="http://beyondrelational.com/puzzles/tsql/1/english/pair-wise-and-ordered-assignment-of-objects-from-two-different-lists.aspx" target="_blank"&gt;TSQL Challenge 1&lt;/a&gt; which comes with a variety of birds, grains and fruits. You need to feed the birds with correct combination of food baskets before you move to your own dinner table. To move to the second course, you need to solve &lt;a href="http://beyondrelational.com/puzzles/tsql/1/english/pair-wise-and-ordered-assignment-of-objects-from-two-different-lists.aspx" target="_blank"&gt;TSQL Challenge 1&lt;/a&gt;. To cater to the tastes all of you from different parts of the world, we have made it available in &lt;a href="http://beyondrelational.com/puzzles/tsql/1/english/pair-wise-and-ordered-assignment-of-objects-from-two-different-lists.aspx" target="_blank"&gt;English&lt;/a&gt;, &lt;a href="http://beyondrelational.com/puzzles/tsql/1/korean/pair-wise-and-ordered-assignment-of-objects-from-two-different-lists.aspx" target="_blank"&gt;Korean&lt;/a&gt;, &lt;a href="http://beyondrelational.com/puzzles/tsql/1/chinese/pair-wise-and-ordered-assignment-of-objects-from-two-different-lists.aspx" target="_blank"&gt;Chinese&lt;/a&gt;, &lt;a href="http://beyondrelational.com/puzzles/tsql/1/italian/pair-wise-and-ordered-assignment-of-objects-from-two-different-lists.aspx" target="_blank"&gt;Italian&lt;/a&gt;, &lt;a href="http://beyondrelational.com/puzzles/tsql/1/french/pair-wise-and-ordered-assignment-of-objects-from-two-different-lists.aspx" target="_blank"&gt;French&lt;/a&gt; and &lt;a href="http://beyondrelational.com/puzzles/tsql/1/portuguese/pair-wise-and-ordered-assignment-of-objects-from-two-different-lists.aspx" target="_blank"&gt;Portuguese&lt;/a&gt; flavors.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Meet the new born baby – PLSQL Challenges&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Many people from the ORACLE world suggested that it is a good idea to re-run these challenges in PLSQL as well. This will help us to learn several interesting facts about other products. For example, such a comparison will tell us how easily you can solve a problem in ORACLE which is quite hard in SQL Server. Similarly, it will be quite interesting to know that a problem that is hard to solve in PLSQL can be easily solved in TSQL. &lt;/p&gt;  &lt;p&gt;Keeping this in mind, we have been working on bringing up the PLSQL version of TSQL Challenges. You can find the first &lt;a href="http://beyondrelational.com/puzzles/plsql/default.aspx" target="_blank"&gt;PLSQL Challenge&lt;/a&gt; &lt;a href="http://beyondrelational.com/puzzles/plsql/1/english/pair-wise-and-ordered-assignment-of-objects-from-two-different-lists.aspx" target="_blank"&gt;here&lt;/a&gt;. I am quite hopeful that many of you will step forward and help this infant to grow up just like many of you did for TSQL Challenges. I look forward to hear your comments, suggestion and feed back through the &lt;a href="http://beyondrelational.com/ask/plsqlchallenges/default.aspx" target="_blank"&gt;PLSQL Challenge Discussion Thread&lt;/a&gt;. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=11672" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/oIoPbUsrWX0" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQL+SERVER/default.aspx">SQL SERVER</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_TSQL/default.aspx">#TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/02/27/happy-birthday-to-tsql-challenges-and-its-younger-sibling.aspx</feedburner:origLink></item><item><title>What is SQL Server Juneau?</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/wkO0Gmb-Al4/what-is-sql-server-juneau.aspx</link><pubDate>Mon, 07 Feb 2011 08:44:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:11415</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=11415</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=11415</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/02/07/what-is-sql-server-juneau.aspx#comments</comments><description>&lt;p&gt;“&lt;a href="http://msdn.microsoft.com/en-us/data/gg427686" target="_blank"&gt;Juneau&lt;/a&gt;” is the code name given to the new SQL Server development environment which is based on Visual Studio shell. It is officially named “SQL Server Developer Tools” (SSDT) which is expected to provide a wide range of functionalities that are currently not available with SQL Server Management Studio (SSMS).&lt;/p&gt;  &lt;p&gt;The current version of SQL Server Denali is CTP1 which does not include Juneau. It is expected to be available with the next CTP release (CTP2). See &lt;a href="http://what.isnew.in/sqlserver/denali" target="_blank"&gt;What is new in SQL Server Denali&lt;/a&gt; for a detailed list of features available in the next SQL Server Version (SQL11).&lt;/p&gt;  &lt;p&gt;One of the interesting features that will be available in Juneau is more support for SQL Azure Development. A few other features that I found interesting are: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Supports connected and offline database development&lt;/li&gt;    &lt;li&gt;Integrated application and database development&lt;/li&gt;    &lt;li&gt;Entity Framework Integration&lt;/li&gt;    &lt;li&gt;WPF based Text Editor&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;SSMS is my primary (and favorite) development environment and I am not sure whether I would ever like to switch to a different tool. I hope Juneau will not replace SSMS. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=11415" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/wkO0Gmb-Al4" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/TSQL/default.aspx">TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQL+SERVER/default.aspx">SQL SERVER</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_TSQL/default.aspx">#TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/DENALI/default.aspx">DENALI</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQL11/default.aspx">SQL11</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/Juneau/default.aspx">Juneau</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/02/07/what-is-sql-server-juneau.aspx</feedburner:origLink></item><item><title>What is SQL Server Crescent?</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/qdoJCG65g-8/what-is-sql-server-crescent.aspx</link><pubDate>Fri, 04 Feb 2011 13:51:40 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:11403</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=11403</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=11403</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/02/04/what-is-sql-server-crescent.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/b/sqlrsteamblog/archive/2010/11/09/a-glimpse-at-project-crescent.aspx" target="_blank"&gt;Project Crescent&lt;/a&gt; is a new data visualization tool that will be part of the next version of SQL Server – code named Denali. &lt;/p&gt;  &lt;p&gt;“Crescent” is the code name given to the new reporting/visualization tools and it looks like the name may change by the time the product is released. Crescent is expected to revolutionize ad-hoc reporting requirements by providing users new user experience and allow them to present the data in new and exciting ways.&amp;#160; &lt;/p&gt;  &lt;p&gt;Experts who got early access to Crescent says that Crescent expands the Self Service BI capabilities currently available with PowerPivot for Excel. Crescent provides drag-and-drop ad-hoc reporting capability. Crescent is not available with the current release of Denali (CTP1) but is expected to be part of CTP2. To see the list of new features available in Denali, visit: &lt;a title="http://beyondrelational.com/whatisnew/sqlserver/denali/" href="http://beyondrelational.com/whatisnew/sqlserver/denali/"&gt;http://beyondrelational.com/whatisnew/sqlserver/denali/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;What is more exciting is to know that &lt;a href="http://team.silverlight.net/announcement/project-crescent/" target="_blank"&gt;Crescent is entirely built on Silverlight&lt;/a&gt;. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=11403" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/qdoJCG65g-8" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/TSQL/default.aspx">TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQL+SERVER/default.aspx">SQL SERVER</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/What+is+New/default.aspx">What is New</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_TSQL/default.aspx">#TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/DENALI/default.aspx">DENALI</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/Crescent/default.aspx">Crescent</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/02/04/what-is-sql-server-crescent.aspx</feedburner:origLink></item><item><title>SSRS – How to find all the reports that use one or more given columns?</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/VfMWdKKv00o/ssrs-how-to-find-all-the-reports-that-use-one-or-more-given-columns.aspx</link><pubDate>Fri, 21 Jan 2011 08:27:49 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:11259</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=11259</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=11259</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/01/21/ssrs-how-to-find-all-the-reports-that-use-one-or-more-given-columns.aspx#comments</comments><description>&lt;p&gt;In the past I have published a few queries that allows you to query SQL Server Reporting Services database – to retrieve specific information about various reports deployed in the Reporting Server Instance.&lt;/p&gt; &lt;p&gt;Recently, I got a &lt;a href="http://beyondrelational.com/ask/jacob/questions/11/finding-all-reports-referencing-a-certain-fieldcolumn-on-report-server.aspx"&gt;question&lt;/a&gt; in my &lt;a href="http://beyondrelational.com/ask/jacob/questions/11/finding-all-reports-referencing-a-certain-fieldcolumn-on-report-server.aspx"&gt;ASK forum&lt;/a&gt; who wanted to identify all the reports that use a specific column. I thought of writing a blog post about it so that it can be added to the SSRS query series and help other people with similar problems.&lt;/p&gt; &lt;p&gt;The RDL file that gets generated when you design a report, is an XML document. When you deploy the report on Reporting Server, the RDL file (which is an XML document) gets inserted into the Report Server database (named ReportServer by default). You can query this database to obtain the XML content of all the reports and then use XQuery to read specific information about each report.&lt;/p&gt; &lt;p&gt;The following query demonstrates how to read all the columns used by all the reports in the given SQL Server Reporting Server instance and search for a specific column. The query given below returns the report name and data source name of all reports that references a specified column name – which is passed as a parameter.&lt;/p&gt;&lt;pre class="brush: sql"&gt;DECLARE @FieldToSearch VARCHAR(100)
SELECT @FieldToSearch = &amp;#39;PatientNumber&amp;#39;

;WITH XMLNAMESPACES (
	DEFAULT 
	&amp;#39;http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition&amp;#39;,
	&amp;#39;http://schemas.microsoft.com/SQLServer/reporting/reportdesigner&amp;#39; AS rd
)
SELECT
	name,
	d.value(&amp;#39;@Name[1]&amp;#39;, &amp;#39;VARCHAR(50)&amp;#39;) AS DataSetName,
	df.value(&amp;#39;@Name[1]&amp;#39;, &amp;#39;VARCHAR(50)&amp;#39;) AS ReportFieldName,
	df.value(&amp;#39;DataField[1]&amp;#39;, &amp;#39;VARCHAR(50)&amp;#39;) AS DataFieldName
FROM (
	select name, 
	CAST(CAST(content AS VARBINARY(MAX)) AS XML) AS reportXML
	from ReportServer.dbo.Catalog
	WHERE Type = 2
) a
CROSS APPLY reportXML.nodes(&amp;#39;/Report/DataSets/DataSet&amp;#39;) r(d)
CROSS APPLY d.nodes(&amp;#39;Fields/Field&amp;#39;) f(df)
WHERE df.exist(&amp;#39;DataField[ . = sql:variable(&amp;quot;@FieldToSearch&amp;quot;)]&amp;#39;) = 1
/*
Name          DataSetName   ReportFieldName  DataFieldName
------------  ------------  ---------------  ---------------
Patient List  DSPatients    PatientID        PatientNumber
AR Details    DSPatientsAR  PatientNumber    PatientNumber
*/
&lt;/pre&gt;
&lt;div class="lightbulb"&gt;The code given above is tested with SSRS 2005 SP2. It is expected to work on other versions, but I have not tested. If you find a problem running this query on other SSRS versions, let me know. &lt;/div&gt;
&lt;p&gt;I would recommend you read the following posts as well:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/blogs/jacob/archive/2008/01/16/how-to-find-all-stored-procedures-used-by-report-server.aspx"&gt;How to find all stored procedures used by Report Server?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/blogs/jacob/archive/2008/11/14/how-to-query-report-server-to-find-out-the-data-source-used-by-one-or-more-reports.aspx"&gt;How to query report server to find out the data source used by one or more reports?&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=11259" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/VfMWdKKv00o" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XML/default.aspx">XML</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery/default.aspx">XQuery</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/TSQL/default.aspx">TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SSRS/default.aspx">SSRS</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BI/default.aspx">BI</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQLSERVER/default.aspx">SQLSERVER</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_TSQL/default.aspx">#TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_BI/default.aspx">#BI</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/01/21/ssrs-how-to-find-all-the-reports-that-use-one-or-more-given-columns.aspx</feedburner:origLink></item><item><title>Inviting everyone to participate in the .NET Quiz! An Apple iPad Waiting</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/lvtSQwM1Tro/inviting-everyone-to-participate-in-the-net-quiz-an-apple-ipad-waiting.aspx</link><pubDate>Sat, 01 Jan 2011 09:23:19 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:11012</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=11012</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=11012</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2011/01/01/inviting-everyone-to-participate-in-the-net-quiz-an-apple-ipad-waiting.aspx#comments</comments><description>&lt;p&gt;After the recent &lt;a href="http://beyondrelational.com/quiz/SQLServer/General/2010/default.aspx"&gt;SQL Server Quiz&lt;/a&gt; we got several requests to start a .NET quiz that follows the similar model. We have been working hard for the last couple of months and finally the .NET Quiz is Ready.&lt;/p&gt;  &lt;p&gt;The SQL Server Quiz was our first attempt in this area and we came to know about several stuff we are missing. One of the serious shortcoming was the user interface on the web pages. We have been working hard on rebuilding the quiz module and released a new version that goes live with the .NET Quiz. &lt;/p&gt;  &lt;p&gt;I invite all of you to take part in the &lt;a href="http://beyondrelational.com/quiz/dotnet/general/2011/default.aspx"&gt;.NET Quiz&lt;/a&gt;. The winner gets an Apple iPad (sponsored by &lt;a href="http://bit.ly/dVGSTY"&gt;Redgate&lt;/a&gt;). &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=11012" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/lvtSQwM1Tro" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/DOTNET/default.aspx">DOTNET</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/announcement/default.aspx">announcement</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/quiz/default.aspx">quiz</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2011/01/01/inviting-everyone-to-participate-in-the-net-quiz-an-apple-ipad-waiting.aspx</feedburner:origLink></item><item><title>Storing TSQL Queries in a table without losing the formatting</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/yBOpRyICMV4/storing-tsql-queries-in-a-table-without-losing-the-formatting.aspx</link><pubDate>Fri, 17 Dec 2010 12:49:23 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:10761</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>8</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=10761</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=10761</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2010/12/17/storing-tsql-queries-in-a-table-without-losing-the-formatting.aspx#comments</comments><description>&lt;p&gt;One of the applications we worked on recently had to deal with storing TSQL queries in a table and executing them based on some business logic. It was not a very complicated project, but the development team had a tough time with the formatting of the queries stored in the table. This was a huge problem when the queries were to be modified. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The developer writes a well formatted TSQL code and stores it into the table. Later on when a change request comes, he retrieves the query text from the table and finds that all the formatting is lost. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Why does it happen?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Well, the formatting is not really lost. When the developer stores a well formatted query into the VARCHAR(MAX)/NVARCHAR(MAX) column of a table, the formatting is also stored. The problem is the way he retrieves it. &lt;/p&gt;  &lt;p&gt;The common way of retrieving the query text is to run a SELECT query which will display the result in a grid view. The grid view does not maintain the special characters (line feed, carriage return). That is the reason why you are loosing the formatting.&lt;/p&gt;  &lt;p&gt;An immediate workaround is to change the output to text and run the SELECT query. This works if the TSQL queries stored in the table are small. If the queries are large, then it might truncate the queries.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Workaround&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In this post, let us see a workaround that shows how to retrieve the query text without loosing the formatting. To see this in action, let us start by creating a table to store the queries.&lt;/p&gt;  &lt;pre class="brush: sql"&gt;USE tempdb
GO

IF OBJECT_ID(&amp;#39;BRQueries&amp;#39;,&amp;#39;U&amp;#39;) IS NOT NULL BEGIN
	DROP TABLE BRQueries
END

CREATE TABLE BRQueries(
	QueryID INT, 
	QueryText VARCHAR(MAX)
)&lt;/pre&gt;

&lt;p&gt;Next, let us write a well formed query.&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT 
   t.Name AS TableName,
   c.Name AS ColumnName
FROM sys.tables t
INNER JOIN sys.columns c ON
	t.object_id = c.object_id&lt;/pre&gt;

&lt;p&gt;Let us now insert this query into the table&lt;/p&gt;

&lt;pre class="brush: sql"&gt;INSERT INTO BRQueries (QueryID, QueryText)
SELECT 1, 
&amp;#39;
SELECT 
   t.Name AS TableName,
   c.Name AS ColumnName
FROM sys.tables t
INNER JOIN sys.columns c ON
	t.object_id = c.object_id&amp;#39;&lt;/pre&gt;

&lt;p&gt;Next, Let us run a SELECT query to retrieve the query text. If we use &amp;#39;result to grid&amp;#39;, we will loose the formatting. If we use &amp;#39;result to text&amp;#39; we will get the correctly formatted text in this case. However, if the query is longer it might get truncated. If the table has several other columns and rows, the output will be completely messed up.&lt;/p&gt;

&lt;p&gt;A workaround is to use to use the XML function &lt;i&gt;processing-instruction()&lt;/i&gt;. Run the following query.&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT
	QueryID,
	(
		SELECT QueryText AS &amp;#39;processing-instruction(q)&amp;#39; 
		FROM BRQueries b
		WHERE b.QueryID = a.QueryID
		FOR XML PATH(&amp;#39;&amp;#39;), TYPE
	) AS Query
FROM BRQueries a&lt;/pre&gt;

&lt;p&gt;Take the result of the query into a grid either by pressing CTRL+D or from the toolbar and you will see the result as follows: &lt;/p&gt;
&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/query_5F00_3F245F0A.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="query" border="0" alt="query" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/query_5F00_thumb_5F00_5CB63A09.png" width="474" height="86" /&gt;&lt;/a&gt; 

&lt;p&gt;Click on the desired row and it will open up the query text with the original formatting.&lt;/p&gt;

&lt;pre class="brush: xml"&gt;&amp;lt;?q 
SELECT 
   t.Name AS TableName,
   c.Name AS ColumnName
FROM sys.tables t
INNER JOIN sys.columns c ON
	t.object_id = c.object_id
?&amp;gt;&lt;/pre&gt;

&lt;p&gt;You can strip of the XML tags from the top and bottom of the query text and go ahead with editing. Well, this is not a &amp;#39;great&amp;#39; method but a quick and dirty trick that might come handy at times. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=10761" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/yBOpRyICMV4" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XML/default.aspx">XML</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/FOR+XML+PATH/default.aspx">FOR XML PATH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/TSQL/default.aspx">TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQLSERVER/default.aspx">SQLSERVER</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_XML/default.aspx">#XML</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_TSQL/default.aspx">#TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2010/12/17/storing-tsql-queries-in-a-table-without-losing-the-formatting.aspx</feedburner:origLink></item><item><title>XQuery Lab 63 – Deleting empty elements from an XML document</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/D9qNfWnp1oE/xquery-lab-63-deleting-empty-elements-from-an-xml-document.aspx</link><pubDate>Tue, 14 Dec 2010 15:04:02 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:10728</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=10728</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=10728</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2010/12/14/xquery-lab-63-deleting-empty-elements-from-an-xml-document.aspx#comments</comments><description>&lt;p&gt;I saw this question on the forum today and after writing an example that demonstrates this, I thought of including it as part of the &lt;a href="http://beyondrelational.com/blogs/jacob/archive/2008/06/26/xquery-labs-a-collection-of-xquery-sample-scripts.aspx"&gt;XQuery Labs&lt;/a&gt;. &lt;/p&gt; &lt;br /&gt; &lt;p&gt;Here is the sample XML we need to process.&lt;/p&gt; &lt;pre class="brush: html"&gt;
&amp;lt;userdata pageid=&amp;quot;page9&amp;quot; annotationSetId=&amp;quot;80&amp;quot;&amp;gt;
    &amp;lt;notes /&amp;gt;
    &amp;lt;notes&amp;gt;
      &amp;lt;note id=&amp;quot;332E7A17-3E57-3540-CC28-DFA1C68A7802&amp;quot; 
		x1=&amp;quot;297.25&amp;quot; x2=&amp;quot;297.25&amp;quot; y1=&amp;quot;447.85&amp;quot; y2=&amp;quot;447.85&amp;quot; 
		lastModified=&amp;quot;2010-12-13T12:08:32Z&amp;quot; type=&amp;quot;mynotes&amp;quot;&amp;gt;
      &amp;lt;/note&amp;gt;
    &amp;lt;/notes&amp;gt;
    &amp;lt;notes /&amp;gt;
    &amp;lt;notes /&amp;gt;
    &amp;lt;page_hotspots /&amp;gt;
  &amp;lt;/userdata&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The task is to delete all &lt;strong&gt;notes &lt;/strong&gt;elements that are empty and produce the following output.&lt;/p&gt;
&lt;pre class="brush: html"&gt;
&amp;lt;userdata pageid=&amp;quot;page9&amp;quot; annotationSetId=&amp;quot;80&amp;quot;&amp;gt;
  &amp;lt;notes&amp;gt;
    &amp;lt;note id=&amp;quot;332E7A17-3E57-3540-CC28-DFA1C68A7802&amp;quot; 
		x1=&amp;quot;297.25&amp;quot; x2=&amp;quot;297.25&amp;quot; y1=&amp;quot;447.85&amp;quot; y2=&amp;quot;447.85&amp;quot; 
		lastModified=&amp;quot;2010-12-13T12:08:32Z&amp;quot; type=&amp;quot;mynotes&amp;quot; /&amp;gt;
  &amp;lt;/notes&amp;gt;
  &amp;lt;page_hotspots /&amp;gt;
&amp;lt;/userdata&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Here is the TSQL code that deletes the empty elements using an XQuery expression. &lt;/p&gt;
&lt;pre class="brush: sql"&gt;
DECLARE @x XML
SELECT @x = &amp;#39;
&amp;lt;userdata pageid=&amp;quot;page9&amp;quot; annotationSetId=&amp;quot;80&amp;quot;&amp;gt;
    &amp;lt;notes /&amp;gt;
    &amp;lt;notes&amp;gt;
      &amp;lt;note id=&amp;quot;332E7A17-3E57-3540-CC28-DFA1C68A7802&amp;quot; 
		x1=&amp;quot;297.25&amp;quot; x2=&amp;quot;297.25&amp;quot; y1=&amp;quot;447.85&amp;quot; y2=&amp;quot;447.85&amp;quot; 
		lastModified=&amp;quot;2010-12-13T12:08:32Z&amp;quot; type=&amp;quot;mynotes&amp;quot;&amp;gt;
      &amp;lt;/note&amp;gt;
    &amp;lt;/notes&amp;gt;
    &amp;lt;notes /&amp;gt;
    &amp;lt;notes /&amp;gt;
    &amp;lt;page_hotspots /&amp;gt;
  &amp;lt;/userdata&amp;gt;&amp;#39;

SET @x.modify(&amp;#39;
	delete /userdata/notes[empty(./*)]
&amp;#39;)

SELECT @x

/*
&amp;lt;userdata pageid=&amp;quot;page9&amp;quot; annotationSetId=&amp;quot;80&amp;quot;&amp;gt;
  &amp;lt;notes&amp;gt;
    &amp;lt;note id=&amp;quot;332E7A17-3E57-3540-CC28-DFA1C68A7802&amp;quot; 
		x1=&amp;quot;297.25&amp;quot; x2=&amp;quot;297.25&amp;quot; y1=&amp;quot;447.85&amp;quot; y2=&amp;quot;447.85&amp;quot; 
		lastModified=&amp;quot;2010-12-13T12:08:32Z&amp;quot; type=&amp;quot;mynotes&amp;quot; /&amp;gt;
  &amp;lt;/notes&amp;gt;
  &amp;lt;page_hotspots /&amp;gt;
&amp;lt;/userdata&amp;gt;
*/
&lt;/pre&gt;
&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;View All Labs: &lt;/b&gt;&lt;a href="http://beyondrelational.com/blogs/jacob/archive/2008/06/26/xquery-labs-a-collection-of-xquery-sample-scripts.aspx"&gt;XQuery Labs - A Collection of XQuery Sample Scripts and Tutorials&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=10728" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/D9qNfWnp1oE" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery-Functions/default.aspx">XQuery-Functions</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery-Labs/default.aspx">XQuery-Labs</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XML/default.aspx">XML</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery/default.aspx">XQuery</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/TSQL/default.aspx">TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery+Tutorials/default.aspx">XQuery Tutorials</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery+Lab/default.aspx">XQuery Lab</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery+Functions/default.aspx">XQuery Functions</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_XML/default.aspx">#XML</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_XQUERY/default.aspx">#XQUERY</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQL+Server+-+XQuery/default.aspx">SQL Server - XQuery</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_TSQL/default.aspx">#TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/XQuery+Training/default.aspx">XQuery Training</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2010/12/14/xquery-lab-63-deleting-empty-elements-from-an-xml-document.aspx</feedburner:origLink></item><item><title>SSMS Enhancement in SQL11 (Denali) – Support for Code Snippets</title><link>http://feedproxy.google.com/~r/ExploringBeyondRelational/~3/TmayUxQf-ao/ssms-enhancement-in-sql11-denali-support-for-code-snippets.aspx</link><pubDate>Sat, 20 Nov 2010 06:28:29 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:10423</guid><dc:creator>Jacob Sebastian</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/jacob/rsscomments.aspx?PostID=10423</wfw:commentRss><wfw:comment>http://beyondrelational.com/blogs/jacob/commentapi.aspx?PostID=10423</wfw:comment><comments>http://beyondrelational.com/blogs/jacob/archive/2010/11/20/ssms-enhancement-in-sql11-denali-support-for-code-snippets.aspx#comments</comments><description>&lt;p&gt;Code snippets allow you to quickly insert code templates into your query window to perform common TSQL tasks. By using a keyword short cut you can invoke the code snippet window and select the desired code snippet. This will copy the pre-defined code template to your query with placeholders which clearly indicates the locations where you need to make changes.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Inserting a code snippet&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;You can activate the code snippet window by using the keyboard shortcut &lt;strong&gt;CTRL+K&lt;/strong&gt; followed by &lt;strong&gt;CTRL+X&lt;/strong&gt;. Alternatively, you can select the &lt;em&gt;Insert Snippet.. &lt;/em&gt;menu item from the &lt;em&gt;Edit &amp;gt;&amp;gt; IntelliSense &lt;/em&gt;menu. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet1_5F00_6D5BB8C0.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="codesnippet1" border="0" alt="codesnippet1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet1_5F00_thumb_5F00_5AB2D0D7.png" width="390" height="209" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Code snippets are organized by categories. Select a category to see the available code snippets under that category. For this example, let us select “Function”.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet2_5F00_2CE50812.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="codesnippet2" border="0" alt="codesnippet2" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet2_5F00_thumb_5F00_4AE31606.png" width="390" height="98" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Let us select “Create Inline Table Function” and SSMS will insert the code required to create a Table Valued Function to your query window at the current cursor position.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet3_5F00_336861D5.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="codesnippet3" border="0" alt="codesnippet3" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet3_5F00_thumb_5F00_51666FC9.png" width="277" height="187" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;After inserting the function template, SSMS will also highlight the placeholders that need to be modified. This will help you to identify the places you need to make changes. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Creating your own code snippet&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;SSMS comes with some pre-defined code snippets. It is quite easy to add your own code snippets to SSMS and speed up developing commonly used TSQL code. To do this, you need to create a .snippet file containing your code and register it with the Code Snippet Manager. A .snippet file is an XML file that follows a pre-defined schema.&lt;/p&gt;  &lt;p&gt;Let us create a TSQL code snippet to generate the basic code for a simple TRY-CATCH block. Here is the code that we will include in the new code snippet.&lt;/p&gt;  &lt;pre class="brush: sql"&gt;BEGIN TRY
	-- Your code here
END TRY
BEGIN CATCH
	-- Your error handling here
	;THROW
END CATCH&lt;/pre&gt;

&lt;p&gt;Here is the code snippet file created for inserting the above code fragment.&lt;/p&gt;

&lt;pre class="brush: xml"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;
&amp;lt;CodeSnippets xmlns=&amp;quot;http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet&amp;quot;&amp;gt;
  &amp;lt;CodeSnippet Format=&amp;quot;1.0.0&amp;quot;&amp;gt;
    &amp;lt;Header&amp;gt;
      &amp;lt;SnippetTypes&amp;gt;
        &amp;lt;SnippetType&amp;gt;Expansion&amp;lt;/SnippetType&amp;gt;
      &amp;lt;/SnippetTypes&amp;gt;
      &amp;lt;Title&amp;gt;try-catch&amp;lt;/Title&amp;gt;
      &amp;lt;Author&amp;gt;jacob&amp;lt;/Author&amp;gt;
      &amp;lt;Description&amp;gt;
      &amp;lt;/Description&amp;gt;
      &amp;lt;HelpUrl&amp;gt;
      &amp;lt;/HelpUrl&amp;gt;
      &amp;lt;Shortcut&amp;gt;
      &amp;lt;/Shortcut&amp;gt;
    &amp;lt;/Header&amp;gt;
    &amp;lt;Snippet&amp;gt;
      &amp;lt;Code Language=&amp;quot;sql&amp;quot;&amp;gt;&amp;lt;![CDATA[
		BEGIN TRY
			-- Your code here
		END TRY
		BEGIN CATCH
			-- Your error handling here
			;THROW
		END CATCH
		]]&amp;gt;
	  &amp;lt;/Code&amp;gt;
    &amp;lt;/Snippet&amp;gt;
  &amp;lt;/CodeSnippet&amp;gt;
&amp;lt;/CodeSnippets&amp;gt;&lt;/pre&gt;

&lt;p&gt;There are several tools available that will allow you to create code snippets easily. One such tool is &lt;a href="http://snippetdesigner.codeplex.com"&gt;Snippet Designer&lt;/a&gt; available at codeplex. This allows you to create code snippets right within visual studio. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Registering a code snippet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After creating a code snippet file, you need to register it with SSMS. This can be done using the “Code Snippet Manager”. Launch the “Code Snippet Manager” from the “Tools” menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet4_5F00_08604E03.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="codesnippet4" border="0" alt="codesnippet4" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet4_5F00_thumb_5F00_5AFEB832.png" width="342" height="188" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;This will open the code snippet manager window.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet5_5F00_7FAFCFA9.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="codesnippet5" border="0" alt="codesnippet5" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet5_5F00_thumb_5F00_7456959F.png" width="390" height="291" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The Code Snippet Manager shows all the code snippets registered with SSMS. You can use the &lt;strong&gt;Add&lt;/strong&gt; and &lt;strong&gt;Remove&lt;/strong&gt; buttons to register new code snippets or remove the code snippets already registered.&lt;/p&gt;

&lt;p&gt;Let us register the code snippet we created in the previous step. Click on the &lt;strong&gt;Add &lt;/strong&gt;button and select the folder where you have put your code snippet files. After selecting the code snippet folder, all the code snippets available within the selected folder will show up on the Code Snippet Manager.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet6_5F00_7AF97955.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="codesnippet6" border="0" alt="codesnippet6" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet6_5F00_thumb_5F00_16DA8881.png" width="390" height="291" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing the newly added code snippet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is time for us to test the code snippet we just created and registered. Switch back to SSMS query window and press &lt;strong&gt;CTRL+K, CTRL+X&lt;/strong&gt; and it will open the code snippet prompt as given below.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet7_5F00_574D2530.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="codesnippet7" border="0" alt="codesnippet7" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet7_5F00_thumb_5F00_5CBB95D4.png" width="390" height="64" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Select the code snippet “try-catch” and it will insert the TSQL code we placed within the snippet file at the current cursor position within the SSMS query window.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet8_5F00_28A6F681.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="codesnippet8" border="0" alt="codesnippet8" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jacob/codesnippet8_5F00_thumb_5F00_4711376A.png" width="247" height="139" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The code given above is very basic and used for the demonstration purpose only. You might end up creating more complex code snippets in most real world scenarios. The &lt;a href="http://snippetdesigner.codeplex.com"&gt;Snippet Designer&lt;/a&gt; tool mentioned earlier is quite capable of creating code snippets for Visual Studio as well as SSMS.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=10423" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/ExploringBeyondRelational/~4/TmayUxQf-ao" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/TSQL/default.aspx">TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SSMS/default.aspx">SSMS</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQLSERVER/default.aspx">SQLSERVER</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_TSQL/default.aspx">#TSQL</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/DENALI/default.aspx">DENALI</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/SQL11/default.aspx">SQL11</category><category domain="http://beyondrelational.com/blogs/jacob/archive/tags/_2300_SQL+Server/default.aspx">#SQL Server</category><feedburner:origLink>http://beyondrelational.com/blogs/jacob/archive/2010/11/20/ssms-enhancement-in-sql11-denali-support-for-code-snippets.aspx</feedburner:origLink></item></channel></rss>

