Conditionally sql query

Posts   
 
    
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 17-Aug-2010 11:38:53   

I'd like to create a query with following functionality.

Whatever my query returns 0 records the query will fetch the data by other clause. If the first clause will fetch some records the second clause will be ignored.

I'm supposing to get either one record.

In sql it would be something like this


SELECT * FROM users WHERE name = 'User1'
UNION ALL 
SELECT * FROM users WHERE name = 'Default' 
    AND NOT EXISTS (SELECT 1 FROM users WHERE name='User1')

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 17-Aug-2010 20:33:28   

Sorry, LLBLGen does not support UNION queries in its API (and so not in LINQ either). You will either have to write a stored proc to do the query, or run 2 seperate queries on the client side.

Matt