• There are 2 problems with your code. You cannot concat datetime data type with varchar data type, so you need to convert your parameters to varchar data type (using convert or cast functions). The second problem is that you need to put apostrophes around the dates. The code bellow shows how to do that. Notice also that your code has the potential to be vulnerable to SQL injection

    declare @StartDate datetime = '20000101'

    declare @EndDate datetime = '20140901'

    declare @sqlquery varchar(200)

    set @sqlquery = 'select * from sys.objects where create_date > '''

    + cast(@StartDate as varchar(20)) + ''' AND create_date < ''' + cast(@EndDate as varchar(20))+ ''''

    select @sqlquery

    exec(@SQLQuery)

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/