Skip to main content

Can someone solve this 'flexible' WHERE Clause?

Answered

Comments

1 comment

  • Best answer
    DSP Expert

    PTowe: If I understand the question correctly, it's just a simple where statement:

    SELECT B.ProjectID, B.boaUserID, B.[Count] FROM B INNER JOIN A ON B.boaUserID = A.UserID Where viewzeroRecords=1 or [Count]>0 This would also be a classic example of where you may want to use the Case statement in a where clause, like this: SELECT B.ProjectID, B.boaUserID, B.[Count] FROM B INNER JOIN A ON B.boaUserID = A.UserID where Case when viewzeroRecords=1 then 1 when [Count]>0 then 1 else 0 end =1

    This is not always the fastest solution as a case statement is a bit slow to process, but for complex where statements, it can be quicker than using lots of separate clauses separated by OR . By the way, its not considered good practice to call a column "Count." The use of key words in table names and column names is discouraged. I hope this helps

    1

Please sign in to leave a comment.