Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7564727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:58:11+00:00 2026-05-30T13:58:11+00:00

I am porting a sql query to Simple.Data, the original query is something like:

  • 0

I am porting a sql query to Simple.Data, the original query is something like:

select a.Field1, a.Field2, b.Field1
from TableA a
join TableB b ON a.KeyField = b.KeyField
where coalesce(b.SomeDate, '1/1/1900') <= getdate()

I’ve been able to port everything in the query except for that darn coalesce logic:

var currentDate = DateTime.Now;
var result = db.TableA.Query()
    .Join(db.TableB).On(db.TableA.KeyField == db.TableB.KeyField &&
        db.TableB.SomeDate == currentDate)
    .Select(db.TableA.Field1, db.TableA.Field2, db.TableB.Field1);

Any thoughts on how to get the coalesce behavior in there? I’ve tried using the ?? operator to no avail.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:58:12+00:00Added an answer on May 30, 2026 at 1:58 pm

    When there is a SQL function which takes a column name as its first parameter, you can specify it as a method on the column:

    var currentDate = DateTime.Now;
    var defaultDate = new DateTime(1900,1,1);
    var result = db.TableA.Query()
        .Join(db.TableB).On(db.TableA.KeyField == db.TableB.KeyField &&
            db.TableB.SomeDate.Coalesce(defaultDate) <= currentDate)
        .Select(db.TableA.Field1, db.TableA.Field2, db.TableB.Field1);
    

    Note that if you have referential integrity set up between TableA and TableB, you can leave out the explicit join and simplify this query to:

    var currentDate = DateTime.Now;
    var defaultDate = new DateTime(1900,1,1);
    var result = db.TableA
        .Query(db.TableA.TableB.SomeDate.Coalesce(defaultDate) <= currentDate)
        .Select(db.TableA.Field1, db.TableA.Field2, db.TableB.Field1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am preparing myself for importing data from excel sheet to sql server 2005.I
we have WinForms app which stores data in SQL Server (2000, we are working
I am currently tasked with porting our website code onto a linux server (from
We've porting code to Delphi XE2, and need to change our data access components
I am porting an Access front end/Access back end application to Access front end/SQL
I have a weird problem with my sql script. I have a string $query
I am writing an SQL query which will return a list of auctions a
I am porting an application for KodoJDO to Hibernate. I have a query that
This is a followup question to: SQL Query with ORDER BY But I think
We are looking at various options in porting our persistence layer from Oracle to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.