DECLARE @vDeptId INT SELECT Id ,CONVERT(NVARCHAR(15),OrderDate,103) OrderDate ,OrderNo ,OrderValue FROM tblHoOrder WHERE DeptId=CASE WHEN @vDeptId=0 THEN Id ELSE @vDeptId END