I want this query to insert all the distinct webshop dates in to the second table if they do not already exist for the webshop DataSets
The following query seems to ignore the AND t1.[DataSet] = 'webshop' parameter and not insert the new webshop values as they contain the same date ranges ie. they both contain 01/02/2013
INSERT INTO [ImportedDateRange] ([DataSet],[DateRange]) select DISTINCT 'webshop', cast(T2.[OrderCreatedDate] as DATE) from webshop T2 left join [ImportedDateRange] T1 on cast(T2.[OrderCreatedDate] as DATE) = t1.[DateRange] where t1.[DateRange] is null AND t1.[DataSet] = 'webshop' The desired result is that it inputs the webshop date ranges only if they don't already exist for webshop (this prevents duplicate data if the query is run twice)
DataSet DataRange business 01/02/2013 business 02/02/2013 business 03/02/2013 webshop 01/02/2013 webshop 02/02/2013 webshop 03/02/2013