I have a certain function which returns tabular value. It has several optional parameters. The problem is that when calling a function (in the studio) without specifying the parameters, I get an empty selection, but it should not be so. I feel that conditions in where are incorrectly set. But as soon as he was not out, he did not want to work as he should.
The function looks like this:
ALTER FUNCTION dbo.GetPeople(@m_id INT, @sex INT = -1, @country_id INT = -1, @city_id INT = -1) RETURNS @ReturnTable TABLE(-- тут поля AS BEGIN INSERT INTO @ReturnTable(-- тут поля FROM users WHERE @sex > 0 AND sex = @sex AND @country_id > 0 AND sex = @sex AND @country_id > 0 AND sex = @sex; RETURN; END; I call accordingly
SELECT * FROM GetPeople (1234567,DEFAULT,DEFAULT,DEFAULT)
-1you won't get@sex > 0- teran((@sex = -1) OR (sex = @sex)) ... AND ..- teran