0

This seemingly should be pretty simple, but I'm having difficulty finding an answer. I'm writing a basic open-ended select function, and am trying to find how to select for all supplied values.

This is my best guess on how this would look, but search engines are only yielding answers to more complex of questions today.

DECLARE
    @nAge INT = @age
    @nHeight INT = @height
    @nWeight INT = @weight

SELECT *
FROM table
WHERE ((EXISTS(@nAge) AND nAge = @nAge) OR true)
  AND ((EXISTS(@nHeight) AND nHeight = @nHeight) OR true)
  AND ((EXISTS(@nWeight) AND nWeight = @nWeight) OR true)

Here's a few links I checked first:

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Seph Reed
  • 8,797
  • 11
  • 60
  • 125
  • Does this answer your question? [SQL add filter only if a variable is not null](https://stackoverflow.com/q/38828272/11683) – GSerg Jul 22 '22 at 17:12
  • Does this answer your question? [How to filter records on condition if filter value is NULL in SQL Server?](https://stackoverflow.com/q/35792701/11683) – GSerg Jul 22 '22 at 17:13
  • Also see [An Updated Kitchen Sink Example](https://www.sentryone.com/blog/aaronbertrand/backtobasics-updated-kitchen-sink-example). – Aaron Bertrand Jul 22 '22 at 19:35

0 Answers0