The EVENT_DATE field has a datatype of datetime in all the relevant tables, and the fields EVENT_ID and CARE_ID are integers, but I get an error. Username is a varchar. How do I get round this?Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query.
INSERT INTO newNBOCAP_CARE_PLANS_WITHSELECT CARE_ID, MAX(EVENT_DATE) AS EVENT_DATE, MAX(EVENT_ID) AS EVENT_ID, Username FROM(SELECT i.CARE_ID, EVENT_DATE, EVENT_ID, Username FROM newNBOCAP_CARE_PLANS iJOIN(SELECT CARE_ID, MIN(EVENT_DATE) FirstTRDateFROM newNBOCAP_CARE_PLANSWHERE EVENT_TYPE IN ('BR','CH','TE','SU')GROUP BY CARE_ID) FirstTPON FirstTP.CARE_ID = i.CARE_IDWHEREi.EVENT_TYPE = 'CARE_PLAN' ANDi.EVENT_DATE <= FirstTP.FirstTRDate) aGROUP BY CARE_ID, Username