{"id":35,"date":"2016-09-03T08:07:00","date_gmt":"2016-09-03T08:07:00","guid":{"rendered":"\/colin\/morethanfour\/post\/Testing-using-SQL-and-common-table-expressions"},"modified":"2016-09-03T08:07:00","modified_gmt":"2016-09-03T08:07:00","slug":"testing-using-sql-and-common-table-expressions","status":"publish","type":"post","link":"https:\/\/spacefold.com\/colin\/morethanfour\/2016\/09\/03\/testing-using-sql-and-common-table-expressions\/","title":{"rendered":"Testing using SQL and common table expressions"},"content":{"rendered":"<p>Sometimes I forget how to do simple things, like splitting a string into sections based on a delimiter.<\/p>\n<p>Here&#8217;s a nice way to test your code on a range of input values, and see the interim results, in one hit:<\/p>\n<pre>with <br \/>myobject as (<br \/>   -- put in a range of test values:<br \/>   select 'dbo.MyFunction' as NAME<br \/>   union<br \/>   select 'setup.ins_Contact'<br \/>   union<br \/>   select 'MyOtherFunction'<br \/>),<br \/>more2 as (<br \/>   -- calculate interesting attributes:<br \/>   select<br \/>      NAME,<br \/>      len( NAME )            as LENGTH_,<br \/>      charindex( '.', NAME ) as POSITION<br \/>   from myobject<br \/>)<br \/>-- perform the test:<br \/>select <br \/>   NAME, POSITION, LENGTH_,<br \/>   case when POSITION=0 then 'dbo'<br \/>                        else substring( NAME, 1, POSITION-1 ) <br \/>                        end as SCHEMA_,<br \/>   substring( NAME, POSITION+1 , (LENGTH_ - POSITION ) ) as OBJECT_<br \/>from more2;<br \/>;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes I forget how to do simple things, like splitting a string into sections based on a delimiter. Here&#8217;s a nice way to test your code on a range of input values, and see the interim results, in one hit: with myobject as ( &#8212; put in a range of test values: select &#8216;dbo.MyFunction&#8217; as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,17],"tags":[],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-sql-syntax","category-t-sql","post-preview"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}