• @charles

    Check this query out - I am sure this will be lot faster than your dynamic one AND this allows use of variables in the WHERE clause which do not need to be passed as well. This is just to give you an idea how you can do without dynamic queries.

    SELECT C.CustomerID AS CUSTOMER_ID, C.CompanyName AS COMPANY_NAME,

    C.ContactName AS CO_CONTACT, C.City AS CITY, C.Country AS COUNTRY,

    C.Phone AS CUST_PHONE,

    O.OrderID AS ORDER_NUMBER,

    SUBSTRING(E.FirstName,1,1) + char(32) + E.LastName AS ORDER_ENTERED_BY

    FROM CustomersC

    JOINOrdersOon C.CustomerID = O.CustomerID

    JOINEmployeesEon O.EmployeeID = E.EmployeeID

    WHERE (C.Country= ' + QUOTENAME(@Country, '''') OR @Country = '')

    AND (E.LastName LIKE '%' + QUOTENAME(@Employee, '''') OR @Employee = '')

    ORDER BY COMPANY_NAME

    Also another pointer - dont use LIKE operator with % at the begining of the search pattern - this will cause a table/index scan and hamper query's performance. Instead use CONTAINS function that works along with Fulltext indexing i.e. MS Search Engine.

    Cheers

    Randeep