Sharpeye500
Sharpeye500

Reputation: 9073

Single select query to handle two conditions

I have a select query in which there is a where condition

  select column1,column2 from table1 where isnull(i.picturecolumn) != 1;

picturecolumn is in bytes data type.

I need to use hyperlink column , if hyperlink column is null, then look for picture column.

  select column1,column2 from table1 where isnull(i.hyperlinkcolumn) != 1;

ie:

if (hyperlink==null)
{
   select column1,column2 from table1 where isnull(i.picturecolumn) != 1;
}
else
{
select column1,column2 from table1 where isnull(i.hyperlinkcolumn) != 1;
}

I have single select query in the code, i need to replace with another select query to handle this, any thoughts?

Upvotes: 0

Views: 415

Answers (2)

Joe Stefanelli
Joe Stefanelli

Reputation: 135808

select column1,column2 
    from table1 
    where isnull(coalesce(i.hyperlinkcolumn, i.picturecolumn)) != 1;

Upvotes: 3

Mike
Mike

Reputation: 2136

I'm not sure, but I think this is what you're looking for: SELECT col1,col2 FROM table1 WHERE picturecolumn IS NOT NULL OR hyperlinkcolumn IS NOT NULL;

Basically, return results for anything where either one of those columns is not null.

Upvotes: 1

Related Questions