• You're welcome Vishal. But looking at your "working" example, what you are doing isn't really dynamic SQL at all. You are assigning a long string value to your @WHERE_CLAUSE variable and then just eliminating the equal sign and everything to the left. The " Customer_ID = " isn't necessary at all in the value of @WHERE_CLAUSE. The actual test against the customer column is being done expressly in your where clause, not dynamic at all. You might as well just start out assigning it a value of 8.

    DECLARE

    @CUSTID VARCHAR(20) = '0000000008'

    SELECT *

    FROM dbo.TEST AS C

    WHERE CUSTOMER_ID = isnull(@CUSTID,1)

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills