Wildcard search / search string evaluation

I defined the wildcard as "%" (this is proposed in all examples I've seen):

<Property Name="WildcardCharacter" Type="System.String">%</Property>

I've a SQL statement defined:

Select Uid,firstname,lastname From dbo.Participant WHERE (Uid&gt;=@GeneratedMinUid) and (Uid&lt;=@GeneratedMaxUid) AND (lastname LIKE @lastname)

The part "(Uid&gt;=@GeneratedMinUid) and (Uid&lt;=@GeneratedMaxUid)" is generated by the BDC Meta Man. Even that "Uid" is a string the "°<="/"<=" is being constructed!

Why not just:

(Uid = @GeneratedUid)


My problem ist that the SQL evaluates to (I just search for the lastname and the other parameters are filled with a wildcard):


Select Uid,firstname,lastname From dbo.Participant WHERE (Uid>='%') and (Uid<='%') AND (lastname LIKE 'searchName')

Is this correct?

And this search string doesn't return the lastnames witch 'searchName' because "(Uid>='%') and (Uid<='%')" is never true for my "searchName"!

The server log contains this:

Select Uid,firstname,lastname From dbo.Participant WHERE (Uid>=@GeneratedMinUid) and (Uid<=@GeneratedMaxUid) AND (lastname LIKE @lastname)
Parameter Signature: System.String @GeneratedMinUid, System.String @GeneratedMaxUid, System.String @lastname,
Parameter Values:
Queried 0 TypeDescriptor records for TypeDescriptor with Id '3433'
Queried 0 TypeDescriptor records for TypeDescriptor with Id '3435'
Queried 0 TypeDescriptor records for TypeDescriptor with Id '3437'
Parameter
'@GeneratedMinUid':
TypeDesc Uid: %
Parameter
'@GeneratedMaxUid':
TypeDesc Uid: %
Parameter
'@lastname':
TypeDesc lastname: 1111
Finished executing query
Instantiating Type 'System.String'.
Recursively instantiating Type 'System.String' at a nest level of '0'.
Found default value '%'; returning that instead of instantiating at a nest level of '0'.
Completely instantiated Type 'System.String'.
Instantiating Type 'System.String'.
Recursively instantiating Type 'System.String' at a nest level of '0'.
Found default value '%'; returning that instead of instantiating at a nest level of '0'.
Completely instantiated Type 'System.String'.
Instantiating Type 'System.String'.
Recursively instantiating Type 'System.String' at a nest level of '0'.
Found default value '%'; returning that instead of instantiating at a nest level of '0'.
Completely instantiated Type 'System.String'.

[3704 byte] By [Erulu] at [2008-3-1]
# 1
If Uid is a string type and it is a primary key: Let's assume that the min value is 'a' and the max value is 'z', then you can define your default value as 'a' and 'z' respectively, and the SQL statement will resolve correctly. In your situation you have to figure what your min and max values are and use them!
FrankChiang at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Business Data Catalog...
# 2

To clarify the previous post, the reason you have to use <= and >= instead of = is that you need to nullify that where clause when you aren't passing in that parameter.

To state that differently, SQL doesn't have a wildcard character for Integers, so we have to instead make a broad range that won't cancel out any rows to achieve the wildcard effect.

Set your MIN default value to something smaller than any values in your database, and your MAX default value to something larger than any values in your database.

KeirGordon at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Business Data Catalog...

SharePoint Products and Technologies

Site Classified