Question : CAST DATETIME2 to DATETIME

I am having the worst time with this... lord knows what I'm missing.
v2008,  have a very critical solution driven procedurally across the data layer.  it traverses mutliple servers, basically doing reconcilation on demand.  if/when it is needed, it is business critical.  

recently i began upgrading my v2000 servers to v2008.  I'm about half way there -- so this reconciliation logic traverses both v2000 and v2008.  

one of the ups of v2008, of course, is the improved precision with DATETIME2.   my v2008 databases are using DATETIME2 in the timefield.  in retrospect, I should have left it at DATETIME until all my boxes were upgraded.  then i could have converted.

for the most part, there are no problems with the new datetime datatype.  invisibile to the front end.   but it's becoming a problem with this reconciliation solution.  here's the short story

- i create a discrepancy  (basically, delete a trade)
- i then run my finder proc, it finds it, and attempts to write it into a working table
- that write fails with 'Syntax error converting datetime from character string.'
- the datasource in this particular scenario is v2008, the timefield is DATETIME2
- the working table within which this write fails is DATETIME.  i cannot change it, however, because that box is still v2000.  

i MUST have a workaround like yesterday.  whatever workaround i put into place is only temporary --- it will not be an issue when the upgrade is complete.  the timefield in question will be DATETIME2 across the board.

in between now and then, is there not an easy way to strip those last three digits off my datestring and pump it from v2008 DATETIME2 into v2000 DATETIME?

i want this:   2009-07-09 08:45:00.0000000
to be this:   2009-07-09 08:45:00.000

how the heck hard can that be.  
i tried the code below, it returns properly in the select, but every insert from v2008 DATETIME2 into v2000 DATETIME fails w/the error:
'Syntax error converting datetime from character string.'

seriously important.  any input is greatly appreciated
Code Snippet:
1:
2:
3:
4:
IF(@start IS NULL)
DECLARE @start2 DATETIME
SELECT @start2 = MAX(timefield) FROM v2008Server.database.dbo.table 
SET @start = @start2

Answer : CAST DATETIME2 to DATETIME

That should work as the issue is probably the extra digits of precision on datetime2 aren't allowing it to be parsed correctly.

Try this to verify.  If works, should work on insert too.

select convert(datetime, convert(varchar(23),timefield,121), 121)
Random Solutions  
 
programming4us programming4us