How to work on LIKE Query

Posts   
 
    
Posts: 97
Joined: 29-Apr-2009
# Posted on: 14-May-2009 12:46:15   

hello all,

i want to search by date in my project. in my database there is field dtCreationDate which store date and time of creation.

my database image : www.freeimagehosting.net/uploads/218743366b.png

now i want to search by date, so want to use LIKE query, by that i can get result.

i am using self servicing.

can you please help me??

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 14-May-2009 18:20:26   

The LIKE operator does not really apply to dates, only to string values. Can you give us an idea of the sort of query you want to run, or what you have tried so far?

Posts: 97
Joined: 29-Apr-2009
# Posted on: 15-May-2009 05:01:01   

MTrinder wrote:

The LIKE operator does not really apply to dates, only to string values. Can you give us an idea of the sort of query you want to run, or what you have tried so far?

Hi MTrinder,

Thanks for reply

well i want to search by date. i.e. suppose i will enter date like 05/15/2009, so it will show me the articles list on which date(05/15/2009) it was posted.

but the problem is that in my database date is store (date and time) like :

05/15/2009 4:10:17 PM

so i thought , i can use like query to search on date. so it gives result.

if i am wrong please correct me and give me some solution.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-May-2009 05:41:34   

In this case, use DBFunctionCall. You could use this expression (a trick I found here). So it would look like:

IPredicate monthFilter = new EntityField("ArticleCreationDate", 
     new DbFunctionCall("CAST( FLOOR( CAST( {0} AS FLOAT ) ) AS DATETIME )",
     new object[] { ArticleFields.DtCreationDate  })) == someDateTimeValue);

For the rest, do the same you did here: http://llblgen.com/tinyforum/Messages.aspx?ThreadID=15906

David Elizondo | LLBLGen Support Team
Posts: 97
Joined: 29-Apr-2009
# Posted on: 15-May-2009 06:02:37   

daelmo wrote:

In this case, use DBFunctionCall. You could use this expression (a trick I found here). So it would look like:

IPredicate monthFilter = new EntityField("ArticleCreationDate", 
     new DbFunctionCall("CAST( FLOOR( CAST( {0} AS FLOAT ) ) AS DATETIME )",
     new object[] { ArticleFields.DtCreationDate  })) == someDateTimeValue);

For the rest, do the same you did here: http://llblgen.com/tinyforum/Messages.aspx?ThreadID=15906

Hi daelmo

Thanks a lot man,

done it.

Posts: 97
Joined: 29-Apr-2009
# Posted on: 15-May-2009 07:13:27   

daelmo wrote:

In this case, use DBFunctionCall. You could use this expression (a trick I found here). So it would look like:

IPredicate monthFilter = new EntityField("ArticleCreationDate", 
     new DbFunctionCall("CAST( FLOOR( CAST( {0} AS FLOAT ) ) AS DATETIME )",
     new object[] { ArticleFields.DtCreationDate  })) == someDateTimeValue);

For the rest, do the same you did here: http://llblgen.com/tinyforum/Messages.aspx?ThreadID=15906

Hi daelmo

but can u tell me how can i use LIKE Query in self servicing.

if suppose i have i have table and there is field called EmployeeName

so how can i user LIKE Query : e.g. in PredicateExpression

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-May-2009 09:19:42   

Please use FieldLikePredicate

Posts: 97
Joined: 29-Apr-2009
# Posted on: 15-May-2009 10:57:51   

Walaa wrote:

Please use FieldLikePredicate

Thanks for link walaa. i got it how to do that.

thanks