How do I...

Posts   
 
    
lotek
User
Posts: 56
Joined: 14-Sep-2005
# Posted on: 14-Nov-2005 22:19:15   

Does llblgen have an equivelent to:

SELECT col1, col2, CASE WHEN EXISTS (SELECT * FROM othertable WHERE col1 = col1) THEN 1 ELSE 0 END AS col3 FROM table

I basically want to see if a row exists in another table and return a boolean value if it does/doesnt. ( I want to get a typed list or entity collection)

Thanks! Matt

pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 15-Nov-2005 00:00:09   

lotek wrote:

Does llblgen have an equivelent to:

SELECT col1, col2, CASE WHEN EXISTS (SELECT * FROM othertable WHERE col1 = col1) THEN 1 ELSE 0 END AS col3 FROM table

I basically want to see if a row exists in another table and return a boolean value if it does/doesnt. ( I want to get a typed list or entity collection)

Thanks! Matt

Wouldn't this query be the same as:

SELECT col1 , col2 , CASE WHEN ot.col1 IS NULL THEN 0 ELSE 1 END col3 FROM table LEFT JOIN othertable ot ON table.col1 = ot.col1

??? I'm pretty sure you can do that in LLBLGEN.

BOB

lotek
User
Posts: 56
Joined: 14-Sep-2005
# Posted on: 15-Nov-2005 02:27:09   

Yep, any code sample of how i might write that?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 15-Nov-2005 08:27:48   

CASE constructs are currently not supported. If you want to get the same behavior as a CASE statement in a query, you have to perform the data manipulation at the client side.

Frans Bouma | Lead developer LLBLGen Pro
pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 15-Nov-2005 17:30:46   

lotek wrote:

Yep, any code sample of how i might write that?

I think you would be able to set up a fetch that will return a NULL in col3, then create a type converter to convert the field to bool. Set the bool to true if the value is not null, and false if it is.

Frans, is this feasible?

BOb

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 15-Nov-2005 18:57:15   

From the top of my head, I think it will work. simple_smile Good suggestion for the type converter.

Frans Bouma | Lead developer LLBLGen Pro