Search code examples
c#sqlcompact-frameworksql-server-ce

SQL conditional statements?


I'm trying to write a query for a table in SQLCE and compact-framework but the query needs to read every row with two conditions.

Column 'location' in any given row may or may not be null, if it's not null it needs to be checked for its value, if it's null the row should be selected, i.e:

if( location!= null )
{
    if( d == "location" )
         SELECT;
}
else
    SELECT;

Anyone know how I can go about doing this?


Solution

  • Use OR to test if either condition is true.

    SELECT col1, col2, ..., coln
    FROM yourtable
    WHERE location IS NULL OR location = 'location'