Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Hmm, it should indeed be simple boolean algebra to disregard one branch of this, seems the SQL optimizer does not realize the variable is constant during the query. In theory it could change, but there would need to be some section in the query itself, setting @Boolset. I think it could differ if you actually make this a parameter of a table valued stored procedure.(@BoolSet = 1 And FirstFilter) Or (@BoolSet = 0 And SecondFilter)
Yes that's correct only one of those produces and results. I tried a union it's as fast as running the single query. I wasn't convinced so I posted the same question on stackoverflow. Apparently union is the commonly known solution. I wanted the query to remain insi compliant so union it is.Hmm, it should indeed be simple boolean algebra to disregard one branch of this, seems the SQL optimizer does not realize the variable is constant during the query. In theory it could change, but there would need to be some section in the query itself, setting @Boolset. I think it could differ if you actually make this a parameter of a table valued stored procedure.
And now, I assume, your union will essentially have one empty result and one actual result, depending on a bit value. I wonder whether it would be simpler to have two queries and call the one according to a bit, that you actually want to run.