SSIS Datetime Variable perfoming >= instead of >

The source table has timestamp column (Modified Date), which gets upated with each modification via an update trigger.

I store the MAX(modifieddate) in a DeltaExtractionHistory Table in the staging database for each extraction or package execution. Then in the next run, I need to pick the coulmns that have a greater datetime, than the last extracted MAX(ModifiedDate) in the DeltaExtractionHistory table for delta processing.

The OLEDB source has the following SQL statement:

SELECT * FROM [dbo].[MyTable] WHERE [ModifiedDate] > ?

with the following parameter:

Parameter 0 : dtLastModifiedDate

dtLastModifiedDate is an SSIS variable of type Datetime. I read the value of MAX(ModifiedDate) in this variable in a SQLExecuteTask prior to running the data flow task that contains the OLEDB source task.

The problem is - instead of extracting greater datetime, it also extracts the MAX(Modifieddate), which was already extracted in the last run. In other words instead of functioning as [ModifiedDate] > ?, it is functioning as [ModifiedDate] >= ?

because of this, the primary key gets violated on the target table. I think this is happening because the date is stored as "2007-03-01 11:56:34.550" in the table, but SSIS variable shows it in the data viewer as "01/03/2007 11:56:34 PM". It truncates the milliseconds and picks the same date again, because it thinks milliseconds .550 is greater than 000. But I am not 100% sure, may be it is only showing this in the dataviewer, but it contains the ms part as well. I tried using

SELECT * FROM [dbo].[MyTable] WHERE [ModifiedDate] > ? AND DATEPART(ms, MODIFIEDDATE) > DATEPART(ms, ?)

But it fails with an error that the provider was not able to parse the SQL and try storing the statement in the SQL variable. I could not succeed in that - the statement never parses with the parameters.

Can someone please help in this.

Thanks

[1985 byte] By [Gary8877] at [2008-1-4]
# 1

IF the database a SQL Server database? if so, the problem is not SSIS; is the DB engine. from BOL ( http://msdn2.microsoft.com/en-us/ms187819.aspx )

datetime values are rounded to increments of .000, .003, or .007 seconds, as shown in the following table.

Example Rounded example

01/01/98 23:59:59.999

1998-01-02 00:00:00.000

01/01/98 23:59:59.995,

01/01/98 23:59:59.996,

01/01/98 23:59:59.997, or

01/01/98 23:59:59.998

1998-01-01 23:59:59.997

01/01/98 23:59:59.992,

01/01/98 23:59:59.993, or

01/01/98 23:59:59.994

1998-01-01 23:59:59.993

01/01/98 23:59:59.990 or

01/01/98 23:59:59.991

1998-01-01 23:59:59.990

I don't know if there is any work around to this; but you may want to ask in the database engine forum.

RafaelSalas at 2007-10-3 > top of Msdn Tech,SQL Server,SQL Server Integration Services...
# 2
Thanks Rafael.
Gary8877 at 2007-10-3 > top of Msdn Tech,SQL Server,SQL Server Integration Services...
# 3

I just ran into the very same problem and found a solution. The problem is that the DateTime in SSIS is not the same as DateTime in SQL Server 2005. It is truncating the milliseconds as you suspected.

So you retrieved Max(DateTime) from SQL as "1/1/2007 12:00:00.500" but it is read into an SSIS DateTime variable as "1/1/2007 12:00:00" - Not good!

The solution I used was to change the variable into a string, and change the SQL Max(DateTime) into:

Convert(varchar, Max(DateTime), 21)

The rest should work. I was using DB2 OLE DB, so I had to additionally do the following in the DB2 SQL:

where DateTime > CAST(? AS Timestamp)

Not sure if you need to do something similar on your side.

Note that if there is a possibility of the table you're doing a Max(DateTime) on being empty - a null DateTime returned for Max(DateTime) - then you'll need to do something like:

select convert(varchar, coalesce(max(CreateTimestamp), '1/1/2000'), 21) as StartTimestamp from Reports

Where 1/1/2000 is a sufficiently old datetime. If you don't do this, the package might fail (it did with DB2 OLE DB).

Hope it makes sense. Good luck.

StGeorge at 2007-10-3 > top of Msdn Tech,SQL Server,SQL Server Integration Services...
# 4
Thanks StGeorge - this was helpful and resolved the problem.
Gary8877 at 2007-10-3 > top of Msdn Tech,SQL Server,SQL Server Integration Services...
# 5

Hi!

This SQL command resolved this problem. You must store the LastModifiedDate in a SSIS datetime variable (time) and the milliseconds of the LastModifiedDate in a SSIS int32 variable (ms).

You must use this SQL statement:

SELECT *
FROM TEST_TABLE
WHERE ((Test_Timestamp > DATEADD(s, 1, ?))) OR (DATEADD(ms, -1*DATEPART(ms, Test_Timestamp), Test_Timestamp)= ? AND (DATEPART(ms, Test_Timestamp)>?) )

Parameters:
Param 0: time
Param 1: time
Param 2: ms

PETERNAGY at 2007-10-3 > top of Msdn Tech,SQL Server,SQL Server Integration Services...

SQL Server

Site Classified