• is this a subset of a larger script? why the dynamic SQL?

    also, since you drop and recreate the table every time, why not a temp table?

    why create the table in advance? why not just use INSERT ... INTO and build the table on the fly completely?

    SET @InsertSQL = 'SELECT identity(int,1,1) As ID,* INTO Hosea_tempTable FROM '

    + @TableName

    + ' WHERE (Product_Id = '''

    + @Product_Id

    + ''' or Product_Id = '''') AND (Fund_Id = '''

    + @Fund_Id

    + ''' or Fund_Id is null)';

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!