{"id":1057,"date":"2004-07-16T22:28:00","date_gmt":"2004-07-16T22:28:00","guid":{"rendered":"\/blogs\/bobb\/post\/Rite-of-passage-programs-and-SQLCLR.aspx"},"modified":"2013-02-22T18:42:04","modified_gmt":"2013-02-23T02:42:04","slug":"rite-of-passage-programs-and-sqlclr","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/","title":{"rendered":"&#8220;Rite of passage&#8221; programs and SQLCLR"},"content":{"rendered":"<p>\nWhen you get a brand new tool, programming language, or API, the first thing most programmers use it for is to write their favorite &quot;rite of passage&quot; program. This is an example that is so simple, it&#39;s only purpose is to illustrate the that compiler or tools are installed and working correctly and that &quot;the system knows about them&quot;. One of my old friends would call them &quot;the canonical examples&quot;.\n<\/p>\n<p>\nTwo of these that I always revert back to are &quot;Hello, World&quot; and &quot;Add two numbers together&quot;. Hello World is the first thing that you write with any new programming language. Popularized&nbsp;by K&amp;R, perhaps, maybe before. Add two numbers together is the starter distributed technologies example, the &quot;original&quot; DCE\/RPC came with this one, on the premise that, if you had to add two numbers together, it would be quicker to do it on the Cray Supercomputer across the world than to entrust it to the wimpy little CPU on your workstation. Another such program I&#39;d just heard of (so I&#39;m culturally deprived), via a <a href=\"http:\/\/blogs.msdn.com\/b\/mfussell\/archive\/2004\/05\/13\/130969.aspx\" class=\"broken_link\">Mark Fussell blog posting<\/a> is the &quot;99 bottles of beer&quot; program, especially useful for recusrive languages. And of course, my habit of writing a <a href=\"\/blogs\/bobb\/#ac9275759-424c-4e89-9b65-b73ef17a46e6\">new data provider <\/a>when the model changes.\n<\/p>\n<p>\nBeing a database programmer, when using SQL Server, the rite of passage program is to do what amounts to &quot;select * from authors&quot; in the pubs sample database. I was saddened to hear that the pubs sample database wouldn&#39;t ship by default with SQL Server 2005, but already had my &quot;instpubs.sql&quot; script stashed away for a rainy day.\n<\/p>\n<p>\nHere&#39;s my three favorite &quot;rite of passage&quot; programs, written as SQLCLR stored procedures\/user-defined functions.\n<\/p>\n<p>\n[SqlProcedure]<br \/>\npublic static void SayHello()<br \/>\n{&nbsp;&nbsp; \/\/ the &#39;H&#39;&nbsp; and &#39;W&#39; must be capitalized. Exclamation point is required.<br \/>\n&nbsp;&nbsp;&nbsp; SqlContext.GetPipe().Send(&quot;Hello World!&quot;);<br \/>\n}\n<\/p>\n<p>\n[SqlFunction]<br \/>\npublic static SqlInt32 AddTwo(SqlInt32 x, SqlInt32 y)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; return x + y;<br \/>\n}\n<\/p>\n<p>\n[SqlProcedure]<br \/>\npublic static void GetAuthors()<br \/>\n{<br \/>\n&nbsp;&nbsp; SqlCommand cmd = SqlContext.GetCommand();<br \/>\n&nbsp;&nbsp; cmd.CommandText = &quot;select * from authors&quot;;<br \/>\n&nbsp;&nbsp; SqlContext.GetPipe().Execute(cmd);<br \/>\n}\n<\/p>\n<p>\nand the T-SQL to invoke them:\n<\/p>\n<p>\nUSE pubs<br \/>\nGO\n<\/p>\n<p>\nEXECUTE SayHello<br \/>\nGO\n<\/p>\n<p>\nDECLARE @answer int<br \/>\nSET @answer = dbo.AddTwo(2,3)<br \/>\nPRINT @answer<br \/>\nGO\n<\/p>\n<p>\nEXECUTE GetAuthors<br \/>\nGO<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you get a brand new tool, programming language, or API, the first thing most programmers use it for is to write their favorite &quot;rite of passage&quot; program. This is an example that is so simple, it&#39;s only purpose is to illustrate the that compiler or tools are installed and working correctly and that &quot;the [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,38],"tags":[],"class_list":["post-1057","post","type-post","status-publish","format-standard","hentry","category-sql-server-2005","category-sqlclr"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>&quot;Rite of passage&quot; programs and SQLCLR - Bob Beauchemin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"&quot;Rite of passage&quot; programs and SQLCLR - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"When you get a brand new tool, programming language, or API, the first thing most programmers use it for is to write their favorite &quot;rite of passage&quot; program. This is an example that is so simple, it&#039;s only purpose is to illustrate the that compiler or tools are installed and working correctly and that &quot;the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2004-07-16T22:28:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-02-23T02:42:04+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/\",\"name\":\"\\\"Rite of passage\\\" programs and SQLCLR - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2004-07-16T22:28:00+00:00\",\"dateModified\":\"2013-02-23T02:42:04+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server 2005\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sql-server-2005\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"&#8220;Rite of passage&#8221; programs and SQLCLR\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\"Rite of passage\" programs and SQLCLR - Bob Beauchemin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/","og_locale":"en_US","og_type":"article","og_title":"\"Rite of passage\" programs and SQLCLR - Bob Beauchemin","og_description":"When you get a brand new tool, programming language, or API, the first thing most programmers use it for is to write their favorite &quot;rite of passage&quot; program. This is an example that is so simple, it&#39;s only purpose is to illustrate the that compiler or tools are installed and working correctly and that &quot;the [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/","og_site_name":"Bob Beauchemin","article_published_time":"2004-07-16T22:28:00+00:00","article_modified_time":"2013-02-23T02:42:04+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/","name":"\"Rite of passage\" programs and SQLCLR - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2004-07-16T22:28:00+00:00","dateModified":"2013-02-23T02:42:04+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/rite-of-passage-programs-and-sqlclr\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"SQL Server 2005","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sql-server-2005\/"},{"@type":"ListItem","position":3,"name":"&#8220;Rite of passage&#8221; programs and SQLCLR"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/1057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=1057"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/1057\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=1057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=1057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=1057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}