This example is the opposite of the one above example.
SQL 1
DECLARE @CWB_NO varchar (50)
Set @cwb_no = ' 31301379874 '
SELECT A.awb_no,
A.bwb_no,
A.cwb_no,
A.origin,
A.dest,
A.MODIFY_ON,
A.CREATED_ON,
A.consignor_customer_code,
A.consignor_code,
A.consignor_name,
A.consignee_name,
A.cwb_status,
A.cwb_type,
ISNULL (a.pcs, 0) as PCS,
A.bwblist,
B.pweight
From TB_CWB as a
Left JOIN Tb_cwbweight as B
On a.cwb_no = B.cwb_no
and b.available = ' Y '
WHERE a.available = ' Y '
and (A.cwb_no = @CWB_NO OR
((@CWB_NO is NULL)
and (a.awb_no = null OR null is NULL)
and (a.bwb_no = null OR null is NULL)
and (A.ie_type = null OR null is NULL)
and (a.created_on >= null OR null is NULL)
and (a.created_on <= null OR null is NULL)
and (a.payment = null OR null is NULL)
and (A.origin = null OR null is NULL)
and (a.dest = null OR null is NULL)
and (A.consignor_customer_code = null OR null is NULL)
and (A.consignor_name like '% ' + null + '% ' OR null is NULL)
and (A.consignee_name like '% ' + null + '% ' OR null is NULL)
and (A.cwb_type = null OR null))