• I believe you can write this query without using DYNAMIC SQL. but the only part that confuses me is @CID. You specified it as integer, and you are passing a name to it.

    You can write something like this

    SELECT *

    FROM [Transaction]

    WHERE Transdt BETWEEN CONVERT(VARCHAR (10),@transfrmdt,111) AND CONVERT(VARCHAR (10),@transtodt,111)

    AND (@Cid IS NULL OR Cid = @cid)

    AND (NULLIF(@Type, '') IS NULL OR [Type] = @Type)

    Good Luck 🙂 .. Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.