﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Exact searching</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Sun, 12 Apr 2026 19:38:06 GMT</lastBuildDate><ttl>20</ttl><item><title>Exact searching</title><link>http://forum.strataframe.net/FindPost28185.aspx</link><description>Hi there,&lt;/P&gt;&lt;P&gt;in one of my BOs ("LieferBO") I added a get-method I took from the help-file&lt;/P&gt;&lt;P&gt;and modified it to myBO-name and field-name.&lt;/P&gt;&lt;P&gt;[code]&lt;/P&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;&lt;P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;Dim&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt; loCommand &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;New&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;SqlCommand&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;()&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;&lt;P&gt;loCommand.CommandText = &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;"SELECT COUNT(*) FROM liefer WHERE adresse = @pAdresse"&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;&lt;P&gt;loCommand.Parameters.Add(&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;"@pAdresse"&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;, &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;SqlDbType&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;.VarChar)&lt;/P&gt;&lt;P&gt;loCommand.Parameters(&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;"@pAdresse"&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;).Value = cAdresse&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;&lt;P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;Return&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;CType&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;(&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;Me&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;.ExecuteScalar(loCommand), &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;Integer&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;)&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;P&gt;[/code&lt;/P&gt;&lt;P&gt;But now I have the following problem which I can't solve by myself:&lt;/P&gt;&lt;P&gt;There are, for example the following records with the field "adresse" which is a char(6)-field:&lt;/P&gt;&lt;P&gt;B-M&lt;/P&gt;&lt;P&gt;BALM&lt;/P&gt;&lt;P&gt;BZ&lt;/P&gt;&lt;P&gt;I want to search, if there is a record with "BAL", which would be a valid new value, but the method returns 1 because it finds the "BALM"-record. I tried changing the var cAdresse to cAdresse.padr(6," ") which always worked with VFP-Views, but not here.&lt;/P&gt;&lt;P&gt;Can somebody advise me how this can be done?&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Thomas</description><pubDate>Tue, 31 Aug 2010 14:07:41 GMT</pubDate><dc:creator>Thomas Holste</dc:creator></item><item><title>RE: Exact searching</title><link>http://forum.strataframe.net/FindPost28215.aspx</link><description>Hi Greg,&lt;/P&gt;&lt;P&gt;thank you for explaining the advantage of a varchar-type.&lt;/P&gt;&lt;P&gt;I guess, one of my next tasks will be to write conversion-apps (from VFP) and&amp;nbsp;&lt;/P&gt;&lt;P&gt;compare the speed with some&amp;nbsp; bigger tables (&amp;gt; 100000 records) .&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Thomas</description><pubDate>Tue, 31 Aug 2010 14:07:41 GMT</pubDate><dc:creator>Thomas Holste</dc:creator></item><item><title>RE: Exact searching</title><link>http://forum.strataframe.net/FindPost28209.aspx</link><description>I tend to almost always use varchar (or nvarchar if I expect to support multiple languages). If I did use a char is would be in cases were all data would be close to or exactly the length of the field. It is my understanding that if the values are variable, then a Varchar is faster (because exactly the data that is needed is sent over the wire).  Usually if I want to encode data, I use an enum and store an int in the database, which is way faster than a char.</description><pubDate>Tue, 31 Aug 2010 09:19:33 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Exact searching</title><link>http://forum.strataframe.net/FindPost28202.aspx</link><description>Hi Greg,&lt;/P&gt;&lt;P&gt;thanks a lot for your help. After playing around a bit i found the reason why the function does not work as I expected it. I call it the "Cut and Paste Disease" because&amp;nbsp;I copied the example but did not change&lt;/P&gt;&lt;P&gt;&lt;FONT face=Consolas&gt;&amp;nbsp;&lt;/FONT&gt;loCommand.Parameters.Add(&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;"@pAdresse"&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;, &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;SqlDbType&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;.VarChar)&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;P&gt;to&lt;/P&gt;&lt;P&gt;loCommand.Parameters.Add(&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;"@pAdresse"&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;, &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;&lt;FONT color=#2b91af size=2 face=Consolas&gt;SqlDbType&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;.Char)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;Because my datatype is char.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;Nowe everything works fine. But after all I have a more generic question and that is what I should do when my data-conversion has to become more precise (By now I used Les Pinters conversion tool to ha a starting point)? Shoul I use char or varchar types. Space is today no problem but speed will always be, so after my reading by now I decided to use the char-type. What is your suggestion?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face=Consolas&gt;Thanks a lot&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face=Consolas&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face=Consolas&gt;Thomas&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;</description><pubDate>Tue, 31 Aug 2010 02:36:34 GMT</pubDate><dc:creator>Thomas Holste</dc:creator></item><item><title>RE: Exact searching</title><link>http://forum.strataframe.net/FindPost28193.aspx</link><description>Thomas, I think the problem is that the data type of the field is char(6). This means that the field [b]always[/b] has 6 characters (see last paragraph). However, when you are setting things up in .NET, it is a string, which won't have the extra characters. I.e.&lt;br&gt;
&lt;br&gt;
If you provide 'B-M' from .NET, it won't match the value in the database, which is 'B-M   ' (note extra spaces).&lt;br&gt;
&lt;br&gt;
If the values are unique enough, you can just switch to a like statement:&lt;br&gt;
&lt;br&gt;
WHERE adresse Like(@pAdresse + '%')&lt;br&gt;
&lt;br&gt;
This won't work if you could have values like 'BAL' and 'BALM', because 'BAL' would incorrectly match 'BALM' also.&lt;br&gt;
&lt;br&gt;
The next option would be to manipulate the SQL field by trimming it:&lt;br&gt;
&lt;br&gt;
WHERE adresse = RTRIM(@pAdresse)&lt;br&gt;
&lt;br&gt;
You could also try padding the .NET strings, but that would be harder than just trimming the db value.&lt;br&gt;
&lt;br&gt;
When I did a test in SQL Server 2005, you original query worked. I.e. SQL Server 2005 doesn't include the extra spaces to ensure that the string is 6 characters. However, I think SQL Server 2000 does include the extra spaces, because I know I'd had to deal with this before.  &lt;br&gt;
&lt;br&gt;</description><pubDate>Mon, 30 Aug 2010 14:57:33 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Exact searching</title><link>http://forum.strataframe.net/FindPost28186.aspx</link><description>Hi Thomas,&lt;br&gt;
Your query looks OK and it should be returning a full match.  The behavior you are describing is what you get when using the LIKE % operator.  I am not sure, but probably there is some switch somewhere in MS-SQL to change the behavior, try looking in Google since this is basically plain SQL.  &lt;br&gt;
&lt;br&gt;
By the way, have you tested your query in MS Management Studio?</description><pubDate>Mon, 30 Aug 2010 13:37:22 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item></channel></rss>