Q:

Ignore other results if a resultset has been found

To start, take this snippet as an example:
SELECT * 
FROM StatsVehicle 
WHERE ((ReferenceMakeId = @referenceMakeId)
 OR @referenceMakeId IS NULL)

This will fetch and filter the records if the variable @referenceMakeId is not null, and if it is null, will fetch all the records. In other words, it is taking the first one into consideration if @referenceMakeId is not null.
I would like to add a further restriction to this, how can I achieve this?
For instance
(ReferenceModelId = @referenceModeleId) OR
(
    (ReferenceMakeId = @referenceMakeId) OR
    (@referenceMakeId IS NULL)
)

If @referenceModelId is not null, it will only need to filter by ReferenceModelId, and ignore the other statements inside it. If I actually do this as such, it returns all the records. Is there anything that can be done to achieve such a thing?

A:

Maybe something like this?
SELECT * FROM StatsVehicle WHERE 
( 
    -- Removed the following, as it's not clear if this is beneficial
    -- (@referenceModeleId IS NOT NULL) AND 
    (ReferenceModelId = @referenceModeleId)
) OR
(@referenceModeleId IS NULL AND 
 (
    (ReferenceMakeId = @referenceMakeId) OR
    (@referenceMakeId IS NULL)
 )
)

