<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SOS Query Library</title>
	<atom:link href="http://www.sosoft.com/queries/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sosoft.com/queries</link>
	<description>Getting the most from your SOS database</description>
	<lastBuildDate>Mon, 14 May 2012 16:02:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Service Count, Total Charges, and Applied Payments by Provider and Patient Category</title>
		<link>http://www.sosoft.com/queries/2012/05/14/service-count-total-charges-and-applied-payments-by-provider-and-patient-category/</link>
		<comments>http://www.sosoft.com/queries/2012/05/14/service-count-total-charges-and-applied-payments-by-provider-and-patient-category/#comments</comments>
		<pubDate>Mon, 14 May 2012 15:59:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All Queries]]></category>
		<category><![CDATA[Payment Analysis]]></category>
		<category><![CDATA[Queries - Accounting]]></category>
		<category><![CDATA[Queries - Providers]]></category>

		<guid isPermaLink="false">http://www.sosoft.com/queries/?p=599</guid>
		<description><![CDATA[<p>We would like to know the income generated for services based on provider and patient category.</p> <p>The following query shows these results in a &#8220;ROLLUP&#8221; grid, displaying both detail down to the service code level as well as subtotals and grand totals. When you run the query and examine the results, you should interpret &#8220;NULL&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>We would like to know the income generated for services based on provider and patient category.</p>
<p><em>The following query shows these results in a &#8220;ROLLUP&#8221; grid, displaying both detail down to the service code level as well as subtotals and grand totals. When you run the query and examine the results, you should interpret &#8220;NULL&#8221; in the Provider, PtCategory, and Service columns as meaning &#8220;ALL&#8221;. For example, the row that shows NULL in all three of these columns is showing the totals for ALL providers, ALL ptcategories, and ALL service codes &#8212; in other words, the grand totals. A row that shows a specific provider and a specific category, but NULL in the Service column provides the subtotal of all service codes for the indicated provider and category. You could limit the result set by replacing the wildcard percent sign in the WHERE clause with a specific provider code and/or patient category code if you like.</em></p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Select All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
   <span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">.</span>provfname <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' '</span><span style="color: #66cc66;">+</span>a<span style="color: #66cc66;">.</span>provlname<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Provider&quot;</span><span style="color: #66cc66;">,</span>
   c<span style="color: #66cc66;">.</span>categcode <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;PtCategory&quot;</span><span style="color: #66cc66;">,</span>
   a<span style="color: #66cc66;">.</span>srvcode <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Service&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DISTINCT</span> jnum<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Srv Count&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">.</span>chgsplamt<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;TotalCharges&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>crsplamt<span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> rv_creditsplits
   <span style="color: #993333; font-weight: bold;">WHERE</span>  chgsplnum <span style="color: #66cc66;">=</span> a<span style="color: #66cc66;">.</span>chgsplnum <span style="color: #993333; font-weight: bold;">AND</span> credtype <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'CASH'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'CHECK'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'CHARGE'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;TotalPayments&quot;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
   rv_charges a
   <span style="color: #993333; font-weight: bold;">JOIN</span> patients b <span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> b<span style="color: #66cc66;">.</span>ptnum
   <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> ptcategs c <span style="color: #993333; font-weight: bold;">ON</span> b<span style="color: #66cc66;">.</span>ptcategnum <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>ptcategnum
<span style="color: #993333; font-weight: bold;">WHERE</span>
   a<span style="color: #66cc66;">.</span>trandate <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #ff0000;">'1980-01-01'</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #ff0000;">'2008-12-31'</span>
   <span style="color: #993333; font-weight: bold;">AND</span> a<span style="color: #66cc66;">.</span>provcode <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%'</span>
   <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #ff0000;">&quot;PtCategory&quot;</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%'</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span>
  ROLLUP <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Provider&quot;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">&quot;PtCategory&quot;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">&quot;Service&quot;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.sosoft.com/queries/2012/05/14/service-count-total-charges-and-applied-payments-by-provider-and-patient-category/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Appointment Count by Patient Category and Appointment Type</title>
		<link>http://www.sosoft.com/queries/2012/04/24/appointment-count-by-patient-category-and-appointment-type/</link>
		<comments>http://www.sosoft.com/queries/2012/04/24/appointment-count-by-patient-category-and-appointment-type/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 20:01:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All Queries]]></category>
		<category><![CDATA[Queries - Appointments]]></category>
		<category><![CDATA[Queries - Patients]]></category>

		<guid isPermaLink="false">http://www.sosoft.com/queries/?p=594</guid>
		<description><![CDATA[<p>We need a report that provides total number of a particular type of appointment by pt category for a specified period.</p> <p>Be sure to adjust the date range in the WHERE clause for your desired period.</p> <p>This query uses the GROUP BY ROLLUP (  ) statement to give grand and subtotals as well as the [...]]]></description>
			<content:encoded><![CDATA[<p><em>We need a report that provides total number of a particular type of appointment by pt category for a specified period.</em></p>
<p>Be sure to adjust the date range in the WHERE clause for your desired period.</p>
<p>This query uses the GROUP BY ROLLUP (  ) statement to give grand and subtotals as well as the results for each specific patient category, provider type, and service code combination. Wherever you see NULL in the result set, interpret as &#8220;ALL&#8221;.</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Select All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
  <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>d<span style="color: #66cc66;">.</span>categcode<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'None'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;PtCategory&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>f<span style="color: #66cc66;">.</span>ApptType<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'None'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;ApptType&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DISTINCT</span> a<span style="color: #66cc66;">.</span>detailnum<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> ApptCount
<span style="color: #993333; font-weight: bold;">FROM</span>
  appt_d a
  <span style="color: #993333; font-weight: bold;">JOIN</span> patients c <span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>ptnum
  <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> ptcategs d <span style="color: #993333; font-weight: bold;">ON</span> c<span style="color: #66cc66;">.</span>ptcategnum <span style="color: #66cc66;">=</span> d<span style="color: #66cc66;">.</span>ptcategnum 
  <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> appttypes f <span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span>appttypenum <span style="color: #66cc66;">=</span> f<span style="color: #66cc66;">.</span>appttypenum
<span style="color: #993333; font-weight: bold;">WHERE</span> 
  a<span style="color: #66cc66;">.</span>adate <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #ff0000;">'2012-01-01'</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #ff0000;">'2012-12-31'</span>
  <span style="color: #993333; font-weight: bold;">AND</span> c<span style="color: #66cc66;">.</span>licnum <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">101</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> ROLLUP <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;PtCategory&quot;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">&quot;ApptType&quot;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.sosoft.com/queries/2012/04/24/appointment-count-by-patient-category-and-appointment-type/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Service Count and Units By Patient Category, Provider Type, and Service Code</title>
		<link>http://www.sosoft.com/queries/2012/04/24/service-count-and-units-by-patient-category-provider-type-and-service-code/</link>
		<comments>http://www.sosoft.com/queries/2012/04/24/service-count-and-units-by-patient-category-provider-type-and-service-code/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 19:58:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All Queries]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Queries - Patients]]></category>
		<category><![CDATA[Queries - Providers]]></category>

		<guid isPermaLink="false">http://www.sosoft.com/queries/?p=592</guid>
		<description><![CDATA[<p>We need a report that provides units provided/charges for a specified patient category, broken down by provider type and service code for a specified date range from both active and inactive clients in dataset 101.</p> <p>Be sure to adjust the date range in the WHERE clause for your desired period.</p> <p>This query uses the GROUP BY [...]]]></description>
			<content:encoded><![CDATA[<p><em>We need a report that provides units provided/charges for a specified patient category, broken down by provider type and service code for a specified date range from both active and inactive clients in dataset 101.</em></p>
<p>Be sure to adjust the date range in the WHERE clause for your desired period.</p>
<p>This query uses the GROUP BY ROLLUP (  ) statement to give grand and subtotals as well as the results for each specific patient category, provider type, and service code combination. Wherever you see NULL in the result set, interpret as &#8220;ALL&#8221;.</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Select All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
  <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>d<span style="color: #66cc66;">.</span>categcode<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'None'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;PtCategory&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>f<span style="color: #66cc66;">.</span>provtypecode<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'None'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;ProvType&quot;</span><span style="color: #66cc66;">,</span>
  g<span style="color: #66cc66;">.</span>srvcode <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;ServiceCode&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DISTINCT</span> b<span style="color: #66cc66;">.</span>jnum<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> ServiceCount<span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">.</span>units<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TotalUnits
<span style="color: #993333; font-weight: bold;">FROM</span>
  journal a
  <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges b <span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span>jnum <span style="color: #66cc66;">=</span> b<span style="color: #66cc66;">.</span>jnum
  <span style="color: #993333; font-weight: bold;">JOIN</span> patients c <span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>ptnum
  <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> ptcategs d <span style="color: #993333; font-weight: bold;">ON</span> c<span style="color: #66cc66;">.</span>ptcategnum <span style="color: #66cc66;">=</span> d<span style="color: #66cc66;">.</span>ptcategnum
  <span style="color: #993333; font-weight: bold;">JOIN</span> providers e <span style="color: #993333; font-weight: bold;">ON</span> b<span style="color: #66cc66;">.</span>providernum <span style="color: #66cc66;">=</span> e<span style="color: #66cc66;">.</span>providernum
  <span style="color: #993333; font-weight: bold;">JOIN</span> services g <span style="color: #993333; font-weight: bold;">ON</span> b<span style="color: #66cc66;">.</span>servicenum <span style="color: #66cc66;">=</span> g<span style="color: #66cc66;">.</span>servicenum
  <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> provtype f <span style="color: #993333; font-weight: bold;">ON</span> e<span style="color: #66cc66;">.</span>provtypenum <span style="color: #66cc66;">=</span> f<span style="color: #66cc66;">.</span>provtypenum
<span style="color: #993333; font-weight: bold;">WHERE</span>
  a<span style="color: #66cc66;">.</span>trandate <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #ff0000;">'2012-01-01'</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #ff0000;">'2012-12-31'</span>
  <span style="color: #993333; font-weight: bold;">AND</span> a<span style="color: #66cc66;">.</span>amount <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span>
  <span style="color: #993333; font-weight: bold;">AND</span> c<span style="color: #66cc66;">.</span>licnum <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">101</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> ROLLUP <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;PtCategory&quot;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">&quot;ProvType&quot;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">&quot;ServiceCode&quot;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.sosoft.com/queries/2012/04/24/service-count-and-units-by-patient-category-provider-type-and-service-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Count of Intakes for Past 365 Days With Specified Dx</title>
		<link>http://www.sosoft.com/queries/2012/04/17/count-of-intakes-for-past-365-days-with-specified-dx/</link>
		<comments>http://www.sosoft.com/queries/2012/04/17/count-of-intakes-for-past-365-days-with-specified-dx/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 21:18:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All Queries]]></category>
		<category><![CDATA[Queries - Patients]]></category>
		<category><![CDATA[Queries - Providers]]></category>

		<guid isPermaLink="false">http://www.sosoft.com/queries/?p=587</guid>
		<description><![CDATA[<p>We need the total number of new (the past 365 days) intakes that were given a primary or secondary diagnosis of 304.4, including sub-diagnoses. In addition to the grand total, we also would like a breakdown by provider.</p> <p>The following query demonstrates some simple date arithmetic in the WHERE clause to provide a dynamic calculation [...]]]></description>
			<content:encoded><![CDATA[<p><em>We need the total number of new (the past 365 days) intakes that were given a primary or secondary diagnosis of 304.4, including sub-diagnoses. In addition to the grand total, we also would like a breakdown by provider.</em></p>
<p>The following query demonstrates some simple date arithmetic in the WHERE clause to provide a dynamic calculation of the date 365 days ago. In addition, we are using the GROUP BY ROLLUP ( &#8230; ) structure to get both the grand total and the subtotals in the same result set. When you run the query you will see a top row where NULL appears in the provider and provcode columns. In this context, whereever you see NULL, it actually should be interpreted as &#8220;all&#8221;. The first row then shows the number of intakes for &#8220;all providers&#8221; and &#8220;all provcodes,&#8221; in other words, the grand total.</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Select All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
  <span style="color: #993333; font-weight: bold;">UPPER</span><span style="color: #66cc66;">&#40;</span>provlname<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">', '</span> <span style="color: #66cc66;">+</span> provfname <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Provider&quot;</span><span style="color: #66cc66;">,</span>provcode<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DISTINCT</span> pt<span style="color: #66cc66;">.</span>ptnum<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;N&quot;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
  patients pt
  <span style="color: #993333; font-weight: bold;">JOIN</span> ptcsu csu <span style="color: #993333; font-weight: bold;">ON</span> pt<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> csu<span style="color: #66cc66;">.</span>ptnum
  <span style="color: #993333; font-weight: bold;">JOIN</span> ptcsudx ptdx <span style="color: #993333; font-weight: bold;">ON</span> csu<span style="color: #66cc66;">.</span>ptcsunum <span style="color: #66cc66;">=</span> ptdx<span style="color: #66cc66;">.</span>ptcsunum
  <span style="color: #993333; font-weight: bold;">JOIN</span> providers prv <span style="color: #993333; font-weight: bold;">ON</span> pt<span style="color: #66cc66;">.</span>providernum <span style="color: #66cc66;">=</span> prv<span style="color: #66cc66;">.</span>providernum
<span style="color: #993333; font-weight: bold;">WHERE</span>
  <span style="color: #66cc66;">&#40;</span>pt<span style="color: #66cc66;">.</span>intakedate <span style="color: #66cc66;">&gt;=</span> <span style="color: #66cc66;">&#40;</span>TODAY<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #66cc66;">&#40;</span>dxcode1 <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'304.4%'</span> <span style="color: #993333; font-weight: bold;">OR</span> dxcode2 <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'304.4%'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span>
  ROLLUP <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Provider&quot;</span><span style="color: #66cc66;">,</span>provcode<span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.sosoft.com/queries/2012/04/17/count-of-intakes-for-past-365-days-with-specified-dx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Balance Breakdown By Patient On Specified Date</title>
		<link>http://www.sosoft.com/queries/2012/04/11/balance-breakdown-by-patient-on-specified-date/</link>
		<comments>http://www.sosoft.com/queries/2012/04/11/balance-breakdown-by-patient-on-specified-date/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 17:02:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All Queries]]></category>
		<category><![CDATA[Billing Analysis]]></category>
		<category><![CDATA[Payment Analysis]]></category>
		<category><![CDATA[Queries - Accounting]]></category>
		<category><![CDATA[Queries - Insurance]]></category>
		<category><![CDATA[Queries - Patients]]></category>

		<guid isPermaLink="false">http://www.sosoft.com/queries/?p=581</guid>
		<description><![CDATA[<p> Our auditors have requested a report of outstanding balances per client, as of Dec 31, 2011, separated by liability (Medicare, Medicaid, private insurance and self-pay). Insurance type is specified by &#8220;Coverage Type&#8221; on the Additional tab of the Insurance Carrie/Plan. We want to report patients in either the Active or Inactive lists, as long as [...]]]></description>
			<content:encoded><![CDATA[<p><em> Our auditors have requested a report of outstanding balances per client, as of Dec 31, 2011, separated by liability (Medicare, Medicaid, private insurance and self-pay). Insurance type is specified by &#8220;Coverage Type&#8221; on the Additional tab of the Insurance Carrie/Plan. We want to report patients in either the Active or Inactive lists, as long as they have a balance of some kind at the end of 2011.</em></p>
<p>Because we are looking for balances on a previous date, we have to tally up all the charges and payments on or before that date, then subtract the latter from the former to find the balance. To do that will require a bunch of embedded subqueries as you can see in the query below. If you want to run the query for a different date, be sure to replace ALL the instances of &#8217;2011-12-31&#8242;!</p>
<p>The output specified in this example will go to an HTML format file called AUDIT2011.HTML located in the C:\SOS folder. You can output the results to screen for inspection before outputting to file by inserting two dashes or slashes at the beginning of the last line. Just remove those characters when you are ready to generate the file. The benefit of outputting in HTML format is that you can view the results in a web browser, or open the file with Excel for additional massaging.</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Select All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
   a<span style="color: #66cc66;">.</span>lastname<span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>firstname<span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Account ID&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #808080; font-style: italic;">-- Medicare</span>
   <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>chgsplamt<span style="color: #66cc66;">&#41;</span> 
   <span style="color: #993333; font-weight: bold;">FROM</span> jchgsplits chs <span style="color: #993333; font-weight: bold;">JOIN</span> ptpayors ptp <span style="color: #993333; font-weight: bold;">ON</span> chs<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #66cc66;">=</span> ptp<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #993333; font-weight: bold;">JOIN</span> carriers car <span style="color: #993333; font-weight: bold;">ON</span> ptp<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> car<span style="color: #66cc66;">.</span>payornum
   <span style="color: #993333; font-weight: bold;">WHERE</span> chs<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> a<span style="color: #66cc66;">.</span>ptnum <span style="color: #993333; font-weight: bold;">AND</span> car<span style="color: #66cc66;">.</span>coverage <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'C'</span> <span style="color: #993333; font-weight: bold;">AND</span> chs<span style="color: #66cc66;">.</span>chgspldate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Medicare Charges&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>crsplamt<span style="color: #66cc66;">&#41;</span> 
   <span style="color: #993333; font-weight: bold;">FROM</span> jcrsplits crs 
     <span style="color: #993333; font-weight: bold;">JOIN</span> jchgsplits chs <span style="color: #993333; font-weight: bold;">ON</span> crs<span style="color: #66cc66;">.</span>chgsplnum <span style="color: #66cc66;">=</span> chs<span style="color: #66cc66;">.</span>chgsplnum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> ptpayors ptp <span style="color: #993333; font-weight: bold;">ON</span> chs<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #66cc66;">=</span> ptp<span style="color: #66cc66;">.</span>ptpayornum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> carriers car <span style="color: #993333; font-weight: bold;">ON</span> ptp<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> car<span style="color: #66cc66;">.</span>payornum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> jcredits cre <span style="color: #993333; font-weight: bold;">ON</span> crs<span style="color: #66cc66;">.</span>jnum <span style="color: #66cc66;">=</span> cre<span style="color: #66cc66;">.</span>jnum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> journal jou <span style="color: #993333; font-weight: bold;">ON</span> cre<span style="color: #66cc66;">.</span>jnum <span style="color: #66cc66;">=</span> jou<span style="color: #66cc66;">.</span>jnum
   <span style="color: #993333; font-weight: bold;">WHERE</span> chs<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> a<span style="color: #66cc66;">.</span>ptnum 
     <span style="color: #993333; font-weight: bold;">AND</span> car<span style="color: #66cc66;">.</span>coverage <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'C'</span> 
     <span style="color: #993333; font-weight: bold;">AND</span> chs<span style="color: #66cc66;">.</span>chgspldate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span> 
     <span style="color: #993333; font-weight: bold;">AND</span> jou<span style="color: #66cc66;">.</span>trandate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Medicare Credits&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Medicare Charges&quot;</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000;">&quot;Medicare Credits&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Medicare Balance&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #808080; font-style: italic;">-- Medicaid</span>
   <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>chgsplamt<span style="color: #66cc66;">&#41;</span> 
   <span style="color: #993333; font-weight: bold;">FROM</span> jchgsplits chs <span style="color: #993333; font-weight: bold;">JOIN</span> ptpayors ptp <span style="color: #993333; font-weight: bold;">ON</span> chs<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #66cc66;">=</span> ptp<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #993333; font-weight: bold;">JOIN</span> carriers car <span style="color: #993333; font-weight: bold;">ON</span> ptp<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> car<span style="color: #66cc66;">.</span>payornum
   <span style="color: #993333; font-weight: bold;">WHERE</span> chs<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> a<span style="color: #66cc66;">.</span>ptnum <span style="color: #993333; font-weight: bold;">AND</span> car<span style="color: #66cc66;">.</span>coverage <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'D'</span> <span style="color: #993333; font-weight: bold;">AND</span> chs<span style="color: #66cc66;">.</span>chgspldate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Medicaid Charges&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>crsplamt<span style="color: #66cc66;">&#41;</span> 
   <span style="color: #993333; font-weight: bold;">FROM</span> jcrsplits crs 
     <span style="color: #993333; font-weight: bold;">JOIN</span> jchgsplits chs <span style="color: #993333; font-weight: bold;">ON</span> crs<span style="color: #66cc66;">.</span>chgsplnum <span style="color: #66cc66;">=</span> chs<span style="color: #66cc66;">.</span>chgsplnum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> ptpayors ptp <span style="color: #993333; font-weight: bold;">ON</span> chs<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #66cc66;">=</span> ptp<span style="color: #66cc66;">.</span>ptpayornum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> carriers car <span style="color: #993333; font-weight: bold;">ON</span> ptp<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> car<span style="color: #66cc66;">.</span>payornum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> jcredits cre <span style="color: #993333; font-weight: bold;">ON</span> crs<span style="color: #66cc66;">.</span>jnum <span style="color: #66cc66;">=</span> cre<span style="color: #66cc66;">.</span>jnum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> journal jou <span style="color: #993333; font-weight: bold;">ON</span> cre<span style="color: #66cc66;">.</span>jnum <span style="color: #66cc66;">=</span> jou<span style="color: #66cc66;">.</span>jnum
   <span style="color: #993333; font-weight: bold;">WHERE</span> chs<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> a<span style="color: #66cc66;">.</span>ptnum 
     <span style="color: #993333; font-weight: bold;">AND</span> car<span style="color: #66cc66;">.</span>coverage <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'D'</span> 
     <span style="color: #993333; font-weight: bold;">AND</span> chs<span style="color: #66cc66;">.</span>chgspldate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span> 
     <span style="color: #993333; font-weight: bold;">AND</span> jou<span style="color: #66cc66;">.</span>trandate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Medicaid Credits&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Medicaid Charges&quot;</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000;">&quot;Medicaid Credits&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Medicaid Balance&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #808080; font-style: italic;">-- Private Ins </span>
   <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>chgsplamt<span style="color: #66cc66;">&#41;</span> 
   <span style="color: #993333; font-weight: bold;">FROM</span> jchgsplits chs <span style="color: #993333; font-weight: bold;">JOIN</span> ptpayors ptp <span style="color: #993333; font-weight: bold;">ON</span> chs<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #66cc66;">=</span> ptp<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #993333; font-weight: bold;">JOIN</span> carriers car <span style="color: #993333; font-weight: bold;">ON</span> ptp<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> car<span style="color: #66cc66;">.</span>payornum
   <span style="color: #993333; font-weight: bold;">WHERE</span> chs<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> a<span style="color: #66cc66;">.</span>ptnum <span style="color: #993333; font-weight: bold;">AND</span> car<span style="color: #66cc66;">.</span>coverage <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'C'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'D'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> chs<span style="color: #66cc66;">.</span>chgspldate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Private Ins Charges&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>crsplamt<span style="color: #66cc66;">&#41;</span> 
   <span style="color: #993333; font-weight: bold;">FROM</span> jcrsplits crs 
     <span style="color: #993333; font-weight: bold;">JOIN</span> jchgsplits chs <span style="color: #993333; font-weight: bold;">ON</span> crs<span style="color: #66cc66;">.</span>chgsplnum <span style="color: #66cc66;">=</span> chs<span style="color: #66cc66;">.</span>chgsplnum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> ptpayors ptp <span style="color: #993333; font-weight: bold;">ON</span> chs<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #66cc66;">=</span> ptp<span style="color: #66cc66;">.</span>ptpayornum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> carriers car <span style="color: #993333; font-weight: bold;">ON</span> ptp<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> car<span style="color: #66cc66;">.</span>payornum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> jcredits cre <span style="color: #993333; font-weight: bold;">ON</span> crs<span style="color: #66cc66;">.</span>jnum <span style="color: #66cc66;">=</span> cre<span style="color: #66cc66;">.</span>jnum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> journal jou <span style="color: #993333; font-weight: bold;">ON</span> cre<span style="color: #66cc66;">.</span>jnum <span style="color: #66cc66;">=</span> jou<span style="color: #66cc66;">.</span>jnum
   <span style="color: #993333; font-weight: bold;">WHERE</span> chs<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> a<span style="color: #66cc66;">.</span>ptnum 
     <span style="color: #993333; font-weight: bold;">AND</span> car<span style="color: #66cc66;">.</span>coverage <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'C'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'D'</span><span style="color: #66cc66;">&#41;</span> 
     <span style="color: #993333; font-weight: bold;">AND</span> chs<span style="color: #66cc66;">.</span>chgspldate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span> 
     <span style="color: #993333; font-weight: bold;">AND</span> jou<span style="color: #66cc66;">.</span>trandate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Private Ins Credits&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Private Ins Charges&quot;</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000;">&quot;Private Ins Credits&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Private Ins Balance&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #808080; font-style: italic;">-- Self-Pay</span>
   <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>chgsplamt<span style="color: #66cc66;">&#41;</span> 
   <span style="color: #993333; font-weight: bold;">FROM</span> jchgsplits chs <span style="color: #993333; font-weight: bold;">JOIN</span> ptpayors ptp <span style="color: #993333; font-weight: bold;">ON</span> chs<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #66cc66;">=</span> ptp<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #993333; font-weight: bold;">JOIN</span> payors pay <span style="color: #993333; font-weight: bold;">ON</span> ptp<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> pay<span style="color: #66cc66;">.</span>payornum
   <span style="color: #993333; font-weight: bold;">WHERE</span> chs<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> a<span style="color: #66cc66;">.</span>ptnum <span style="color: #993333; font-weight: bold;">AND</span> pay<span style="color: #66cc66;">.</span>payortype <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'P'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'O'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> chs<span style="color: #66cc66;">.</span>chgspldate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Self-Pay Charges&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>crsplamt<span style="color: #66cc66;">&#41;</span> 
   <span style="color: #993333; font-weight: bold;">FROM</span> jcrsplits crs 
     <span style="color: #993333; font-weight: bold;">JOIN</span> jchgsplits chs <span style="color: #993333; font-weight: bold;">ON</span> crs<span style="color: #66cc66;">.</span>chgsplnum <span style="color: #66cc66;">=</span> chs<span style="color: #66cc66;">.</span>chgsplnum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> ptpayors ptp <span style="color: #993333; font-weight: bold;">ON</span> chs<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #66cc66;">=</span> ptp<span style="color: #66cc66;">.</span>ptpayornum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> payors pay <span style="color: #993333; font-weight: bold;">ON</span> ptp<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> pay<span style="color: #66cc66;">.</span>payornum
     <span style="color: #993333; font-weight: bold;">JOIN</span> jcredits cre <span style="color: #993333; font-weight: bold;">ON</span> crs<span style="color: #66cc66;">.</span>jnum <span style="color: #66cc66;">=</span> cre<span style="color: #66cc66;">.</span>jnum 
     <span style="color: #993333; font-weight: bold;">JOIN</span> journal jou <span style="color: #993333; font-weight: bold;">ON</span> cre<span style="color: #66cc66;">.</span>jnum <span style="color: #66cc66;">=</span> jou<span style="color: #66cc66;">.</span>jnum
   <span style="color: #993333; font-weight: bold;">WHERE</span> chs<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> a<span style="color: #66cc66;">.</span>ptnum 
     <span style="color: #993333; font-weight: bold;">AND</span> pay<span style="color: #66cc66;">.</span>payortype <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'P'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'O'</span><span style="color: #66cc66;">&#41;</span> 
     <span style="color: #993333; font-weight: bold;">AND</span> chs<span style="color: #66cc66;">.</span>chgspldate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span> 
     <span style="color: #993333; font-weight: bold;">AND</span> jou<span style="color: #66cc66;">.</span>trandate <span style="color: #66cc66;">&lt;=</span> <span style="color: #ff0000;">'2011-12-31'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Self-Pay Credits&quot;</span><span style="color: #66cc66;">,</span>
   <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Self-Pay Charges&quot;</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000;">&quot;Self-Pay Credits&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Self-Pay Balance&quot;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">FROM</span> 
  patients a  
<span style="color: #993333; font-weight: bold;">WHERE</span>
  <span style="color: #ff0000;">&quot;Medicare Balance&quot;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #cc66cc;">0</span>
  <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #ff0000;">&quot;Medicaid Balance&quot;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #cc66cc;">0</span>
  <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #ff0000;">&quot;Private Ins Balance&quot;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #cc66cc;">0</span>
  <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #ff0000;">&quot;Self-Pay Balance&quot;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #cc66cc;">0</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span>
  a<span style="color: #66cc66;">.</span>lastname<span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>firstname<span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>id</pre></td></tr></table></div></div>

<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sosoft.com/queries/2012/04/11/balance-breakdown-by-patient-on-specified-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Insurance Carriers with Active Patients</title>
		<link>http://www.sosoft.com/queries/2012/03/30/insurance-carriers-with-active-patients/</link>
		<comments>http://www.sosoft.com/queries/2012/03/30/insurance-carriers-with-active-patients/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 15:55:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All Queries]]></category>
		<category><![CDATA[Queries - Insurance]]></category>
		<category><![CDATA[Queries - Patients]]></category>

		<guid isPermaLink="false">http://www.sosoft.com/queries/?p=576</guid>
		<description><![CDATA[<p>In order to clean up my list of insurance carriers in SOS I would like to list all active Insurance Carrier’s/ Plans (defined as insurances with Patients tied to them) with their Address, Phone number, and NEIC Numbers. Actually I would like this list with just the count of active patient accounts, and a second [...]]]></description>
			<content:encoded><![CDATA[<p><em>In order to clean up my list of insurance carriers in SOS I would like to list all active Insurance Carrier’s/ Plans (defined as insurances with Patients tied to them) with their Address, Phone number, and NEIC Numbers. Actually I would like this list with just the count of active patient accounts, and a second list that includes the patients linked to each carrier.</em></p>
<p>This request is a little vague in that it is not clear whether the linked patients should be restricted to active patients or not. The first query assumes that it is only carriers linked to active patients (in the Active Patient List and without a discharge date), but you can just remove the flag and dischargedate conditions in the WHERE clause to get carriers linked to any patient.</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Select All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
  c<span style="color: #66cc66;">.</span>payorname <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Ins Plan&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">.</span>ptnum<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;ActivePatientCount&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>PayorNum<span style="color: #66cc66;">,</span>
  d<span style="color: #66cc66;">.</span>companynum <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;NEIC#&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Addr1<span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Addr2<span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>City<span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>State<span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Zip<span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Phone1Desc<span style="color: #66cc66;">,</span>
  <span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">.</span>phone1area<span style="color: #66cc66;">+</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">+</span>phone1<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Phone1&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Phone2Desc<span style="color: #66cc66;">,</span>
  <span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">.</span>phone2area<span style="color: #66cc66;">+</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">+</span>phone2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Phone2&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Phone3Desc<span style="color: #66cc66;">,</span>
  <span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">.</span>phone3area<span style="color: #66cc66;">+</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">+</span>phone3<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Phone3&quot;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
  patients a
  <span style="color: #993333; font-weight: bold;">JOIN</span> ptpayors b <span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> b<span style="color: #66cc66;">.</span>ptnum
  <span style="color: #993333; font-weight: bold;">JOIN</span> payors c <span style="color: #993333; font-weight: bold;">ON</span> b<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>payornum
  <span style="color: #993333; font-weight: bold;">JOIN</span> carriers d <span style="color: #993333; font-weight: bold;">ON</span> c<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> d<span style="color: #66cc66;">.</span>payornum
<span style="color: #993333; font-weight: bold;">WHERE</span>
  a<span style="color: #66cc66;">.</span>flag <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>
  <span style="color: #993333; font-weight: bold;">AND</span> a<span style="color: #66cc66;">.</span>dischargedate <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NULL</span>
  <span style="color: #993333; font-weight: bold;">AND</span> c<span style="color: #66cc66;">.</span>payortype <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'I'</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span>
  <span style="color: #ff0000;">&quot;Ins Plan&quot;</span><span style="color: #66cc66;">,</span>c<span style="color: #66cc66;">.</span>payornum<span style="color: #66cc66;">,</span><span style="color: #ff0000;">&quot;NEIC#&quot;</span><span style="color: #66cc66;">,</span>c<span style="color: #66cc66;">.</span>Addr1<span style="color: #66cc66;">,</span> c<span style="color: #66cc66;">.</span>Addr2<span style="color: #66cc66;">,</span> c<span style="color: #66cc66;">.</span>City<span style="color: #66cc66;">,</span> c<span style="color: #66cc66;">.</span>State<span style="color: #66cc66;">,</span> c<span style="color: #66cc66;">.</span>Zip<span style="color: #66cc66;">,</span>c<span style="color: #66cc66;">.</span>Phone1Desc<span style="color: #66cc66;">,</span><span style="color: #ff0000;">&quot;Phone1&quot;</span><span style="color: #66cc66;">,</span>c<span style="color: #66cc66;">.</span>Phone2Desc<span style="color: #66cc66;">,</span><span style="color: #ff0000;">&quot;Phone2&quot;</span><span style="color: #66cc66;">,</span>c<span style="color: #66cc66;">.</span>Phone3Desc<span style="color: #66cc66;">,</span><span style="color: #ff0000;">&quot;Phone3&quot;</span>
<span style="color: #993333; font-weight: bold;">HAVING</span>
  <span style="color: #ff0000;">&quot;ActivePatientCount&quot;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span>
  c<span style="color: #66cc66;">.</span>payorname<span style="color: #66cc66;">,</span> c<span style="color: #66cc66;">.</span>payornum</pre></td></tr></table></div></div>

<p>The second query removes the COUNT function, the GROUP BY and HAVING clauses, and adds the patient names and ID&#8217;s.</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Select All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
  c<span style="color: #66cc66;">.</span>payorname <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Ins Plan&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>PayorNum<span style="color: #66cc66;">,</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">UPPER</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">.</span>lastname<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #ff0000;">', '</span><span style="color: #66cc66;">+</span>a<span style="color: #66cc66;">.</span>firstname<span style="color: #66cc66;">+</span><span style="color: #ff0000;">' / '</span><span style="color: #66cc66;">+</span>a<span style="color: #66cc66;">.</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Patient Name/ID&quot;</span><span style="color: #66cc66;">,</span>
  d<span style="color: #66cc66;">.</span>companynum <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;NEIC#&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Addr1 <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;InsAddr1&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Addr2 <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;InsAddr2&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>City <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;InsCity&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>State <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;InsState&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Zip <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;InsZip&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Phone1Desc <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;InsPhone1Desc&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">.</span>phone1area<span style="color: #66cc66;">+</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">+</span>phone1<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Phone1&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Phone2Desc <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;InsPhone2Desc&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">.</span>phone2area<span style="color: #66cc66;">+</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">+</span>phone2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Phone2&quot;</span><span style="color: #66cc66;">,</span>
  c<span style="color: #66cc66;">.</span>Phone3Desc <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;InsPhone3Desc&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">.</span>phone3area<span style="color: #66cc66;">+</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">+</span>phone3<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Phone3&quot;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
  patients a
  <span style="color: #993333; font-weight: bold;">JOIN</span> ptpayors b <span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> b<span style="color: #66cc66;">.</span>ptnum
  <span style="color: #993333; font-weight: bold;">JOIN</span> payors c <span style="color: #993333; font-weight: bold;">ON</span> b<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>payornum
  <span style="color: #993333; font-weight: bold;">JOIN</span> carriers d <span style="color: #993333; font-weight: bold;">ON</span> c<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> d<span style="color: #66cc66;">.</span>payornum
<span style="color: #993333; font-weight: bold;">WHERE</span>
  a<span style="color: #66cc66;">.</span>flag <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>
  <span style="color: #993333; font-weight: bold;">AND</span> a<span style="color: #66cc66;">.</span>dischargedate <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NULL</span>
  <span style="color: #993333; font-weight: bold;">AND</span> c<span style="color: #66cc66;">.</span>payortype <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'I'</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span>
  c<span style="color: #66cc66;">.</span>payorname<span style="color: #66cc66;">,</span> c<span style="color: #66cc66;">.</span>payornum</pre></td></tr></table></div></div>

<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sosoft.com/queries/2012/03/30/insurance-carriers-with-active-patients/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flyspeed SQL Query: How to configure your SOSDATA connection</title>
		<link>http://www.sosoft.com/queries/2012/03/15/flyspeed-sql-query-how-to-configure-your-sosdata-connection/</link>
		<comments>http://www.sosoft.com/queries/2012/03/15/flyspeed-sql-query-how-to-configure-your-sosdata-connection/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 20:43:52 +0000</pubDate>
		<dc:creator>seth</dc:creator>
				<category><![CDATA[All Queries]]></category>

		<guid isPermaLink="false">http://www.sosoft.com/queries/2012/03/15/flyspeed-sql-query-how-to-configure-your-sosdata-connection/</guid>
		<description><![CDATA[<p>Flyspeed is a general purpose query tool that is compatible with SOS&#8217;s Sybase SQL Anywhere database, as well as most other popular databases, such as Microsoft SQL Server. It provides structure that will be welcome to those who are new to SQL, as well as to those who are SQL experts.&#160; Flyspeed is free, but [...]]]></description>
			<content:encoded><![CDATA[<p>Flyspeed is a general purpose query tool that is compatible with SOS&#8217;s Sybase SQL Anywhere database, as well as most other popular databases, such as Microsoft SQL Server. It provides structure that will be welcome to those who are new to SQL, as well as to those who are SQL experts.&#160; Flyspeed is free, but if you would like to print or export the results of your queries you will have to purchase a $29 license. See <a title="http://www.activedbsoft.com/overview-querytool.html" href="http://www.activedbsoft.com/overview-querytool.html">http://www.activedbsoft.com/overview-querytool.html</a> for more details.</p>
<p>Once you have your copy of Flyspeed, just follow these steps to get started:</p>
<ol>
<li>Make sure that you have followed the instructions in <a title="http://www.sosoft.com/queries/how2010/" href="http://www.sosoft.com/queries/how2010/">http://www.sosoft.com/queries/how2010/</a> or <a title="http://www.sosoft.com/queries/how2009/" href="http://www.sosoft.com/queries/how2009/">http://www.sosoft.com/queries/how2009/</a> (depending on the version of SOS you are using). Do a simple query using the SOS-provided DBISQL utility to be sure everything is working: <u>SELECT * FROM PATIENTS</u> for example.</li>
<li>Now start up Flyspeed.</li>
<li>Select <strong>Connection</strong> &gt; <strong>New Connection</strong> from the menu at the top of the screen to launch the New Connection Wizard.
<p><a href="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML12d8e21.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SNAGHTML12d8e21" border="0" alt="SNAGHTML12d8e21" src="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML12d8e21_thumb.png" width="234" height="244" /></a>      </li>
<li>On the Database Server window, select &quot;Generic ODBC Connection&quot; as the <em>Connection Type</em>. For <em>SQL Syntax</em>, select &quot;Sybase&quot;. A third field, <em>Server version</em>, will appear. Make sure it says &quot;Sybase ASA&quot; (NOT &quot;Sybase ASE&quot;), then click <strong>Next</strong>.
<p><a href="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML15be018.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SNAGHTML15be018" border="0" alt="SNAGHTML15be018" src="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML15be018_thumb.png" width="434" height="321" /></a>      </li>
<li>On the <strong>Connection properties</strong> window, select the first option, <em>System/User DSN</em>, and type or select <u>SOSDATA</u>. If you are on a secure workstation, you can add your SOS login ID and, optionally, password so that you can connect without having to enter your credentials each time. Be sure to type your password in all UPPERCASE. If, and only if, your workstation is secure and not located in a public area, you may check the <em>Save password</em> option. Click <strong>Next</strong>.
<p><a href="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML137cc2a.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SNAGHTML137cc2a" border="0" alt="SNAGHTML137cc2a" src="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML137cc2a_thumb.png" width="437" height="323" /></a>      </li>
<li>Finally, give the connection a name, such as &quot;SOS&quot;, and click <strong>Finish</strong>. You will see your connection listed in the pane on the left. Click the little plus to the left of the connection name to expand it. You will see a folder in which you can save your queries and other folders containing all the base tables and views in the SOSDATA database. If at some point you want to query other databases you may have on your network, they can be added in a similar fashion. In the screenshot below you will see several of the other databases running here at SOS in the list.
<p><a href="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML1453baf.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SNAGHTML1453baf" border="0" alt="SNAGHTML1453baf" src="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML1453baf_thumb.png" width="297" height="288" /></a>      </li>
<li>To start working on your first query, click the <strong>New Query</strong> button in the toolbar at the top.
<p><a href="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML148d2a0.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SNAGHTML148d2a0" border="0" alt="SNAGHTML148d2a0" src="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML148d2a0_thumb.png" width="356" height="247" /></a>      </p>
</li>
<li>Next, click the <strong>Add Object</strong> button in the toolbar to select the tables, views, or both for your query. Ignore the system objects and scroll right until you see items that you recognize, starting with &quot;AdjustX&quot; (adjustment explanations) in the tables, and &quot;AGINGBYSORTCODE&quot; in the views. As soon as you select the first one, you will see your query start to take shape in the worksheet. If you add more than one object (table or view), drag from a field in one object to the appropriate field in a second object to create a JOIN to link the two. You can change the type of JOIN by right-clicking on the line that will appear between the two objects.
<p><a href="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML14e03ed.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SNAGHTML14e03ed" border="0" alt="SNAGHTML14e03ed" src="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML14e03ed_thumb.png" width="386" height="343" /></a>      </p>
<p><a href="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML154d889.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SNAGHTML154d889" border="0" alt="SNAGHTML154d889" src="http://www.sosoft.com/queries/wp-content/uploads/2012/03/SNAGHTML154d889_thumb.png" width="575" height="479" /></a>      </li>
<li>Click the checkboxes next to the columns/fields you want to output in your query, and configure your filter conditions in the middle pane of the worksheet.</li>
</ol>
<p>That should be enough to get you started. There is no way for you to damage the database, so feel free to experiment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sosoft.com/queries/2012/03/15/flyspeed-sql-query-how-to-configure-your-sosdata-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Medicaid Patients by Rendering Provider within Specified Date Range</title>
		<link>http://www.sosoft.com/queries/2012/03/08/medicaid-patients-by-rendering-provider-within-specified-date-range/</link>
		<comments>http://www.sosoft.com/queries/2012/03/08/medicaid-patients-by-rendering-provider-within-specified-date-range/#comments</comments>
		<pubDate>Thu, 08 Mar 2012 22:41:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All Queries]]></category>

		<guid isPermaLink="false">http://www.sosoft.com/queries/?p=540</guid>
		<description><![CDATA[<p>I need a report that lists Medicaid clients seen between a specific date range by rendering provider.</p> <p>The following query should deliver the goods. Because we are looking at RENDERING provider, the same patient may be listed two or more times, depending on the number of different providers seen during the specified period. Speaking of [...]]]></description>
			<content:encoded><![CDATA[<p><em>I need a report that lists Medicaid clients seen between a specific date range by rendering provider.</em></p>
<p>The following query should deliver the goods. Because we are looking at RENDERING provider, the same patient may be listed two or more times, depending on the number of different providers seen during the specified period. Speaking of period, be sure to adjust the desired date range in the first condition under WHERE.</p>
<p>Notice that the second word of the query is DISTINCT. Adding that keyword after SELECT eliminates duplicate rows in the output. Without that word, there would be a row for every matching charge in each patient&#8217;s ledger.</p>
<p>&nbsp;</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Select All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">DISTINCT</span>
  <span style="color: #66cc66;">&#40;</span>prv<span style="color: #66cc66;">.</span>provlname <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">', '</span><span style="color: #66cc66;">+</span> prv<span style="color: #66cc66;">.</span>provfname <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' ('</span> <span style="color: #66cc66;">+</span> prv<span style="color: #66cc66;">.</span>provcode <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">')'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;provider&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">UPPER</span><span style="color: #66cc66;">&#40;</span>pt<span style="color: #66cc66;">.</span>lastname<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span><span style="color: #ff0000;">', '</span><span style="color: #66cc66;">+</span> pt<span style="color: #66cc66;">.</span>firstname<span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' '</span><span style="color: #66cc66;">+</span> pt<span style="color: #66cc66;">.</span>midinit<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;ptfullname&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Acct ID: '</span><span style="color: #66cc66;">+</span> pt<span style="color: #66cc66;">.</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;acctid&quot;</span><span style="color: #66cc66;">,</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Medicaid #: '</span> <span style="color: #66cc66;">+</span> pol<span style="color: #66cc66;">.</span>insdid<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;medicaidnum&quot;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
  patients pt
  <span style="color: #993333; font-weight: bold;">JOIN</span> ptpayors ptp <span style="color: #993333; font-weight: bold;">ON</span> pt<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> ptp<span style="color: #66cc66;">.</span>ptnum
  <span style="color: #993333; font-weight: bold;">JOIN</span> carriers car <span style="color: #993333; font-weight: bold;">ON</span> ptp<span style="color: #66cc66;">.</span>payornum <span style="color: #66cc66;">=</span> car<span style="color: #66cc66;">.</span>payornum
  <span style="color: #993333; font-weight: bold;">JOIN</span> ptpolicies pol <span style="color: #993333; font-weight: bold;">ON</span> ptp<span style="color: #66cc66;">.</span>ptpayornum <span style="color: #66cc66;">=</span> pol<span style="color: #66cc66;">.</span>ptpayornum
  <span style="color: #993333; font-weight: bold;">JOIN</span> journal jou <span style="color: #993333; font-weight: bold;">ON</span> pt<span style="color: #66cc66;">.</span>ptnum <span style="color: #66cc66;">=</span> jou<span style="color: #66cc66;">.</span>ptnum
  <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges chg <span style="color: #993333; font-weight: bold;">ON</span> jou<span style="color: #66cc66;">.</span>jnum <span style="color: #66cc66;">=</span> chg<span style="color: #66cc66;">.</span>jnum
  <span style="color: #993333; font-weight: bold;">JOIN</span> providers prv <span style="color: #993333; font-weight: bold;">ON</span> chg<span style="color: #66cc66;">.</span>providernum <span style="color: #66cc66;">=</span> prv<span style="color: #66cc66;">.</span>providernum
<span style="color: #993333; font-weight: bold;">WHERE</span>
  <span style="color: #808080; font-style: italic;">-- desired date range of charge entries</span>
  jou<span style="color: #66cc66;">.</span>trandate <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #ff0000;">'2000-01-01'</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #ff0000;">'2012-3-31'</span>
  <span style="color: #808080; font-style: italic;">-- carrier is set as &quot;Medicaid&quot;</span>
  <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #66cc66;">&#40;</span>car<span style="color: #66cc66;">.</span>coverage <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'D'</span> <span style="color: #993333; font-weight: bold;">OR</span> car<span style="color: #66cc66;">.</span>insflag <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'A'</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #808080; font-style: italic;">-- the Medicaid policy was active on the date of the charge entry</span>
  <span style="color: #993333; font-weight: bold;">AND</span> jou<span style="color: #66cc66;">.</span>trandate <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>pol<span style="color: #66cc66;">.</span>active<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'1900-01-01'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>pol<span style="color: #66cc66;">.</span>inactive<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'2100-12-31'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span>
  <span style="color: #ff0000;">&quot;provider&quot;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">&quot;ptfullname&quot;</span></pre></td></tr></table></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.sosoft.com/queries/2012/03/08/medicaid-patients-by-rendering-provider-within-specified-date-range/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking for Fields that Should Be Included in Encounter Import</title>
		<link>http://www.sosoft.com/queries/2012/03/07/checking-for-fields-that-should-be-included-in-encounter-import/</link>
		<comments>http://www.sosoft.com/queries/2012/03/07/checking-for-fields-that-should-be-included-in-encounter-import/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 22:16:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All Queries]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Queries - Accounting]]></category>

		<guid isPermaLink="false">http://www.sosoft.com/queries/?p=535</guid>
		<description><![CDATA[<p>The following query generates an HTML report that indicates the field elements that should be considered for inclusion if you are planning to import encounter data from a third-party product for billing by SOS Office Manager. The previous year of charge entries are analyzed.</p> Select All Code:1 2 3 4 5 6 7 8 9 [...]]]></description>
			<content:encoded><![CDATA[<p>The following query generates an HTML report that indicates the field elements that should be considered for inclusion if you are planning to import encounter data from a third-party product for billing by SOS Office Manager. The previous year of charge entries are analyzed.</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Select All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Total Charge Count'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'CSU = U'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> csutype <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'u'</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'CSU = N'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> csutype <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'n'</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Date Range'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>startdate<span style="color: #66cc66;">,</span>trandate<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> trandate
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Units &lt;&gt; 1'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> units <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #cc66cc;">1</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Cost'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>cost<span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #cc66cc;">0</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'CPT Modifiers'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>cptmod1<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>cptmod2<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>cptmod3<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>cptmod4<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">''</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Non-default POS'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> poscodenum <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> lastpos <span style="color: #993333; font-weight: bold;">FROM</span> ptvars <span style="color: #993333; font-weight: bold;">WHERE</span> ptnum <span style="color: #66cc66;">=</span> journal<span style="color: #66cc66;">.</span>ptnum<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'FP'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>fp<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">''</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'EMG'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>emergency<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">''</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'COB'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>cob<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">''</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Box 24K'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>box24k<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">''</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Lab Charge'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>labchg<span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #cc66cc;">0</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'SortCode'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>sortcode<span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #cc66cc;">0</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Comment1'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>comment1<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">''</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Comment2'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>comment2<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">''</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Remark'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>remark<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">''</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Memo'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>memo<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">''</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'MemoHA0'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> journal <span style="color: #993333; font-weight: bold;">JOIN</span> jcharges <span style="color: #993333; font-weight: bold;">WHERE</span> trandate <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>today<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">365</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>memoisha0<span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #cc66cc;">0</span>
;
OUTPUT <span style="color: #993333; font-weight: bold;">TO</span> <span style="color: #ff0000;">'c:<span style="color: #000099; font-weight: bold;">\s</span>os<span style="color: #000099; font-weight: bold;">\C</span>hargeImportCheck.html'</span> format html
;</pre></td></tr></table></div></div>

<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sosoft.com/queries/2012/03/07/checking-for-fields-that-should-be-included-in-encounter-import/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Identifying Accounts with Unapplied &#8220;Balance Forward&#8221; Amounts</title>
		<link>http://www.sosoft.com/queries/2012/02/17/identifying-accounts-with-unapplied-balance-forward-amounts/</link>
		<comments>http://www.sosoft.com/queries/2012/02/17/identifying-accounts-with-unapplied-balance-forward-amounts/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 21:44:50 +0000</pubDate>
		<dc:creator>seth</dc:creator>
				<category><![CDATA[All Queries]]></category>

		<guid isPermaLink="false">http://www.sosoft.com/queries/?p=529</guid>
		<description><![CDATA[<p>During the conversion of data from the old DOS software to the Windows version of SOS, one option was to create a dummy payor called &#8220;Balance Forward&#8221; and initialize it with the total balance from the old software. Years later, some customers have had difficulties determining accurate account balances because of credit amounts that linger [...]]]></description>
			<content:encoded><![CDATA[<p>During the conversion of data from the old DOS software to the Windows version of SOS, one option was to create a dummy payor called &#8220;Balance Forward&#8221; and initialize it with the total balance from the old software. Years later, some customers have had difficulties determining accurate account balances because of credit amounts that linger as unapplied payments attributed to the Balance Forward payor. The following query lists the accounts showing this issue.</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Select All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> 
  fullnameid<span style="color: #66cc66;">,</span> 
  licnum <span style="color: #993333; font-weight: bold;">AS</span> dataset<span style="color: #66cc66;">,</span> 
  <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span> flag <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'active'</span> <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #ff0000;">'inactive'</span> ENDIF<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> PtList<span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>crsplamt<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> Tot_Unapplied
<span style="color: #993333; font-weight: bold;">FROM</span> 
  rv_creditsplits
<span style="color: #993333; font-weight: bold;">WHERE</span> 
  payornum <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">2</span>
<span style="color: #993333; font-weight: bold;">AND</span> 
  <span style="color: #66cc66;">&#40;</span>chgsplnum <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">OR</span> chgsplnum <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> 
  fullnameid<span style="color: #66cc66;">,</span> licnum<span style="color: #66cc66;">,</span> ptlist
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> 
  fullnameid</pre></td></tr></table></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.sosoft.com/queries/2012/02/17/identifying-accounts-with-unapplied-balance-forward-amounts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

