<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">SQL Papaya</title><subtitle type="html">Ooey Gooey SQL Goodness</subtitle><id>http://blogs.technet.com/peet/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.technet.com/peet/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.technet.com/peet/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2009-01-07T01:27:00Z</updated><entry><title>Microsoft Research releases Songsmith - Boogie On!</title><link rel="alternate" type="text/html" href="http://blogs.technet.com/peet/archive/2009/01/09/microsoft-research-releases-songsmith-boogie-on.aspx" /><id>http://blogs.technet.com/peet/archive/2009/01/09/microsoft-research-releases-songsmith-boogie-on.aspx</id><published>2009-01-09T03:00:48Z</published><updated>2009-01-09T03:00:48Z</updated><content type="html">It's my second post, and it's not about SQL. If there's one thing I love more than SQL (excluding beer, chocolate, vacations etc), it's music. I'm a bit of a closet musician (hack?) and I'm really excited by a new application from Microsoft Research . It's called Songsmith and it's a fantastic tool for those who want to create songs. Just sing a melody and Songsmith will create a chord progression that fits with your tune and then generate an arrangement. That's impressive. I remember a time when...(&lt;a href="http://blogs.technet.com/peet/archive/2009/01/09/microsoft-research-releases-songsmith-boogie-on.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3178536" width="1" height="1"&gt;</content><author><name>Peet</name><uri>http://blogs.technet.com/members/Peet.aspx</uri></author><category term="Music" scheme="http://blogs.technet.com/peet/archive/tags/Music/default.aspx" /></entry><entry><title>Joining Disparate Datasets in SQL Server Reporting Services using OPENROWSET</title><link rel="alternate" type="text/html" href="http://blogs.technet.com/peet/archive/2009/01/07/joining-disparate-datasets-in-sql-server-reporting-services-using-openrowset.aspx" /><id>http://blogs.technet.com/peet/archive/2009/01/07/joining-disparate-datasets-in-sql-server-reporting-services-using-openrowset.aspx</id><published>2009-01-07T04:27:00Z</published><updated>2009-01-07T04:27:00Z</updated><content type="html">&lt;P&gt;First post, so I thought we'd ease into things with something simple.&lt;/P&gt;
&lt;P&gt;I recently happened across someone who had a problem with creating a report in SQL Server Reporting Services. The report utilised datasets from several data sources. So far no issue. However,&amp;nbsp; tables that existed in different database instances that needed to be combined into a single dataset.&lt;/P&gt;
&lt;P&gt;That is, each database has a table with a list of contacts to be retrieved as follows:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;select&lt;/SPAN&gt; FirstName,
       LastName
&lt;SPAN class=kwrd&gt;from&lt;/SPAN&gt; SalesDB.Customer.Contact &lt;/PRE&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;
&lt;/P&gt;
&lt;P&gt;The original report looked a bit like this:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;
&lt;A href="http://blogs.technet.com/blogfiles/peet/WindowsLiveWriter/JoiningDisparateDatasetsinSSRS_E229/ContactLayout_2.png" mce_href="http://blogs.technet.com/blogfiles/peet/WindowsLiveWriter/JoiningDisparateDatasetsinSSRS_E229/ContactLayout_2.png"&gt;&lt;IMG title=ContactLayout style="BORDER-TOP-WIDTH: 0px; DISPLAY: block; BORDER-LEFT-WIDTH: 0px; FLOAT: none; BORDER-BOTTOM-WIDTH: 0px; MARGIN-LEFT: auto; MARGIN-RIGHT: auto; BORDER-RIGHT-WIDTH: 0px" height=308 alt=ContactLayout src="http://blogs.technet.com/blogfiles/peet/WindowsLiveWriter/JoiningDisparateDatasetsinSSRS_E229/ContactLayout_thumb.png" width=531 border=0 mce_src="http://blogs.technet.com/blogfiles/peet/WindowsLiveWriter/JoiningDisparateDatasetsinSSRS_E229/ContactLayout_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can probably see already, this isn't exactly useful. The report should show a single contact list. For the record, if you're not certain, SSRS can't do this for you. Each data source is treated as a distinct entity and you can't make a single set of data out of them. So, we need to turn to SQL Server to provide a singe datasource that contains the dataset.&lt;/P&gt;
&lt;P&gt;Lucky enough we had an instance of SQL Server to play with and eventually use for production purposes. So, my first instinct was to create a linked server for each of the databases and then a view which combines them. Unfortunately, we ran into permissions issues and that's when I started to scratch my head. What next?&lt;/P&gt;
&lt;P&gt;Well, there's an ugly-but-functional way of taking care of situations like this - OPENROWSET. The idea is to create a simple view to query each of the servers and combine the results. The beauty of this approach is that the permissions needed are only for creating a view. &lt;/P&gt;
&lt;P&gt;OPENROWSET requires coding the credentials for the datasources inside the query. You'll recall that we were already connecting from SSRS, so we can just use the same information inside the view. In this case we were able to use a trusted connection. This is how the view looks: &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;create&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;view&lt;/SPAN&gt; GetTheData &lt;SPAN class=kwrd&gt;as&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;select&lt;/SPAN&gt; a.*
&lt;SPAN class=kwrd&gt;from&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;openrowset&lt;/SPAN&gt;(&lt;SPAN class=str&gt;'SQLNCLI'&lt;/SPAN&gt;,&amp;nbsp; &lt;SPAN class=str&gt;'Server=ServerA;
                Trusted_Connection=yes;'&lt;/SPAN&gt;, 
                &lt;SPAN class=str&gt;'select FirstName,
       LastName
from SalesDB.Customer.Contact'&lt;/SPAN&gt;
                ) &lt;SPAN class=kwrd&gt;as&lt;/SPAN&gt; tabA

&lt;SPAN class=kwrd&gt;union&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;all&lt;/SPAN&gt;  &lt;SPAN class=rem&gt;-- gives us the full datasets&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;select&lt;/SPAN&gt; tabB.*
&lt;SPAN class=kwrd&gt;from&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;openrowset&lt;/SPAN&gt;(&lt;SPAN class=str&gt;'SQLNCLI'&lt;/SPAN&gt;, 
                &lt;SPAN class=str&gt;'Server=ServerB;
                Trusted_Connection=yes;'&lt;/SPAN&gt;,
                &lt;SPAN class=str&gt;'select FirstName,
       LastName
from SalesDB.Customer.Contact '&lt;/SPAN&gt;
                ) &lt;SPAN class=kwrd&gt;as&lt;/SPAN&gt; tabB

&lt;SPAN class=kwrd&gt;union&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;all&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;select&lt;/SPAN&gt; tabC.*
&lt;SPAN class=kwrd&gt;select&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;openrowset&lt;/SPAN&gt;(&lt;SPAN class=str&gt;'SQLNCLI'&lt;/SPAN&gt;, 
                &lt;SPAN class=str&gt;'Server=Server;
                Trusted_Connection=yes;'&lt;/SPAN&gt;,
                &lt;SPAN class=str&gt;'select FirstName,
       LastName
from SalesDB.Customer.Contact '&lt;/SPAN&gt;
                ) &lt;SPAN class=kwrd&gt;as&lt;/SPAN&gt; tabC
&lt;/PRE&gt;
&lt;P&gt;From here we can ditch the 3 datasources in SSRS, set up a single datasource and reference the view GetTheData. Note that this a very simple example, connecting via SQL Native Client OLE DB provider. OPENROWSET is capable of far more than connecting to SQL Server, it's great for many other OLE DB data sources.&lt;/P&gt;
&lt;P&gt;Now, the important part for me here wasn't that I had anything technically difficult to do. My issue was that I was temporarily blind and automatically thought that linked servers would be the answer. When that didn't work I was stumped for a moment because I'd momentarily forgotten about OPENROWSET (!!) If you're like me, it's easy to have a favourite way of doing everything, to the detriment of keeping an open mind.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can find more information on OPENROWSET in BOL: &lt;A title=http://msdn.microsoft.com/en-us/library/ms190312.aspx href="http://msdn.microsoft.com/en-us/library/ms190312.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms190312.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms190312.aspx&lt;/A&gt;&lt;/P&gt;
&lt;DIV class=wlWriterEditableSmartContent id=scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e00aa36e-e6e7-4496-b7f8-26205275bed0 style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;Tagged as: &lt;A href="http://blogs.technet.com/peet/archive/SSRS/default.aspx" rel=tag mce_href="http://blogs.technet.com/peet/archive/SSRS/default.aspx"&gt;SSRS&lt;/A&gt;&lt;/DIV&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3177231" width="1" height="1"&gt;</content><author><name>Peet</name><uri>http://blogs.technet.com/members/Peet.aspx</uri></author><category term="SSRS" scheme="http://blogs.technet.com/peet/archive/tags/SSRS/default.aspx" /></entry></feed>