• The following runs without error on my system. I had to correct some errors in the code provided.

    You will want to run the following in a sandbox database first as I do create and drop the parameter_value table.

    --Example Data values (key_value):

    create table dbo.parameter_value (

    pvid int identity(1,1),

    datatype char(1),

    key_value varchar(64)

    );

    insert into dbo.parameter_value(datatype, key_value)

    values

    ('D','2013-10-29 22:59:00Z'),

    ('D','2013-04-25 23:59:00Z'),

    ('D','2013-03-06 22:59:00Z'),

    ('D','2013-03-06 22:59:00Z'),

    ('D','2013-03-06 22:59:00Z'),

    ('D','2013-03-29 22:59:00Z'),

    ('D','2013-03-06 22:59:00Z'),

    ('D','2013-04-27 23:59:00Z'),

    ('D','2013-03-06 22:59:00Z'),

    ('D','2013-04-03 23:59:00Z');

    go

    SELECT TOP 10 key_value

    ,convert(datetime2,PV.key_value) as DT2

    ,convert(datetime,CONVERT(DATETIME2, PV.key_value)) AS DT

    FROM parameter_value PV

    WHERE PV.datatype = 'D';

    go

    SELECT TOP 10 key_value

    ,convert(datetime2,PV.key_value) as DT2

    ,convert(datetime,CONVERT(DATETIME2, PV.key_value)) AS DT

    FROM parameter_value PV

    WHERE PV.datatype = 'D'

    and convert(datetime,CONVERT(DATETIME2, PV.key_value)) BETWEEN GETDATE() and DATEADD(d, 10, GETDATE())

    go

    drop table dbo.parameter_value;

    go