<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Passing Multiple Values to One Parameter</title>
	<atom:link href="http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/feed/" rel="self" type="application/rss+xml" />
	<link>http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/</link>
	<description>A DataPig Technologies Blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 00:53:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: Jeff Weir</title>
		<link>http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/comment-page-1/#comment-14649</link>
		<dc:creator>Jeff Weir</dc:creator>
		<pubDate>Wed, 02 Feb 2011 01:08:54 +0000</pubDate>
		<guid isPermaLink="false">http://datapigtechnologies.com/blog/?p=675#comment-14649</guid>
		<description>Here&#039;s a way to do this without VBA when using Excel to query an excel database that exists in the same workbook. (Note: I&#039;ve had this working in Excel 2010 no problem, but had issues in Excel 2003)

Set up a one-column named range for EACH of the criteria you want to filter on. Then use these as tables to filter your records in the WHERE clause. For instance, here&#039;s an example that filters the text feild &#039;GivenName&#039; and the numerical field &#039;Number&#039; from a database called &#039;data&#039;.

&lt;code&gt;
SELECT distinct data.Number
, data.Gender
, data.Salary
, data.GivenName
, data.MiddleInitial
, data.Surname
, data.StreetAddress
, data.City
, data.State
, data.ZipCode
, data.Country
, data.Birthday
, data.BloodType
, data.Pounds

FROM data, Number_min,Number_max, GivenName

Where
data.Number &gt;= Number_min.Number_min
AND data.Number &lt;= Number_max.Number_max
AND data.GivenName like GivenName_criteria.GivenName

&lt;/code&gt;

Number_min, Number_max, and GivenName_equals are the tables (i.e. named ranges) on the worksheet where you enter your desired criteria. You then refresh the query, and the recordset is updated accordingly. Unfortunately the query doesn’t refresh automatically when you amend your filter criteria, but I get around this by adding a ‘trigger’ parameter along the lines of AND data.GivenName  [Trigger_parameter]. This parameter is then linked to a cell on the worksheet, and in that cell I have a  formula that concatenates all the different filter data entry cells. Eg:
 = Number_min &amp; Number_max  &amp; GivenName_equals

So as soon as one of these criteria changes, the trigger parameter triggers the query to refresh. 

Obviously you only want to have one Number_min and Number_max parameter, so the named range for these should only allow users to put in one parameter (i.e. one max and one min). But you can have as many GivenName parameters as you want.

You can also use wildcards in these. So %a% in the GivenName criteria table would return any names with an &#039;a&#039; in them.

Note that one downside of this is you get some ‘memory leak’ if you use MS Query to query an open workbook…basically the query process uses  some memory while it is running, and that memory then can&#039;t be used by your computer until you exit Excel.  But with the examples I&#039;ve been playing with, I haven&#039;t run out of memory.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a way to do this without VBA when using Excel to query an excel database that exists in the same workbook. (Note: I&#8217;ve had this working in Excel 2010 no problem, but had issues in Excel 2003)</p>
<p>Set up a one-column named range for EACH of the criteria you want to filter on. Then use these as tables to filter your records in the WHERE clause. For instance, here&#8217;s an example that filters the text feild &#8216;GivenName&#8217; and the numerical field &#8216;Number&#8217; from a database called &#8216;data&#8217;.</p>
<p><code><br />
SELECT distinct data.Number<br />
, data.Gender<br />
, data.Salary<br />
, data.GivenName<br />
, data.MiddleInitial<br />
, data.Surname<br />
, data.StreetAddress<br />
, data.City<br />
, data.State<br />
, data.ZipCode<br />
, data.Country<br />
, data.Birthday<br />
, data.BloodType<br />
, data.Pounds</p>
<p>FROM data, Number_min,Number_max, GivenName</p>
<p>Where<br />
data.Number &gt;= Number_min.Number_min<br />
AND data.Number &lt;= Number_max.Number_max<br />
AND data.GivenName like GivenName_criteria.GivenName</p>
<p></code></p>
<p>Number_min, Number_max, and GivenName_equals are the tables (i.e. named ranges) on the worksheet where you enter your desired criteria. You then refresh the query, and the recordset is updated accordingly. Unfortunately the query doesn’t refresh automatically when you amend your filter criteria, but I get around this by adding a ‘trigger’ parameter along the lines of AND data.GivenName  [Trigger_parameter]. This parameter is then linked to a cell on the worksheet, and in that cell I have a  formula that concatenates all the different filter data entry cells. Eg:<br />
 = Number_min &amp; Number_max  &amp; GivenName_equals</p>
<p>So as soon as one of these criteria changes, the trigger parameter triggers the query to refresh. </p>
<p>Obviously you only want to have one Number_min and Number_max parameter, so the named range for these should only allow users to put in one parameter (i.e. one max and one min). But you can have as many GivenName parameters as you want.</p>
<p>You can also use wildcards in these. So %a% in the GivenName criteria table would return any names with an &#8216;a&#8217; in them.</p>
<p>Note that one downside of this is you get some ‘memory leak’ if you use MS Query to query an open workbook…basically the query process uses  some memory while it is running, and that memory then can&#8217;t be used by your computer until you exit Excel.  But with the examples I&#8217;ve been playing with, I haven&#8217;t run out of memory.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Banfield</title>
		<link>http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/comment-page-1/#comment-1774</link>
		<dc:creator>Colin Banfield</dc:creator>
		<pubDate>Thu, 06 Aug 2009 16:42:45 +0000</pubDate>
		<guid isPermaLink="false">http://datapigtechnologies.com/blog/?p=675#comment-1774</guid>
		<description>Mike, I went through the same sequence (including the Cast and Convert bit). CharIndex is totally anal. Because it returns an integer, it seems to expect an integer parameter. Feed it an integer parameter, and Excel complains that it&#039;s not valid for the argument (of course). Feed it text, and Excel complains that it&#039;s a bad parameter type. Grrr!</description>
		<content:encoded><![CDATA[<p>Mike, I went through the same sequence (including the Cast and Convert bit). CharIndex is totally anal. Because it returns an integer, it seems to expect an integer parameter. Feed it an integer parameter, and Excel complains that it&#8217;s not valid for the argument (of course). Feed it text, and Excel complains that it&#8217;s a bad parameter type. Grrr!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: datapig</title>
		<link>http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/comment-page-1/#comment-1773</link>
		<dc:creator>datapig</dc:creator>
		<pubDate>Thu, 06 Aug 2009 16:17:30 +0000</pubDate>
		<guid isPermaLink="false">http://datapigtechnologies.com/blog/?p=675#comment-1773</guid>
		<description>Colin:  I didn&#039;t get it to work in SQL Server.  I&#039;ve never tried to use this technique with SQL server until now.  

At first glance it seems as though data type issues are the culprit in preventing the us from hitting SQL Server.  

I know that CharIndex will accept char, nchar, varchar, nvarchar, text, and ntext strings, but for some reason, it won&#039;t recognize the values fed from a parameter.

So then I tried passing the parameter through the Convert and Cast functions but apparently the SQL Server Driver complained that the parameter value can&#039;t be derived when used as an argument in a function.  

So the real issue seems to be that the SQL driver (and presumably the Oracle driver) can&#039;t translate or interpret  a parameter value when fed as an argument in a function.   That is what I&#039;m concluding anyway. 


Nevertheless, Access doesn&#039;t seem to have this problem.  

And Colin has been right all along.  This technique would seem to be severely limited to Access databases.</description>
		<content:encoded><![CDATA[<p>Colin:  I didn&#8217;t get it to work in SQL Server.  I&#8217;ve never tried to use this technique with SQL server until now.  </p>
<p>At first glance it seems as though data type issues are the culprit in preventing the us from hitting SQL Server.  </p>
<p>I know that CharIndex will accept char, nchar, varchar, nvarchar, text, and ntext strings, but for some reason, it won&#8217;t recognize the values fed from a parameter.</p>
<p>So then I tried passing the parameter through the Convert and Cast functions but apparently the SQL Server Driver complained that the parameter value can&#8217;t be derived when used as an argument in a function.  </p>
<p>So the real issue seems to be that the SQL driver (and presumably the Oracle driver) can&#8217;t translate or interpret  a parameter value when fed as an argument in a function.   That is what I&#8217;m concluding anyway. </p>
<p>Nevertheless, Access doesn&#8217;t seem to have this problem.  </p>
<p>And Colin has been right all along.  This technique would seem to be severely limited to Access databases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Banfield</title>
		<link>http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/comment-page-1/#comment-1766</link>
		<dc:creator>Colin Banfield</dc:creator>
		<pubDate>Thu, 06 Aug 2009 14:15:43 +0000</pubDate>
		<guid isPermaLink="false">http://datapigtechnologies.com/blog/?p=675#comment-1766</guid>
		<description>That should read CHARINDEX(?, fieldname)&gt;0.</description>
		<content:encoded><![CDATA[<p>That should read CHARINDEX(?, fieldname)&gt;0.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Banfield</title>
		<link>http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/comment-page-1/#comment-1765</link>
		<dc:creator>Colin Banfield</dc:creator>
		<pubDate>Thu, 06 Aug 2009 14:13:29 +0000</pubDate>
		<guid isPermaLink="false">http://datapigtechnologies.com/blog/?p=675#comment-1765</guid>
		<description>Mike, how did you get this to work with SQL Server? SQL Server doesn&#039;t support Instr, and attempting to pass a parameter into the equivalent CHARINDEX function, like CHARINDEX(?, )&gt;0, doesn&#039;t work.</description>
		<content:encoded><![CDATA[<p>Mike, how did you get this to work with SQL Server? SQL Server doesn&#8217;t support Instr, and attempting to pass a parameter into the equivalent CHARINDEX function, like CHARINDEX(?, )&gt;0, doesn&#8217;t work.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

