{"id":151,"date":"2007-11-14T09:40:00","date_gmt":"2007-11-14T09:40:00","guid":{"rendered":"\/lisa\/post\/2007\/11\/14\/Sideways-Report-SQL-for-VFP-A-Reporting-Convergence-Chapter.aspx"},"modified":"2007-11-14T09:40:00","modified_gmt":"2007-11-14T09:40:00","slug":"sideways-report-sql-for-vfp-a-reporting-convergence-chapter","status":"publish","type":"post","link":"https:\/\/spacefold.com\/lisa\/2007\/11\/14\/sideways-report-sql-for-vfp-a-reporting-convergence-chapter\/","title":{"rendered":"Sideways Report SQL for VFP: A Reporting Convergence Chapter"},"content":{"rendered":"<p>\nA couple of days I wrote about <a href=\"\/lisa\/2007\/11\/09\/SQL-for-Sideways-Layout-Reports\/\" title=\"Sideways Reporting in SQL RS - blog post\">how to &quot;snake columns across&quot; in SQL Server for use with Reporting Services<\/a>.&nbsp;\n<\/p>\n<p>\nAs luck would have it, Ludek.Coufal wrote again this morning asking a completely different question he faces in the VFP reporting environment &#8212;&nbsp;but it can be solved exactly the same way.\n<\/p>\n<p>\nHere&#39;s the deal: Ludek wants to show images &quot;two-up&quot;.This is the &quot;proofsheet&quot; variant of the classic snaking column problem that I mentioned when I wrote earlier.&nbsp; He has stretching memo fields to go with those images.&nbsp; But the VFP Report Engine doesn&#39;t allow variable band height when you decide that columns should flow &quot;across and then down&quot;.&nbsp; Its algorithms aren&#39;t good enough to figure out what to do when the memo fields that are supposed to stretch next to each other have wildly different lengths &#8212; especially when, as is often the case, some records&#39; text might flow through multiple pages.\n<\/p>\n<p>\nSo&#8230; how&nbsp;should Ludek kludge this in the Report Designer? Or&#8230; should he tell his users they can&#39;t have this layout?\n<\/p>\n<p>\nNot a bit of it. This is simply another case of the best tool for the job.&nbsp; In this case, as in SQL Reporting Services, the best tool for the job is not the report layout. It&#39;s your SQL smarts.\n<\/p>\n<p>\nTake another look at the query I wrote for SQL Server in that other post.&nbsp; Here is a version for VFP &#8212; designed with just two columns, for Ludek&#39;s scenario, but obviously extensible to however many columns you need &#8212; it is not, however, guaranteed to work terribly well with huge tables.&nbsp; I have written this example so you can use it with any table:\n<\/p>\n<p><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\"><\/p>\n<p class=\"code\">\nCLOSE ALL<br \/>\nUSE <font face=\"Lucida Sans Typewriter\">? <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">ALIAS <\/font><font face=\"Lucida Sans Typewriter\">YourTable <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">SHARED<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\">YourField = <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">FIELD<\/font><font face=\"Lucida Sans Typewriter\">(1)<br \/>\n<\/font><br \/>\nSELECT <font face=\"Lucida Sans Typewriter\">A.<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RecNo<\/font><font face=\"Lucida Sans Typewriter\">, B.Col1, B.YourMemoCol1, C.Col2, C.YourMemoCol2 ;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">&nbsp;&nbsp; FROM <\/font><font face=\"Lucida Sans Typewriter\">(<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">SELECT <\/font><font face=\"Lucida Sans Typewriter\">(YourField), <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RECNO<\/font><font face=\"Lucida Sans Typewriter\">() <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">AS RecNo FROM <\/font><font face=\"Lucida Sans Typewriter\">YourTable) A ;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">LEFT JOIN <\/font><font face=\"Lucida Sans Typewriter\">;<br \/>\n&nbsp;&nbsp; (<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">SELECT <\/font><font face=\"Lucida Sans Typewriter\">&amp;YourField <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">As <\/font><font face=\"Lucida Sans Typewriter\">Col1, ;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">&nbsp;&nbsp;&nbsp; PADR<\/font><font face=\"Lucida Sans Typewriter\">(&quot;The Memo&quot; + <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">TRANSFORM<\/font><font face=\"Lucida Sans Typewriter\">(<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RECNO<\/font><font face=\"Lucida Sans Typewriter\">()),20) <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">AS <\/font><font face=\"Lucida Sans Typewriter\">YourMemoCol1, ;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">&nbsp;&nbsp;&nbsp; RECNO<\/font><font face=\"Lucida Sans Typewriter\">() <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">AS RecNo <\/font><font face=\"Lucida Sans Typewriter\">;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">FROM <\/font><font face=\"Lucida Sans Typewriter\">YourTable) B ;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">&nbsp;&nbsp; ON <\/font><font face=\"Lucida Sans Typewriter\">B.<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RecNo <\/font><font face=\"Lucida Sans Typewriter\">% 2 = 1 AND A.<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RecNo <\/font><font face=\"Lucida Sans Typewriter\">= <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">CEILING<\/font><font face=\"Lucida Sans Typewriter\">(B.<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RecNo<\/font><font face=\"Lucida Sans Typewriter\">\/2) ;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">LEFT JOIN <\/font><font face=\"Lucida Sans Typewriter\">;<br \/>\n&nbsp;&nbsp; (<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">SELECT <\/font><font face=\"Lucida Sans Typewriter\">&amp;YourField <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">As <\/font><font face=\"Lucida Sans Typewriter\">Col2, ;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">&nbsp;&nbsp;&nbsp; PADR<\/font><font face=\"Lucida Sans Typewriter\">(&quot;The Memo&quot; + <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">TRANSFORM<\/font><font face=\"Lucida Sans Typewriter\">(<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RECNO<\/font><font face=\"Lucida Sans Typewriter\">()),20) <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">AS <\/font><font face=\"Lucida Sans Typewriter\">YourMemoCol2, ;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">&nbsp;&nbsp;&nbsp; RECNO<\/font><font face=\"Lucida Sans Typewriter\">() <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">AS RecNo <\/font><font face=\"Lucida Sans Typewriter\">;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">FROM <\/font><font face=\"Lucida Sans Typewriter\">YourTable) C ;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">&nbsp;&nbsp; ON <\/font><font face=\"Lucida Sans Typewriter\">C.<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RecNo <\/font><font face=\"Lucida Sans Typewriter\">% 2 = 0 AND A.<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RecNo <\/font><font face=\"Lucida Sans Typewriter\">= <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">CEILING<\/font><font face=\"Lucida Sans Typewriter\">(C.<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RecNo<\/font><font face=\"Lucida Sans Typewriter\">\/2) ;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">WHERE <\/font><font face=\"Lucida Sans Typewriter\">(A.<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RecNo <\/font><font face=\"Lucida Sans Typewriter\">&lt;= (<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">SELECT CEILING<\/font><font face=\"Lucida Sans Typewriter\">(<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">COUNT<\/font><font face=\"Lucida Sans Typewriter\">(*)\/2 ) <\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">FROM <\/font><font face=\"Lucida Sans Typewriter\">YourTable)) ;<br \/>\n<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">ORDER BY <\/font><font face=\"Lucida Sans Typewriter\">A.<\/font><font face=\"Lucida Sans Typewriter\" color=\"#0000ff\">RecNo <\/font><font face=\"Lucida Sans Typewriter\" color=\"#008000\">&amp;&amp; or whatever you want <\/font>\n<\/p>\n<p><\/font><\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\nThe result of this&nbsp;query, using the Northwind Customers table, looks like this:\n<\/p>\n<pre>\nRecno&nbsp;&nbsp; Col1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Yourmemocol1&nbsp;&nbsp;&nbsp;&nbsp; Col2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Yourmemocol2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \n1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ALFKI&nbsp;&nbsp;&nbsp;&nbsp; The Memo1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ANATR&nbsp;&nbsp;&nbsp;&nbsp; The Memo2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \n2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ANTON&nbsp;&nbsp;&nbsp;&nbsp; The Memo3&nbsp;&nbsp;&nbsp;&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bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \n<\/pre>\n<p>\nYou can easily see how this solves the &quot;two-up&quot; issue.&nbsp;Ludek just needs a regular detail band, without multiple columns, with a two layout control sets in the band.&nbsp;\n<\/p>\n<p>\nThe layout elements on the left side of the band reference a different set of columns in the row than the elements on the right side of the band.&nbsp; The detail band can stretch just fine, and pays attention to the longer (or longest, with more than two-up) memo for its height.&nbsp; Everybody&#39;s happy.\n<\/p>\n<p>\nAs I said above, this won&#39;t work wonderfully with large tables, but there are probably a lot of ways you can optimize it in VFP so it does. I basically did a straight port from my SQL Server version, swapping ROW_NUMBER() for RECNO() functionality.\n<\/p>\n<p>\nAnd that is pretty much all she wrote on this one&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple of days I wrote about how to &quot;snake columns across&quot; in SQL Server for use with Reporting Services.&nbsp; As luck would have it, Ludek.Coufal wrote again this morning asking a completely different question he faces in the VFP reporting environment &#8212;&nbsp;but it can be solved exactly the same way. Here&#39;s the deal: Ludek<a class=\"more-link\" href=\"https:\/\/spacefold.com\/lisa\/2007\/11\/14\/sideways-report-sql-for-vfp-a-reporting-convergence-chapter\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6,9],"tags":[],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-reporting","category-sql-server","category-visual-foxpro"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}