You should either use COALESCE or use the IS NULL approach.CREATE PROCEDURE spocsearch ( @nm nvarchar(30), @ID nvarchar(7), @custid nvarchar(10))ASSELECT nm, ID, custid, custcodeFROM iTrnsWHERE ID = COALESCE(@ID, ID) AND nm = COALESCE(@nm, nm) AND custid = COALESCE(@custid, custid)
or thisCREATE PROCEDURE spocsearch ( @nm nvarchar(30), @ID nvarchar(7), @custid nvarchar(10))ASSELECT nm, ID, custid, custcodeFROM iTrnsWHERE (ID = @ID OR @ID IS NULL) AND (nm = @nm or @nm is null) AND (custid = @custid or @custid is null)
E 12°55'05.25"N 56°04'39.16"