Avatar of digitalwise
digitalwise asked on

SQL Where statement and conditional selecting

I have two fields in a table - yearcon and yearren.    

select yearren, yearcon from property

Open in new window

If yearren is populated I want to look at that field in the where statement and if not, look at the yearcon field.

where if(yearren > 0, yearren, yearcon) > 2000

Open in new window

Can someone help me?   I have the flu and my brain doesn't work!
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
Scott Pletcher

8/22/2022 - Mon
Brian Crowe

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Scott Pletcher

Avoid using ISNULL in a WHERE or JOIN because it makes the columns "nonsargable".  In this case, the OR may still cause performance issues, but the rule about not using ISNULL is still correct.

WHERE ((yearren > 0 AND yearren > 2000) OR ((yearren IS NULL OR yearren = 0) AND yearcon > 2000))
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck