Go to SoftFluent site to register or reset your account
Welcome Guest Search | Active Topics | Log In

Adding a starting '%' in a search method Options
Carl
#1 Posted : Tuesday, July 27, 2010 3:07:24 PM
Rank: Advanced Member

Groups: Users

Joined: 8/13/2009
Posts: 96
Hi,

I'd like to modify the output of a Search stored procedure so that search parameters are surrounded with '%' rather than just a trailing one.
Example:
Here is my model:
Code:

<cf:method name="Search"
               body="Search(string email, string userName, string firstName, string lastName) where Licensee.EMail startswith @email and Licensee.UserName startswith @userName and Licensee.FirstName startswith @FirstName and Licensee.LastName startswith @LastName" />

This method generates the following stored procedure:
Code:

(...)
IF @email IS NOT NULL
    SELECT @sql = @sql + ' AND ([Licensee].[EMail] LIKE (@email + ''%''))'
(...)


However, is it possible to get this:
Code:

(...)
IF @email IS NOT NULL
    SELECT @sql = @sql + ' AND ([Licensee].[EMail] LIKE (''%'' + @email + ''%''))'
(...)


Regards,
Carl
CodeFluent Support Team
#2 Posted : Tuesday, July 27, 2010 3:56:49 PM
Rank: Administration


Groups: Users, Registered, CodeFluent

Joined: 8/11/2009
Posts: 69
Hi Carl,

You should write it this way:

Code:

<cf:method name="Search" body="Search(string email, string userName) where EMail like ('%%' + @email + '%%') and UserName like ('%%' + @userName + '%%') " />


Note the % character needs to be doubled, otherwise the parser will treat %' + @userName + '% as the reference to an environment variable named ' + @userName + ' (this is a common behavior for all Xml attributes in CodeFluent Entities models). Since there is no environment variable with that name (!) it would then be replaced by an empty string, and the resulting CFQL body would then be:

Code:

<cf:method name="Search" body="Search(string email, string userName) where EMail like ('') and UserName like ('') " />


which is correct but of course does not work as expected :)

Thanks!

CodeFluent Support Team
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.301 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.053 seconds.