Equivalent to Case statement...

Posts   
 
    
adhesion
User
Posts: 7
Joined: 20-Nov-2006
# Posted on: 20-Dec-2006 03:40:34   

I have a situation in a query where I need to display a value based on the existance of another column. In this case, there is a FirstName column, LastName column, and CompanyName column.

If there is a first name and last name then I want to display "LastName, FirstName" but if there are not values then I want to display just the CompanyName.

Is this best done with field expressions (and if so, how?) or with a user-defined function on the database side?

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Dec-2006 07:15:15   

IMHO, this should be done using a custom property in the Entity Class, let's call it "DisplayName" that has a Getter and not a Setter (read-only). In which you can do the check and return whatever string you want.

adhesion
User
Posts: 7
Joined: 20-Nov-2006
# Posted on: 22-Dec-2006 02:59:23   

I'm using a dynamic list. How can I then define the field associated with this custom property? I tried creating a partial class with a readonly property but I'm not sure then how to add this to my ResultsetFields.

Posts: 1268
Joined: 10-Mar-2006
# Posted on: 22-Dec-2006 09:10:35   

I am guessing your backend database does not support calculated fields?

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 23-Dec-2006 23:15:21   

If you're using SQL Server, you could use a udf, but better I think is to created a TypedView in LLBLGen which is based on a view you create containing this logic.