<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Stephen Forte`s Blog</title>
    <link>http://www.stephenforte.net/</link>
    <description>Sex, Drugs, and .NET</description>
    <language>en-us</language>
    <copyright>Stephen Forte</copyright>
    <lastBuildDate>Tue, 18 Nov 2008 03:20:35 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>stevef@orcsweb.com</managingEditor>
    <webMaster>stevef@orcsweb.com</webMaster>
    <geo:lat>40.776777</geo:lat><geo:long>-73.954103</geo:long><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/StephenFortesBlog" type="application/rss+xml" /><item>
      <trackback:ping>http://www.stephenforte.net/Trackback.aspx?guid=da756fc8-8717-4514-a4d4-827f133b201d</trackback:ping>
      <pingback:server>http://www.stephenforte.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.stephenforte.net/PermaLink,guid,da756fc8-8717-4514-a4d4-827f133b201d.aspx</pingback:target>
      <dc:creator>Stephen Forte</dc:creator>
      <wfw:comment>http://www.stephenforte.net/CommentView,guid,da756fc8-8717-4514-a4d4-827f133b201d.aspx</wfw:comment>
      <wfw:commentRss>http://www.stephenforte.net/SyndicationService.asmx/GetEntryCommentsRss?guid=da756fc8-8717-4514-a4d4-827f133b201d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <h3>Data Access Smackdown 
</h3>
        <p>
          <a>
          </a>
        </p>
        <p>
Subject:  
<br /><b>You <i>must</i> register at <a href="https://www.clicktoattend.com/invitation.aspx?code=132141">https://www.clicktoattend.com/invitation.aspx?code=132141</a> in
order to be admitted to the building and attend.</b><br />
Microsoft introduced several new data access technologies in .NET 3.5 SP1. Which one
should you use? Entity Framework? Dynamic Data? ADO.NET Data Services (Astoria)? Linq?
POADN? (Plain old ADO .NET) What about ORMs? Has Microsoft lost its mind? Join Stephen
in a discussion on Data Access Methodologies for the 21st Century, including a discussion
of ATOM over REST. Note: This will require some audience participation. 
</p>
        <p>
Speaker:  
<br /><b>Stephen Forte, Telerik</b><br />
Stephen Forte is Chief Strategy Officer of Telerik, a leading vendor in .NET components.
Prior to his position at Telerik, Stephen was the Chief Technology Officer (CTO) and
co-founder of Corzen, Inc, a New York based provider of online market research data
for Wall Street Firms. Corzen was acquired by Wanted Technologies (TXV: WAN) in 2007.
Stephen is also the Microsoft Regional Director for the NY Metro region and speaks
regularly at industry conferences around the world. He has written several books on
application and database development including Programming Microsoft SQL Server 2008
(MS Press). Prior to Corzen, Stephen served as the CTO of Zagat Survey in New York
City and also was co-founder and CTO of the New York based software consulting firm
The Aurora Development Group. He is currently an MVP, INETA speaker and is the co-moderator
and founder of the NYC .NET Developer Group. Stephen has an MBA from the City University
of New York (Baruch College). Stephen is also a certified scrum master.
</p>
        <p>
Date:  
<br />
Thursday, November 20, 2008 
</p>
        <p>
Time:  
<br />
Reception 6:00 PM , Program 6:15 PM 
</p>
        <p>
Location:   
<br />
Microsoft , 1290 Avenue of the Americas (the AXA building - bet. 51st/52nd Sts.) ,
6th floor 
</p>
        <p>
Directions: 
<br />
B/D/F/V to 47th-50th Sts./Rockefeller Ctr 
<br />
1 to 50th St./Bway 
<br />
N/R/W to 49th St./7th Ave.
</p>
        <img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=da756fc8-8717-4514-a4d4-827f133b201d" />
      <xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/StephenFortesBlog/~4/456707431" height="1" width="1" /></body>
      <title>NYC .NET Developers User Group-&amp;gt; Meeting Thursday</title>
      <guid isPermaLink="false">http://www.stephenforte.net/PermaLink,guid,da756fc8-8717-4514-a4d4-827f133b201d.aspx</guid>
      <link>http://feeds.feedburner.com/~r/StephenFortesBlog/~3/456707431/PermaLink,guid,da756fc8-8717-4514-a4d4-827f133b201d.aspx</link>
      <pubDate>Tue, 18 Nov 2008 03:20:35 GMT</pubDate>
      <description>&lt;h3&gt;Data Access Smackdown 
&lt;/h3&gt;
&lt;p&gt;
&lt;a&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Subject:&amp;#160; 
&lt;br /&gt;
&lt;b&gt;You &lt;i&gt;must&lt;/i&gt; register at &lt;a href="https://www.clicktoattend.com/invitation.aspx?code=132141"&gt;https://www.clicktoattend.com/invitation.aspx?code=132141&lt;/a&gt; in
order to be admitted to the building and attend.&lt;/b&gt; 
&lt;br /&gt;
Microsoft introduced several new data access technologies in .NET 3.5 SP1. Which one
should you use? Entity Framework? Dynamic Data? ADO.NET Data Services (Astoria)? Linq?
POADN? (Plain old ADO .NET) What about ORMs? Has Microsoft lost its mind? Join Stephen
in a discussion on Data Access Methodologies for the 21st Century, including a discussion
of ATOM over REST. Note: This will require some audience participation. 
&lt;/p&gt;
&lt;p&gt;
Speaker:&amp;#160; 
&lt;br /&gt;
&lt;b&gt;Stephen Forte, Telerik&lt;/b&gt; 
&lt;br /&gt;
Stephen Forte is Chief Strategy Officer of Telerik, a leading vendor in .NET components.
Prior to his position at Telerik, Stephen was the Chief Technology Officer (CTO) and
co-founder of Corzen, Inc, a New York based provider of online market research data
for Wall Street Firms. Corzen was acquired by Wanted Technologies (TXV: WAN) in 2007.
Stephen is also the Microsoft Regional Director for the NY Metro region and speaks
regularly at industry conferences around the world. He has written several books on
application and database development including Programming Microsoft SQL Server 2008
(MS Press). Prior to Corzen, Stephen served as the CTO of Zagat Survey in New York
City and also was co-founder and CTO of the New York based software consulting firm
The Aurora Development Group. He is currently an MVP, INETA speaker and is the co-moderator
and founder of the NYC .NET Developer Group. Stephen has an MBA from the City University
of New York (Baruch College). Stephen is also a certified scrum master.
&lt;/p&gt;
&lt;p&gt;
Date:&amp;#160; 
&lt;br /&gt;
Thursday, November 20, 2008 
&lt;/p&gt;
&lt;p&gt;
Time:&amp;#160; 
&lt;br /&gt;
Reception 6:00 PM , Program 6:15 PM 
&lt;/p&gt;
&lt;p&gt;
Location:&amp;#160;&amp;#160; 
&lt;br /&gt;
Microsoft , 1290 Avenue of the Americas (the AXA building - bet. 51st/52nd Sts.) ,
6th floor 
&lt;/p&gt;
&lt;p&gt;
Directions: 
&lt;br /&gt;
B/D/F/V to 47th-50th Sts./Rockefeller Ctr 
&lt;br /&gt;
1 to 50th St./Bway 
&lt;br /&gt;
N/R/W to 49th St./7th Ave.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=da756fc8-8717-4514-a4d4-827f133b201d" /&gt;</description>
      <comments>http://www.stephenforte.net/CommentView,guid,da756fc8-8717-4514-a4d4-827f133b201d.aspx</comments>
      <category>.NET User Group</category>
      <category>Community</category>
    <feedburner:origLink>http://www.stephenforte.net/PermaLink,guid,da756fc8-8717-4514-a4d4-827f133b201d.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.stephenforte.net/Trackback.aspx?guid=bea68676-435b-4f4b-9c3a-2a8a7d73e7dd</trackback:ping>
      <pingback:server>http://www.stephenforte.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.stephenforte.net/PermaLink,guid,bea68676-435b-4f4b-9c3a-2a8a7d73e7dd.aspx</pingback:target>
      <dc:creator>Stephen Forte</dc:creator>
      <wfw:comment>http://www.stephenforte.net/CommentView,guid,bea68676-435b-4f4b-9c3a-2a8a7d73e7dd.aspx</wfw:comment>
      <wfw:commentRss>http://www.stephenforte.net/SyndicationService.asmx/GetEntryCommentsRss?guid=bea68676-435b-4f4b-9c3a-2a8a7d73e7dd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
After 4 days at TechEd here in Barcelona, I have done 6 sessions and have 2 to go
tomorrow. They are:
</p>
        <p>
          <b>DAT02-IS </b>
        </p>
        <p>
        </p>
        <p>
Data Access Smackdown 
</p>
        <p>
Interactive Session 
</p>
        <p>
Database Platform 
</p>
        <p>
11/14/2008   10:45AM - 12:00PM 
</p>
        <p>
          <b>DVP04-IS (R) </b>
        </p>
        <p>
        </p>
        <p>
Tech·Ed Daily Scrum! 
</p>
        <p>
Interactive Session 
</p>
        <p>
Development Practices 
</p>
        <p>
11/14/2008   3:15PM - 4:30PM 
</p>
        <img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=bea68676-435b-4f4b-9c3a-2a8a7d73e7dd" />
      <xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/StephenFortesBlog/~4/451868037" height="1" width="1" /></body>
      <title>TechED Europe Day 4 Update: 6 Sessions down and 2 to go</title>
      <guid isPermaLink="false">http://www.stephenforte.net/PermaLink,guid,bea68676-435b-4f4b-9c3a-2a8a7d73e7dd.aspx</guid>
      <link>http://feeds.feedburner.com/~r/StephenFortesBlog/~3/451868037/PermaLink,guid,bea68676-435b-4f4b-9c3a-2a8a7d73e7dd.aspx</link>
      <pubDate>Thu, 13 Nov 2008 15:06:13 GMT</pubDate>
      <description>&lt;p&gt;
After 4 days at TechEd here in Barcelona, I have done 6 sessions and have 2 to go
tomorrow. They are:
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;DAT02-IS &lt;/b&gt; 
&lt;p&gt;
&lt;/p&gt;
&gt;
&lt;p&gt;
Data Access Smackdown 
&lt;/p&gt;
&lt;p&gt;
Interactive Session 
&lt;/p&gt;
&lt;p&gt;
Database Platform 
&lt;/p&gt;
&lt;p&gt;
11/14/2008&amp;#160;&amp;#160; 10:45AM - 12:00PM 
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;DVP04-IS (R) &lt;/b&gt; 
&lt;p&gt;
&lt;/p&gt;
&gt;
&lt;p&gt;
Tech·Ed Daily Scrum! 
&lt;/p&gt;
&lt;p&gt;
Interactive Session 
&lt;/p&gt;
&lt;p&gt;
Development Practices 
&lt;/p&gt;
&lt;p&gt;
11/14/2008&amp;#160;&amp;#160; 3:15PM - 4:30PM 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=bea68676-435b-4f4b-9c3a-2a8a7d73e7dd" /&gt;</description>
      <comments>http://www.stephenforte.net/CommentView,guid,bea68676-435b-4f4b-9c3a-2a8a7d73e7dd.aspx</comments>
      <category>Tech*Ed 2004</category>
    <feedburner:origLink>http://www.stephenforte.net/PermaLink,guid,bea68676-435b-4f4b-9c3a-2a8a7d73e7dd.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.stephenforte.net/Trackback.aspx?guid=aa0dd52c-08a6-43ea-ba17-92400e50ad42</trackback:ping>
      <pingback:server>http://www.stephenforte.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.stephenforte.net/PermaLink,guid,aa0dd52c-08a6-43ea-ba17-92400e50ad42.aspx</pingback:target>
      <dc:creator>Stephen Forte</dc:creator>
      <wfw:comment>http://www.stephenforte.net/CommentView,guid,aa0dd52c-08a6-43ea-ba17-92400e50ad42.aspx</wfw:comment>
      <wfw:commentRss>http://www.stephenforte.net/SyndicationService.asmx/GetEntryCommentsRss?guid=aa0dd52c-08a6-43ea-ba17-92400e50ad42</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A lot of RDs arrived in Barcelona yesterday to start TechED Europe 2008. We went out
for some tapas and sangria last night and the bill came to 779 euros. What happens
when you get 15 RDs trying to split the bill with their credit card? Chaos. 
</p>
        <p>
 
</p>
        <p>
          <a href="http://www.stephenforte.net/content/binary/WindowsLiveWriter/TechEdEuropePreConDrinkingandEatingwithR_8DDD/bill_4.jpg">
            <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px; display: inline" title="bill" border="0" alt="bill" src="http://www.stephenforte.net/content/binary/WindowsLiveWriter/TechEdEuropePreConDrinkingandEatingwithR_8DDD/bill_thumb_1.jpg" width="392" height="290" />
          </a>
        </p>
        <img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=aa0dd52c-08a6-43ea-ba17-92400e50ad42" />
      <xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/StephenFortesBlog/~4/448486506" height="1" width="1" /></body>
      <title>TechEd Europe Pre-Con: Drinking and Eating with RDs</title>
      <guid isPermaLink="false">http://www.stephenforte.net/PermaLink,guid,aa0dd52c-08a6-43ea-ba17-92400e50ad42.aspx</guid>
      <link>http://feeds.feedburner.com/~r/StephenFortesBlog/~3/448486506/PermaLink,guid,aa0dd52c-08a6-43ea-ba17-92400e50ad42.aspx</link>
      <pubDate>Mon, 10 Nov 2008 15:05:26 GMT</pubDate>
      <description>&lt;p&gt;
A lot of RDs arrived in Barcelona yesterday to start TechED Europe 2008. We went out
for some tapas and sangria last night and the bill came to 779 euros. What happens
when you get 15 RDs trying to split the bill with their credit card? Chaos. 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.stephenforte.net/content/binary/WindowsLiveWriter/TechEdEuropePreConDrinkingandEatingwithR_8DDD/bill_4.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px; display: inline" title="bill" border="0" alt="bill" src="http://www.stephenforte.net/content/binary/WindowsLiveWriter/TechEdEuropePreConDrinkingandEatingwithR_8DDD/bill_thumb_1.jpg" width="392" height="290" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=aa0dd52c-08a6-43ea-ba17-92400e50ad42" /&gt;</description>
      <comments>http://www.stephenforte.net/CommentView,guid,aa0dd52c-08a6-43ea-ba17-92400e50ad42.aspx</comments>
      <category>Regional Director Program</category>
      <category>Tech*Ed 2004</category>
    <feedburner:origLink>http://www.stephenforte.net/PermaLink,guid,aa0dd52c-08a6-43ea-ba17-92400e50ad42.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.stephenforte.net/Trackback.aspx?guid=cf62cd2a-d014-4793-ba3c-3c98335118c1</trackback:ping>
      <pingback:server>http://www.stephenforte.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.stephenforte.net/PermaLink,guid,cf62cd2a-d014-4793-ba3c-3c98335118c1.aspx</pingback:target>
      <dc:creator>Stephen Forte</dc:creator>
      <wfw:comment>http://www.stephenforte.net/CommentView,guid,cf62cd2a-d014-4793-ba3c-3c98335118c1.aspx</wfw:comment>
      <wfw:commentRss>http://www.stephenforte.net/SyndicationService.asmx/GetEntryCommentsRss?guid=cf62cd2a-d014-4793-ba3c-3c98335118c1</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here is a cool TSQL tip I will be showing off next week at <a href="http://www.stephenforte.net/ct.ashx?id=094282f0-a83d-4b23-8df5-35463f817bbd&amp;url=http%3a%2f%2fwww.stephenforte.net%2fct.ashx%3fid%3d6425f370-3e93-4f88-a57e-59dc78a88091%26url%3dhttp%253a%252f%252fwww.stephenforte.net%252fct.ashx%253fid%253d9f5a7ad4-23db-46b8-b767-8197a7795791%2526url%253dhttp%25253a%25252f%25252fwww.microsoft.com%25252femea%25252fteched2008%25252fdeveloper%25252f">TechEd
Europe</a> at one of my sessions (Rock Star Common Table Expressions).
</p>
        <p>
Let’s say you have a product table that looks like this:
</p>
        <p>
          <a href="http://www.stephenforte.net/content/binary/WindowsLiveWriter/UsingaTSQLCommonTableExpressiontoFindDup_E818/image_2.png">
            <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px; display: inline" title="image" border="0" alt="image" src="http://www.stephenforte.net/content/binary/WindowsLiveWriter/UsingaTSQLCommonTableExpressiontoFindDup_E818/image_thumb.png" width="260" height="212" />
          </a>
        </p>
        <p>
As you can see in the image, we have some duplicate data. You can use a <a href="http://msdn.microsoft.com/en-us/library/ms190766.aspx">Common
Table Expression</a> in SQL Server 2005 or 2008 to look up the “parents” using an
aggregate HAVING clause. Then you join to the CTE to the Product table on the Product_Name
field as well as the Product_ID field, but using the &gt; indicator, so we only return
the “children” or products with a higher product ID. Here is the CTE and code:
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: green; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">--Find
the Dupes with a CTE 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">WITH</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> CTEMinProductRecords 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">AS</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <p>
            </p>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: gray; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">( 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>
            <span style="color: blue">SELECT</span>
            <span style="color: fuchsia">MIN</span>
            <span style="color: gray">(</span>Product_ID<span style="color: gray">)</span><span style="color: blue">AS</span> Product_ID<span style="color: gray">,</span> Product_Name 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>
            <span style="color: blue">FROM</span> Products 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>
            <span style="color: blue">GROUP</span>
            <span style="color: blue">BY</span> Product_Name 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>
            <span style="color: blue">HAVING</span>
            <span style="color: fuchsia">COUNT</span>
            <span style="color: gray">(*)</span>
            <span style="color: gray">&gt;</span> 1 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: gray; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">) 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">SELECT</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> cte<span style="color: gray">.</span>Product_ID <span style="color: blue">as</span> DupeProductID<span style="color: gray">,</span><p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">cte<span style="color: gray">.</span>Product_Name <span style="color: blue">as</span> DupeProduct<span style="color: gray">, 
<p /></span></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">p<span style="color: gray">.</span>Product_ID <span style="color: blue">as</span> ParentID<span style="color: gray">,</span> p<span style="color: gray">.</span>Product_Name <span style="color: blue">as</span> ParentProduct<span style="color: gray">, 
<p /></span></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">p<span style="color: gray">.</span>Price <span style="color: blue">as</span> ParentPrice 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">FROM</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> Products
p 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: gray; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">JOIN</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> CTEMinProductRecords
cte <span style="color: blue">ON 
<p /></span></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>p<span style="color: gray">.</span>Product_Name <span style="color: gray">=</span> cte<span style="color: gray">.</span>Product_Name 
<p /></span>
        </p>
        <p class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>
            <span style="color: gray">AND</span> p<span style="color: gray">.</span>Product_ID <span style="color: gray">&gt;</span> cte<span style="color: gray">.</span>Product_ID</span>
        </p>
        <p>
Here are the results:
</p>
        <p>
          <a href="http://www.stephenforte.net/content/binary/WindowsLiveWriter/UsingaTSQLCommonTableExpressiontoFindDup_E818/image_4.png">
            <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px; display: inline" title="image" border="0" alt="image" src="http://www.stephenforte.net/content/binary/WindowsLiveWriter/UsingaTSQLCommonTableExpressiontoFindDup_E818/image_thumb_1.png" width="382" height="92" />
          </a>
        </p>
        <p>
Let’s say you want to automatically delete the children. While the business case for
this may exist (my old business did have a rule, the higher product id was the dupe),
you will want to update all of the “many” tables to the lower product ID first. To
then do the delete using the CTE all you have to do is convert the above select statement
to a delete statement:
</p>
        <p>
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">WITH</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> CTEMinProductRecords 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">AS</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <p>
            </p>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: gray; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">( 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>
            <span style="color: blue">SELECT</span>
            <span style="color: fuchsia">MIN</span>
            <span style="color: gray">(</span>Product_ID<span style="color: gray">)</span><span style="color: blue">AS</span> Product_ID<span style="color: gray">,</span> Product_Name 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>
            <span style="color: blue">FROM</span> Products 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>
            <span style="color: blue">GROUP</span>
            <span style="color: blue">BY</span> Product_Name 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>
            <span style="color: blue">HAVING</span>
            <span style="color: fuchsia">COUNT</span>
            <span style="color: gray">(*)</span>
            <span style="color: gray">&gt;</span> 1 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: gray; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">) 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">DELETE</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> Products<span style="color: green"><p /></span></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">FROM</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> Products
p 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: gray; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">JOIN</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> CTEMinProductRecords
cte <span style="color: blue">ON 
<p /></span></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>p<span style="color: gray">.</span>Product_Name <span style="color: gray">=</span> cte<span style="color: gray">.</span>Product_Name 
<p /></span>
        </p>
        <p class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes"> </span>
            <span style="color: gray">AND</span> p<span style="color: gray">.</span>Product_ID <span style="color: gray">&gt;</span> cte<span style="color: gray">.</span>Product_ID</span>
        </p>
Enjoy! <img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=cf62cd2a-d014-4793-ba3c-3c98335118c1" /><xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/StephenFortesBlog/~4/446851367" height="1" width="1" /></body>
      <title>Using a TSQL Common Table Expression to Find Dupe Records</title>
      <guid isPermaLink="false">http://www.stephenforte.net/PermaLink,guid,cf62cd2a-d014-4793-ba3c-3c98335118c1.aspx</guid>
      <link>http://feeds.feedburner.com/~r/StephenFortesBlog/~3/446851367/PermaLink,guid,cf62cd2a-d014-4793-ba3c-3c98335118c1.aspx</link>
      <pubDate>Sat, 08 Nov 2008 21:30:25 GMT</pubDate>
      <description>&lt;p&gt;
Here is a cool TSQL tip I will be showing off next week at &lt;a href="http://www.stephenforte.net/ct.ashx?id=094282f0-a83d-4b23-8df5-35463f817bbd&amp;amp;url=http%3a%2f%2fwww.stephenforte.net%2fct.ashx%3fid%3d6425f370-3e93-4f88-a57e-59dc78a88091%26url%3dhttp%253a%252f%252fwww.stephenforte.net%252fct.ashx%253fid%253d9f5a7ad4-23db-46b8-b767-8197a7795791%2526url%253dhttp%25253a%25252f%25252fwww.microsoft.com%25252femea%25252fteched2008%25252fdeveloper%25252f"&gt;TechEd
Europe&lt;/a&gt; at one of my sessions (Rock Star Common Table Expressions).
&lt;/p&gt;
&lt;p&gt;
Let’s say you have a product table that looks like this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.stephenforte.net/content/binary/WindowsLiveWriter/UsingaTSQLCommonTableExpressiontoFindDup_E818/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px; display: inline" title="image" border="0" alt="image" src="http://www.stephenforte.net/content/binary/WindowsLiveWriter/UsingaTSQLCommonTableExpressiontoFindDup_E818/image_thumb.png" width="260" height="212" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
As you can see in the image, we have some duplicate data. You can use a &lt;a href="http://msdn.microsoft.com/en-us/library/ms190766.aspx"&gt;Common
Table Expression&lt;/a&gt; in SQL Server 2005 or 2008 to look up the “parents” using an
aggregate HAVING clause. Then you join to the CTE to the Product table on the Product_Name
field as well as the Product_ID field, but using the &amp;gt; indicator, so we only return
the “children” or products with a higher product ID. Here is the CTE and code:
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: green; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;--Find
the Dupes with a CTE 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;WITH&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; CTEMinProductRecords 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;AS&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: gray; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;( 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: blue"&gt;SELECT&lt;/span&gt; &lt;span style="color: fuchsia"&gt;MIN&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;Product_ID&lt;span style="color: gray"&gt;)&lt;/span&gt; &lt;span style="color: blue"&gt;AS&lt;/span&gt; Product_ID&lt;span style="color: gray"&gt;,&lt;/span&gt; Product_Name 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: blue"&gt;FROM&lt;/span&gt; Products 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: blue"&gt;GROUP&lt;/span&gt; &lt;span style="color: blue"&gt;BY&lt;/span&gt; Product_Name 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: blue"&gt;HAVING&lt;/span&gt; &lt;span style="color: fuchsia"&gt;COUNT&lt;/span&gt;&lt;span style="color: gray"&gt;(*)&lt;/span&gt; &lt;span style="color: gray"&gt;&amp;gt;&lt;/span&gt; 1 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: gray; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;) 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; cte&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_ID &lt;span style="color: blue"&gt;as&lt;/span&gt; DupeProductID&lt;span style="color: gray"&gt;,&lt;/span&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;cte&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_Name &lt;span style="color: blue"&gt;as&lt;/span&gt; DupeProduct&lt;span style="color: gray"&gt;, 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;p&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_ID &lt;span style="color: blue"&gt;as&lt;/span&gt; ParentID&lt;span style="color: gray"&gt;,&lt;/span&gt; p&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_Name &lt;span style="color: blue"&gt;as&lt;/span&gt; ParentProduct&lt;span style="color: gray"&gt;, 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;p&lt;span style="color: gray"&gt;.&lt;/span&gt;Price &lt;span style="color: blue"&gt;as&lt;/span&gt; ParentPrice 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;FROM&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; Products
p 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: gray; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;JOIN&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; CTEMinProductRecords
cte &lt;span style="color: blue"&gt;ON 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;p&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_Name &lt;span style="color: gray"&gt;=&lt;/span&gt; cte&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_Name 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: gray"&gt;AND&lt;/span&gt; p&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_ID &lt;span style="color: gray"&gt;&amp;gt;&lt;/span&gt; cte&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_ID&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Here are the results:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.stephenforte.net/content/binary/WindowsLiveWriter/UsingaTSQLCommonTableExpressiontoFindDup_E818/image_4.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px; display: inline" title="image" border="0" alt="image" src="http://www.stephenforte.net/content/binary/WindowsLiveWriter/UsingaTSQLCommonTableExpressiontoFindDup_E818/image_thumb_1.png" width="382" height="92" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Let’s say you want to automatically delete the children. While the business case for
this may exist (my old business did have a rule, the higher product id was the dupe),
you will want to update all of the “many” tables to the lower product ID first. To
then do the delete using the CTE all you have to do is convert the above select statement
to a delete statement:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;WITH&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; CTEMinProductRecords 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;AS&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: gray; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;( 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: blue"&gt;SELECT&lt;/span&gt; &lt;span style="color: fuchsia"&gt;MIN&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;Product_ID&lt;span style="color: gray"&gt;)&lt;/span&gt; &lt;span style="color: blue"&gt;AS&lt;/span&gt; Product_ID&lt;span style="color: gray"&gt;,&lt;/span&gt; Product_Name 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: blue"&gt;FROM&lt;/span&gt; Products 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: blue"&gt;GROUP&lt;/span&gt; &lt;span style="color: blue"&gt;BY&lt;/span&gt; Product_Name 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: blue"&gt;HAVING&lt;/span&gt; &lt;span style="color: fuchsia"&gt;COUNT&lt;/span&gt;&lt;span style="color: gray"&gt;(*)&lt;/span&gt; &lt;span style="color: gray"&gt;&amp;gt;&lt;/span&gt; 1 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: gray; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;) 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;DELETE&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; Products&lt;span style="color: green"&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;FROM&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; Products
p 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: gray; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;JOIN&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; CTEMinProductRecords
cte &lt;span style="color: blue"&gt;ON 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;p&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_Name &lt;span style="color: gray"&gt;=&lt;/span&gt; cte&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_Name 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: gray"&gt;AND&lt;/span&gt; p&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_ID &lt;span style="color: gray"&gt;&amp;gt;&lt;/span&gt; cte&lt;span style="color: gray"&gt;.&lt;/span&gt;Product_ID&lt;/span&gt;
&lt;/p&gt;
Enjoy! &lt;img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=cf62cd2a-d014-4793-ba3c-3c98335118c1" /&gt;</description>
      <comments>http://www.stephenforte.net/CommentView,guid,cf62cd2a-d014-4793-ba3c-3c98335118c1.aspx</comments>
      <category>SQL Server</category>
      <category>Tech*Ed 2004</category>
    <feedburner:origLink>http://www.stephenforte.net/PermaLink,guid,cf62cd2a-d014-4793-ba3c-3c98335118c1.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.stephenforte.net/Trackback.aspx?guid=094282f0-a83d-4b23-8df5-35463f817bbd</trackback:ping>
      <pingback:server>http://www.stephenforte.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.stephenforte.net/PermaLink,guid,094282f0-a83d-4b23-8df5-35463f817bbd.aspx</pingback:target>
      <dc:creator>Stephen Forte</dc:creator>
      <wfw:comment>http://www.stephenforte.net/CommentView,guid,094282f0-a83d-4b23-8df5-35463f817bbd.aspx</wfw:comment>
      <wfw:commentRss>http://www.stephenforte.net/SyndicationService.asmx/GetEntryCommentsRss?guid=094282f0-a83d-4b23-8df5-35463f817bbd</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am a data guy. Maybe that is why the NHibernate Mafia likes to cal me a <a href="http://codebetter.com/blogs/jeremy.miller/archive/2008/07/22/ward-amp-i-talk-over-the-ef-vote-of-no-confidence-document.aspx">database
weenie.</a> Next week at <a href="http://www.stephenforte.net/ct.ashx?id=6425f370-3e93-4f88-a57e-59dc78a88091&amp;url=http%3a%2f%2fwww.stephenforte.net%2fct.ashx%3fid%3d9f5a7ad4-23db-46b8-b767-8197a7795791%26url%3dhttp%253a%252f%252fwww.microsoft.com%252femea%252fteched2008%252fdeveloper%252f">TechEd
Europe</a> I am doing 5 sessions about data. Friday morning I am doing <strong>DAT02-IS</strong> Data
Access Smackdown. As I said before, it is not really a smackdown, but a look at the
SP1 technology and then have a discussion on how best to make choices about which
technology to use in your projects. One of the things that I love is data as a service.
That is one reason why I am so solidly behind the Astoria Project at Microsoft (aka
ADO .NET Data Services.)
</p>
        <p>
One thing that I show in the Smackdown session is a simple LINQ to REST demo. Using
LINQ you can go against a raw REST based data service. (You can also do this via a
proxy, which I will also show at the session and at a later blog post.) 
</p>
        <p>
I have a simple Astoria service <a href="http://stevef.goes.com/northwindservice/NorthwindService.svc/">here</a>.
Let’s take a look at how to talk to it via LINQ to REST. First you have to set a reference
to System.Data.Services.Client and then pull in the namespace like so:
</p>
        <p>
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">using</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> System.Data.Services.Client; 
<p /></span>
        </p>
        <p>
Next you have to create an anonymous type to hold your data. Since we are modeling
the Customer entity in my Astoria service you have to model the type to have exactly
the same data types:
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">public</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="color: blue">class</span>
            <span style="color: #2b91af">Customer 
<p /></span>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">    </span>{ 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>
            <span style="color: blue">public</span>
            <span style="color: blue">string</span> CustomerID
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>
            <span style="color: blue">public</span>
            <span style="color: blue">string</span> CompanyName
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>
            <span style="color: blue">public</span>
            <span style="color: blue">string</span> ContactName
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>
            <span style="color: blue">public</span>
            <span style="color: blue">string</span> ContactTitle
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>
            <span style="color: blue">public</span>
            <span style="color: blue">string</span> Address
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>
            <span style="color: blue">public</span>
            <span style="color: blue">string</span> City
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>
            <span style="color: blue">public</span>
            <span style="color: blue">string</span> Region
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>
            <span style="color: blue">public</span>
            <span style="color: blue">string</span> PostalCode
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>
            <span style="color: blue">public</span>
            <span style="color: blue">string</span> Country
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>
            <span style="color: blue">public</span>
            <span style="color: blue">string</span> Phone
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>
            <span style="color: blue">public</span>
            <span style="color: blue">string</span> Fax
{ <span style="color: blue">get</span>; <span style="color: blue">set</span>; } 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <p>
 
</p>
          </span>
        </p>
        <p class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">    </span>}</span>
        </p>
        <p>
Next inside of a console application we create a new Uri to point to the Astoria service
on my server. Then we will query the service using the Astoria Uri syntax <strong>?$filter=</strong> and
add that to the Uri. After that is real simple, just loop through the customers and
do whatever you want with them. Pretty easy! In a future blog post I will show you
how to use the traditional LINQ operands (from, where, select) against an Astoria
service.
</p>
        <p>
        </p>
        <p class="MsoNormal">
          <span style="font-size: 10pt; line-height: 115%; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
          </span>
          <span style="font-size: 10pt; line-height: 115%">
            <p>
            </p>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">static</span>
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="color: blue">void</span> Main(<span style="color: blue">string</span>[]
args) 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>{ 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">            </span>
            <span style="color: #2b91af">Console</span>.Title
= <span style="color: #a31515">"Linq to Rest!!"</span>; 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <p>
 
</p>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">            </span>
            <span style="color: #2b91af">Uri</span> url
= <span style="color: blue">new</span><span style="color: #2b91af">Uri</span>(<span style="color: #a31515">"http://stevef.goes.com/northwindservice/NorthwindService.svc/"</span>); 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <p>
 
</p>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">            </span>
            <span style="color: #2b91af">DataServiceContext</span> ctx
= <span style="color: blue">new</span><span style="color: #2b91af">DataServiceContext</span>(url); 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <p>
 
</p>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">            </span>
            <span style="color: #2b91af">IEnumerable</span>&lt;<span style="color: #2b91af">Customer</span>&gt;
customers = ctx.Execute&lt;<span style="color: #2b91af">Customer</span>&gt;( 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">                </span>
            <span style="color: blue">New</span>
            <span style="color: #2b91af">Uri</span>(<span style="color: #a31515">"Customer?$filter=Country%20eq%20'Germany'"</span>, <span style="color: #2b91af">UriKind</span>.Relative)); 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <p>
 
</p>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">            </span>
            <span style="color: green">//write
it out to the console window 
<p /></span>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">            </span>
            <span style="color: blue">foreach</span> (<span style="color: blue">var</span> c <span style="color: blue">in</span> customers) 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">            </span>{ 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">                </span>
            <span style="color: #2b91af">Console</span>.WriteLine(c.CompanyName); 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">            </span>} 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">            </span>
            <span style="color: green">//keep
the window open 
<p /></span>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left">
          <span style="font-size: 10pt; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">            </span>
            <span style="color: #2b91af">Console</span>.Read(); 
<p /></span>
        </p>
        <p class="MsoNormal" align="left">
          <span style="font-size: 10pt; line-height: 115%; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">        </span>}</span>
          <span style="font-size: 10pt; line-height: 115%">
            <p>
            </p>
          </span>
        </p>
        <img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=094282f0-a83d-4b23-8df5-35463f817bbd" />
      <xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/StephenFortesBlog/~4/445645177" height="1" width="1" /></body>
      <title>LINQ To REST Data</title>
      <guid isPermaLink="false">http://www.stephenforte.net/PermaLink,guid,094282f0-a83d-4b23-8df5-35463f817bbd.aspx</guid>
      <link>http://feeds.feedburner.com/~r/StephenFortesBlog/~3/445645177/PermaLink,guid,094282f0-a83d-4b23-8df5-35463f817bbd.aspx</link>
      <pubDate>Fri, 07 Nov 2008 16:44:44 GMT</pubDate>
      <description>&lt;p&gt;
I am a data guy. Maybe that is why the NHibernate Mafia likes to cal me a &lt;a href="http://codebetter.com/blogs/jeremy.miller/archive/2008/07/22/ward-amp-i-talk-over-the-ef-vote-of-no-confidence-document.aspx"&gt;database
weenie.&lt;/a&gt; Next week at &lt;a href="http://www.stephenforte.net/ct.ashx?id=6425f370-3e93-4f88-a57e-59dc78a88091&amp;amp;url=http%3a%2f%2fwww.stephenforte.net%2fct.ashx%3fid%3d9f5a7ad4-23db-46b8-b767-8197a7795791%26url%3dhttp%253a%252f%252fwww.microsoft.com%252femea%252fteched2008%252fdeveloper%252f"&gt;TechEd
Europe&lt;/a&gt; I am doing 5 sessions about data. Friday morning I am doing &lt;strong&gt;DAT02-IS&lt;/strong&gt; Data
Access Smackdown. As I said before, it is not really a smackdown, but a look at the
SP1 technology and then have a discussion on how best to make choices about which
technology to use in your projects. One of the things that I love is data as a service.
That is one reason why I am so solidly behind the Astoria Project at Microsoft (aka
ADO .NET Data Services.)
&lt;/p&gt;
&lt;p&gt;
One thing that I show in the Smackdown session is a simple LINQ to REST demo. Using
LINQ you can go against a raw REST based data service. (You can also do this via a
proxy, which I will also show at the session and at a later blog post.) 
&lt;/p&gt;
&lt;p&gt;
I have a simple Astoria service &lt;a href="http://stevef.goes.com/northwindservice/NorthwindService.svc/"&gt;here&lt;/a&gt;.
Let’s take a look at how to talk to it via LINQ to REST. First you have to set a reference
to System.Data.Services.Client and then pull in the namespace like so:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;using&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; System.Data.Services.Client; 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Next you have to create an anonymous type to hold your data. Since we are modeling
the Customer entity in my Astoria service you have to model the type to have exactly
the same data types:
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;public&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Customer 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;{ 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; CustomerID
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; CompanyName
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; ContactName
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; ContactTitle
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; Address
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; City
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; Region
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; PostalCode
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; Country
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; Phone
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; Fax
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; } 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Next inside of a console application we create a new Uri to point to the Astoria service
on my server. Then we will query the service using the Astoria Uri syntax &lt;strong&gt;?$filter=&lt;/strong&gt; and
add that to the Uri. After that is real simple, just loop through the customers and
do whatever you want with them. Pretty easy! In a future blog post I will show you
how to use the traditional LINQ operands (from, where, select) against an Astoria
service.
&lt;/p&gt;
&lt;p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; line-height: 115%"&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;static&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue"&gt;string&lt;/span&gt;[]
args) 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;{ 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Title
= &lt;span style="color: #a31515"&gt;&amp;quot;Linq to Rest!!&amp;quot;&lt;/span&gt;; 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt; url
= &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;http://stevef.goes.com/northwindservice/NorthwindService.svc/&amp;quot;&lt;/span&gt;); 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataServiceContext&lt;/span&gt; ctx
= &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DataServiceContext&lt;/span&gt;(url); 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Customer&lt;/span&gt;&amp;gt;
customers = ctx.Execute&amp;lt;&lt;span style="color: #2b91af"&gt;Customer&lt;/span&gt;&amp;gt;( 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;New&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Customer?$filter=Country%20eq%20'Germany'&amp;quot;&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;UriKind&lt;/span&gt;.Relative)); 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: green"&gt;//write
it out to the console window 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue"&gt;var&lt;/span&gt; c &lt;span style="color: blue"&gt;in&lt;/span&gt; customers) 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;{ 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(c.CompanyName); 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;} 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: green"&gt;//keep
the window open 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Read(); 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" align="left"&gt;
&lt;span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; line-height: 115%"&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=094282f0-a83d-4b23-8df5-35463f817bbd" /&gt;</description>
      <comments>http://www.stephenforte.net/CommentView,guid,094282f0-a83d-4b23-8df5-35463f817bbd.aspx</comments>
      <category>Data Services</category>
      <category>Tech*Ed 2004</category>
    <feedburner:origLink>http://www.stephenforte.net/PermaLink,guid,094282f0-a83d-4b23-8df5-35463f817bbd.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.stephenforte.net/Trackback.aspx?guid=6425f370-3e93-4f88-a57e-59dc78a88091</trackback:ping>
      <pingback:server>http://www.stephenforte.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.stephenforte.net/PermaLink,guid,6425f370-3e93-4f88-a57e-59dc78a88091.aspx</pingback:target>
      <dc:creator>Stephen Forte</dc:creator>
      <wfw:comment>http://www.stephenforte.net/CommentView,guid,6425f370-3e93-4f88-a57e-59dc78a88091.aspx</wfw:comment>
      <wfw:commentRss>http://www.stephenforte.net/SyndicationService.asmx/GetEntryCommentsRss?guid=6425f370-3e93-4f88-a57e-59dc78a88091</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Next week at <a href="http://www.stephenforte.net/ct.ashx?id=9f5a7ad4-23db-46b8-b767-8197a7795791&amp;url=http%3a%2f%2fwww.microsoft.com%2femea%2fteched2008%2fdeveloper%2f">TechEd
Europe</a> I will be doing two talks on Scrum (with one repeat) and we are trying
something new at TechEd this year, so let me know what you think. 
</p>
        <p>
The talk on Tuesday, <strong>DVM309: Using Scrum to Run Your Projects</strong>, is
a typical TechEd breakout session in lecture format with Q&amp;A encouraged. I’ll
go through slides and examples from my experience as a scrum master (and also share
some of my experiences from the <a href="http://www.scrumalliance.org/profiles/37679-stephen-forte">certified
scrum master</a> class.) This is a good overview of Scrum good for beginners or experienced
scrum masters trying to scale out scrum.
</p>
        <p>
On Tuesday and Friday we turn the tables in <strong>DVP04-IS: The Tech*Ed Daily Scrum</strong>!
This is an interactive session where I will be passing around a microphone and it
will be 100% Q&amp;A, war stories, and interactive, no slides if I can help it. (Come
on, ask a lot of questions, tell a lot of war stories make my week a little easier!)
I have done the “Daily Scrum” talk about 10 times this year in several places (New
York, TechEd US in Orlando, Egypt, Pakistan, Netherlands, Bulgaria, Serbia, Connecticut
.NET User Group, etc) and every time it is different and exciting. I always learn
something from the audience as well. Everyone is welcome, you will see how Scrum works
in the real world as well as real life implementations. Since it is mostly interactive,
it is great for people who want to learn about scrum, as well as experts in Scrum.
My only rule is no religious warfare, other than that, anything goes! (Just ask the
Serbians, it was also the last session of their conference and we all drank beer as
we did the Q&amp;A.)
</p>
        <p>
See you all there… If you can’t make it, I hope they will film it and put it online.
</p>
        <img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=6425f370-3e93-4f88-a57e-59dc78a88091" />
      <xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/StephenFortesBlog/~4/444356401" height="1" width="1" /></body>
      <title>Scrum Talks at TechEd Europe Next Week&amp;hellip;</title>
      <guid isPermaLink="false">http://www.stephenforte.net/PermaLink,guid,6425f370-3e93-4f88-a57e-59dc78a88091.aspx</guid>
      <link>http://feeds.feedburner.com/~r/StephenFortesBlog/~3/444356401/PermaLink,guid,6425f370-3e93-4f88-a57e-59dc78a88091.aspx</link>
      <pubDate>Thu, 06 Nov 2008 13:20:19 GMT</pubDate>
      <description>&lt;p&gt;
Next week at &lt;a href="http://www.stephenforte.net/ct.ashx?id=9f5a7ad4-23db-46b8-b767-8197a7795791&amp;amp;url=http%3a%2f%2fwww.microsoft.com%2femea%2fteched2008%2fdeveloper%2f"&gt;TechEd
Europe&lt;/a&gt; I will be doing two talks on Scrum (with one repeat) and we are trying
something new at TechEd this year, so let me know what you think. 
&lt;/p&gt;
&lt;p&gt;
The talk on Tuesday, &lt;strong&gt;DVM309: Using Scrum to Run Your Projects&lt;/strong&gt;, is
a typical TechEd breakout session in lecture format with Q&amp;amp;A encouraged. I’ll
go through slides and examples from my experience as a scrum master (and also share
some of my experiences from the &lt;a href="http://www.scrumalliance.org/profiles/37679-stephen-forte"&gt;certified
scrum master&lt;/a&gt; class.) This is a good overview of Scrum good for beginners or experienced
scrum masters trying to scale out scrum.
&lt;/p&gt;
&lt;p&gt;
On Tuesday and Friday we turn the tables in &lt;strong&gt;DVP04-IS: The Tech*Ed Daily Scrum&lt;/strong&gt;!
This is an interactive session where I will be passing around a microphone and it
will be 100% Q&amp;amp;A, war stories, and interactive, no slides if I can help it. (Come
on, ask a lot of questions, tell a lot of war stories make my week a little easier!)
I have done the “Daily Scrum” talk about 10 times this year in several places (New
York, TechEd US in Orlando, Egypt, Pakistan, Netherlands, Bulgaria, Serbia, Connecticut
.NET User Group, etc) and every time it is different and exciting. I always learn
something from the audience as well. Everyone is welcome, you will see how Scrum works
in the real world as well as real life implementations. Since it is mostly interactive,
it is great for people who want to learn about scrum, as well as experts in Scrum.
My only rule is no religious warfare, other than that, anything goes! (Just ask the
Serbians, it was also the last session of their conference and we all drank beer as
we did the Q&amp;amp;A.)
&lt;/p&gt;
&lt;p&gt;
See you all there… If you can’t make it, I hope they will film it and put it online.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=6425f370-3e93-4f88-a57e-59dc78a88091" /&gt;</description>
      <comments>http://www.stephenforte.net/CommentView,guid,6425f370-3e93-4f88-a57e-59dc78a88091.aspx</comments>
      <category>Agile</category>
      <category>Tech*Ed 2004</category>
    <feedburner:origLink>http://www.stephenforte.net/PermaLink,guid,6425f370-3e93-4f88-a57e-59dc78a88091.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.stephenforte.net/Trackback.aspx?guid=07dfeb00-d0b0-47dd-9761-3b4c9f160277</trackback:ping>
      <pingback:server>http://www.stephenforte.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.stephenforte.net/PermaLink,guid,07dfeb00-d0b0-47dd-9761-3b4c9f160277.aspx</pingback:target>
      <dc:creator>Stephen Forte</dc:creator>
      <wfw:comment>http://www.stephenforte.net/CommentView,guid,07dfeb00-d0b0-47dd-9761-3b4c9f160277.aspx</wfw:comment>
      <wfw:commentRss>http://www.stephenforte.net/SyndicationService.asmx/GetEntryCommentsRss?guid=07dfeb00-d0b0-47dd-9761-3b4c9f160277</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.stephenforte.net/PermaLink,guid,9d26a98e-6d6a-4a60-9a63-8563c1f4d8c0.aspx">Yesterday</a> I
showed how there are some new language constructs in TSQL that will be very familiar
to C# developers. I will be doing three talks on TSQL next week at <a href="http://www.stephenforte.net/ct.ashx?id=9d26a98e-6d6a-4a60-9a63-8563c1f4d8c0&amp;url=http%3a%2f%2fwww.microsoft.com%2femea%2fteched2008%2fdeveloper%2f">TechED
Developers</a> in Barcelona and the talks are designed for application developers.
(But database geeks will enjoy these sessions as well!) If you write any TSQL code
in your applications today, or interact with it, these sessions will give you some
advice and help change the way you approach particular problems.
</p>
        <p>
Today I want to show a new feature about using Table Valued Parameters (TVP) in a
stored procedure and then calling it from an ASP .NET page or any other .NET client
using ADO.NET. A TVP is new in SQL Server 2008, so you can now declare a type of TABLE,
insert data into it, and then pass it to a stored procedure. Have you ever passed
in a CSV string to a DAL or stored procedure or even an XML data type, then parsed
it and executed some SQL? TVP will eliminate that.  Here is an example:
</p>
        <p>
First create a new table for us to play with:
</p>
        <p>
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">Create</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="color: blue">Table</span> TVP_TEST 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: gray; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">(</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">Field_ID <span style="color: blue">int</span><span style="color: blue">primary</span><span style="color: blue">key</span><span style="color: gray">,</span> Field_DESC <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))</span></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="color: gray">
            </span>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
Next create the TVP by declaring a new type. Notice that I have created the type to
be exactly the same shape as the underlying table, this is not a requirement, however,
it is important to do so if you are going to be doing inserts as we do below.
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
 
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: green; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <p>
            </p>
          </span>
        </p>
        <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">CREATE</span>
        <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
          <span style="color: blue">TYPE</span> TVP_TESTType <span style="color: blue">AS</span><span style="color: blue">TABLE</span><span style="color: gray">( 
<p /></span></span>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-tab-count: 1">     </span>Field_ID <span style="color: blue">int</span><span style="color: gray">,</span><p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-tab-count: 1">     </span>Field_DESC <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))</span></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
 
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
Next create a variable as type TVP_TESTType and insert some data into it, insert is
done the same way we would add data to a normal table. Notice that this only puts
data into the variable, NOT the underlying table:
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: green; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">--put
data into the type 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">DECLARE</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> @MyTable <span style="color: blue">as</span> TVP_TESTType 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <p>
 
</p>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: green; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">--put
data into the type 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">INSERT</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="color: blue">INTO</span> @MyTable <span style="color: blue">VALUES 
<p /></span></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-tab-count: 1">     </span>
          </span>
          <span style="color: gray; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">(</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">1<span style="color: gray">,</span><span style="color: red">'Test'</span><span style="color: gray">),</span><span style="color: blue" /><span style="color: gray">(</span>2<span style="color: gray">,</span><span style="color: red">'Next
Test'</span><span style="color: gray">)</span></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
 
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
Now you can insert data into a table very easily (remember @MyTable has to be in scope):
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">INSERT</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="color: blue">INTO</span> TVP_TEST 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">     </span>
            <span style="color: blue">SELECT</span>
            <span style="color: gray">*</span>
            <span style="color: blue">FROM</span> @Mytable</span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
 
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
To get really useful, let’s create a stored procedure that will accept as a parameter
the TVP_TESTType data type and insert data into the TVP_TEST table using the parameter,
notice no parsing of CSV strings, etc:
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">CREATE</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="color: blue">PROCEDURE</span> usp_ins_MyTable 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: gray; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">(</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">@MyTVP <span style="color: blue">as</span> TVP_TESTType <span style="color: blue">READONLY</span><span style="color: gray">) 
<p /></span></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">As 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">INSERT</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="color: blue">INTO</span> TVP_TEST 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <span style="mso-spacerun: yes">     </span>
            <span style="color: blue">SELECT</span>
            <span style="color: gray">*</span>
            <span style="color: blue">FROM</span> @MyTVP</span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
You can call this stored procedure as so, as long as @MyTable is in scope and is filled
with data:
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
 
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: blue; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">exec</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> usp_ins_MyTable<span style="color: blue" />@MyTVP<span style="color: gray">=</span>@MyTable </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
But what is really exciting is calling this data from a .NET client. If you have an
ADO .NET dataset that is the same shape of the TVP you can pass it in from the client
to the server, greatly enhancing data access and batch operations.You can pass in
a dataset as a parameter using the SqlDbType.Structured as its data type. 
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
 
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
Here is some code from C#, just remember that ds is our active dataset filled with
data and shaped the same way as TVP_TESTType:
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
 
</p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: #2b91af; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">SqlCommand</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> cmd
= <span style="color: blue">new</span><span style="color: #2b91af">SqlCommand</span>(<span style="color: #a31515">"usp_ins_Portfolio"</span>,
conn); 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">cmd.CommandType
= <span style="color: #2b91af">CommandType</span>.StoredProcedure; 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: green; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">//add
the ds here as a tvp 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: #2b91af; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">SqlParameter</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> sp
= cmd.Parameters.AddWithValue(<span style="color: #a31515">"@Portfolio"</span>,
ds.Tables[0]); 
<p /></span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="color: green; font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">//notice
structured</span>
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">
            <p>
            </p>
          </span>
        </p>
        <p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">sp.SqlDbType
= <span style="color: #2b91af">SqlDbType</span>.Structured; <span style="color: green"><p /></span></span>
        </p>
        <p class="MsoNormal">
          <span style="font-family: &quot;Lucida Console&quot;; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">cmd.ExecuteNonQuery();</span>
        </p>
        <p class="MsoNormal">
Pretty easy! Now you can pass data sets in as parameters to a stored procedure, eliminating
some funky parsing on either the client or server.
</p>
        <img width="0" height="0" src="http://www.stephenforte.net/aggbug.ashx?id=07dfeb00-d0b0-47dd-9761-3b4c9f160277" />
      <xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/StephenFortesBlog/~4/443366510" height="1" width="1" /></body>
      <title>Table Value Parameters Make Life Easier for C# Developers</title>
      <guid isPermaLink="false">http://www.stephenforte.net/PermaLink,guid,07dfeb00-d0b0-47dd-9761-3b4c9f160277.aspx</guid>
      <link>http://feeds.feedburner.com/~r/StephenFortesBlog/~3/443366510/PermaLink,guid,07dfeb00-d0b0-47dd-9761-3b4c9f160277.aspx</link>
      <pubDate>Wed, 05 Nov 2008 15:59:27 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.stephenforte.net/PermaLink,guid,9d26a98e-6d6a-4a60-9a63-8563c1f4d8c0.aspx"&gt;Yesterday&lt;/a&gt; I
showed how there are some new language constructs in TSQL that will be very familiar
to C# developers. I will be doing three talks on TSQL next week at &lt;a href="http://www.stephenforte.net/ct.ashx?id=9d26a98e-6d6a-4a60-9a63-8563c1f4d8c0&amp;amp;url=http%3a%2f%2fwww.microsoft.com%2femea%2fteched2008%2fdeveloper%2f"&gt;TechED
Developers&lt;/a&gt; in Barcelona and the talks are designed for application developers.
(But database geeks will enjoy these sessions as well!) If you write any TSQL code
in your applications today, or interact with it, these sessions will give you some
advice and help change the way you approach particular problems.
&lt;/p&gt;
&lt;p&gt;
Today I want to show a new feature about using Table Valued Parameters (TVP) in a
stored procedure and then calling it from an ASP .NET page or any other .NET client
using ADO.NET. A TVP is new in SQL Server 2008, so you can now declare a type of TABLE,
insert data into it, and then pass it to a stored procedure. Have you ever passed
in a CSV string to a DAL or stored procedure or even an XML data type, then parsed
it and executed some SQL? TVP will eliminate that.&amp;#160; Here is an example:
&lt;/p&gt;
&lt;p&gt;
First create a new table for us to play with:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;Create&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; &lt;span style="color: blue"&gt;Table&lt;/span&gt; TVP_TEST 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: gray; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;(&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;Field_ID &lt;span style="color: blue"&gt;int&lt;/span&gt; &lt;span style="color: blue"&gt;primary&lt;/span&gt; &lt;span style="color: blue"&gt;key&lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt; Field_DESC &lt;span style="color: blue"&gt;varchar&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;10&lt;span style="color: gray"&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: gray"&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
Next create the TVP by declaring a new type. Notice that I have created the type to
be exactly the same shape as the underlying table, this is not a requirement, however,
it is important to do so if you are going to be doing inserts as we do below.
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&amp;#160;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: green; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; &lt;span style="color: blue"&gt;TYPE&lt;/span&gt; TVP_TESTType &lt;span style="color: blue"&gt;AS&lt;/span&gt; &lt;span style="color: blue"&gt;TABLE&lt;/span&gt;&lt;span style="color: gray"&gt;( 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;Field_ID &lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;Field_DESC &lt;span style="color: blue"&gt;varchar&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;10&lt;span style="color: gray"&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&amp;#160;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
Next create a variable as type TVP_TESTType and insert some data into it, insert is
done the same way we would add data to a normal table. Notice that this only puts
data into the variable, NOT the underlying table:
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: green; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;--put
data into the type 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; @MyTable &lt;span style="color: blue"&gt;as&lt;/span&gt; TVP_TESTType 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: green; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;--put
data into the type 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; &lt;span style="color: blue"&gt;INTO&lt;/span&gt; @MyTable &lt;span style="color: blue"&gt;VALUES 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: gray; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;(&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;1&lt;span style="color: gray"&gt;,&lt;/span&gt; &lt;span style="color: red"&gt;'Test'&lt;/span&gt;&lt;span style="color: gray"&gt;),&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;2&lt;span style="color: gray"&gt;,&lt;/span&gt; &lt;span style="color: red"&gt;'Next
Test'&lt;/span&gt;&lt;span style="color: gray"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&amp;#160;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
Now you can insert data into a table very easily (remember @MyTable has to be in scope):
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; &lt;span style="color: blue"&gt;INTO&lt;/span&gt; TVP_TEST 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;SELECT&lt;/span&gt; &lt;span style="color: gray"&gt;*&lt;/span&gt; &lt;span style="color: blue"&gt;FROM&lt;/span&gt; @Mytable&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&amp;#160;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
To get really useful, let’s create a stored procedure that will accept as a parameter
the TVP_TESTType data type and insert data into the TVP_TEST table using the parameter,
notice no parsing of CSV strings, etc:
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; &lt;span style="color: blue"&gt;PROCEDURE&lt;/span&gt; usp_ins_MyTable 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: gray; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;(&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;@MyTVP &lt;span style="color: blue"&gt;as&lt;/span&gt; TVP_TESTType &lt;span style="color: blue"&gt;READONLY&lt;/span&gt;&lt;span style="color: gray"&gt;) 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;As 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt; &lt;span style="color: blue"&gt;INTO&lt;/span&gt; TVP_TEST 
&lt;p&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;SELECT&lt;/span&gt; &lt;span style="color: gray"&gt;*&lt;/span&gt; &lt;span style="color: blue"&gt;FROM&lt;/span&gt; @MyTVP&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none" class="MsoNormal"&gt;
&lt;span style="font-family: &amp;quot;Lucida Console&amp;quot;; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#