Dears,I've a query that return 5000 rows.I'm insert this results in other table with this command:SET DATEFORMAT dmyINSERT INTO tbOther SELECT Name, DateAdd FROM tbCustomers WHERE (DateAdd BETWEEN CONVERT(CHAR(10), DATEADD(mm, -1, GETDATE()), 103) AND CONVERT(CHAR(10), GETDATE(), 103))
This query is executed all days, but have one problem...After 1 year, in my table tbOther, the customers that IS in table tbOther will be inserted AGAIN in this table, but I don't want that this happens.. I want UPDATE the customers that already exists in table tbOther and INSERT the new customers in table tbOther too...Ex.:[code]Data of the table tbOther:==========================| NAME | DATE ||---------|--------------|| Sergio | 30/07/1981 | ****| Pedro | 10/12/1980 ||---------|--------------|Result of my SELECT:==========================| NAME | DATE ||---------|--------------|| Sergio | 30/07/1981 | ****| Carlos | 20/01/1980 || John | 05/05/1982 ||---------|--------------|My table tbOther AFTER the SELECT (UPDATE)==========================| NAME | DATE ||---------|--------------|| Sergio | 30/07/1981 | ****| Pedro | 10/12/1980 || Carlos | 20/01/1980 || John | 05/05/1982 ||---------|--------------|In this case, the Sergio already exists in table 1, so, only need UPDATE him data..The Carlos and John, that exists in result of my query, I want INSERT in my table tbOther, understand??Thank you so much!!!!