Have following query:create table #PlantTable ( plant_id char(10) default ' ', plant_name char(20) default Null, shift_date datetime, outside_qty decimal(15,2) default Null, intercompany_qty decimal(15,2) default Null )Insert Into #PlantTable(shift_date, intercompany_qty, outside_qty)SELECT * FROM OPENQUERY(ADS_RGGT_SERVER, 'SELECT MAX(SHIFT_STARTED) as shift_date, SUM(CASE WHEN customer_description_1 = ''Ranger Construction Industries'' THEN qty_shipped_today ELSE 0 END) AS intercompany_qty, SUM(CASE WHEN customer_description_1 <> ''Ranger Construction Industries'' THEN qty_shipped_today ELSE 0 END) AS outside_qty FROM salestkt WHERE (void is null or void = false) and incoming_material = false and shift_started = (SELECT MAX(STK.shift_started) as shift_started FROM salestkt AS STK WHERE EXISTS(SELECT * FROM SHFTDATE AS SD WHERE SD.shift_started is not Null and SD.shift_started = STK.shift_started))')
This happens only if no records is found in the SHFTDATE table (which could be the case) and I get error in the "shift_started" field (timestamp)Error converting data type DBTYPE_DBTIMESTAMP to datetime.SALESTKT table:2/23/2010 4:08:00 PM
SHFTDATE table ( 2 records)ASTEC 5/25/2007 11:25:00 AMR (Null value)
I tried to change my query like this:MAX(CASE WHEN SHIFT_STARTED IS NOT NULL then shift_started ELSE Null end) as shift_date,
Did not help.