I have a problem with the view I want to create. I have two tables joined in a left outer join, like tableA and tableB , where tableB remains outer.
I want to select only those rows from table B where the state is 4, so I am adding WHERE state = 4 to my query. Now the result set is truncated quite a bit, because all rows without the corresponding row in tableB are removed from the result (since the state is not 4 for these rows). I also tried WHERE state = 4 OR state IS NULL does not work either (since state technically not NULL when there is no state).
So, I need a WHERE statement, which is evaluated only when there really is a string, does such a thing exist?
If not, I see two options: join (SELECT * FROM tableB WHERE state = 4) instead of table B or create a view with the same WHERE statement and attach it. What is the best performance version?
This, by the way, is SQL Server 2008 R2.
source share