Your question is incomprehensible, so I see two results that you may wish to achieve.
The first depends only on the countryID . Therefore, if countryID is -1, do not select any entry:
IF you do not have a countryID that is -1, then you can use this simple choice, because if @countryID = -1 nothing will return (due to AND), and if not, 1, then the necessary records will return:
SELECT * FROM dbo.bbmf WHERE status=1 AND ( countryId=@countryId )
(In addition to the first solution, if you have a country with id = -1, you should change AND ( countryId=@countryId ) To AND ( countryId=@countryId AND @countryId <> -1) )
The second is that if countryId = -1 , you only need to check the status and get each record using status = 1 , then you should use this statement:
SELECT * FROM dbo.bbmf WHERE status=1 AND (countryId = -1 OR countryId = @countryId)
source share