Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

SQL query to insert non existance data

I am exporting data from Google analytics to SQL database, while exporting data get duplicated if I the program runs many time in the same date range. luckily I can run the canvas of Google analytics data according to an SQL command. how can I write a query that input data from Google analytics if same  "date" was not existing because "date" is the only unique attribute in all the tables.
For instance when I run the program on 17-07-2014 it will go through the database tables check if the same date exist "17-07-2014" then nothing will happened but if it wasn't there new data will be inserted

Thank you
0
Rawan Jambi
Asked:
Rawan Jambi
1 Solution
 
HuaMinChenBusiness AnalystCommented:
You can use cursor with loop to check each record. Read
cursor
While loop
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Not knowing the structure of the tables, your query should be something like:
INSERT INTO TableName
SELECT *
FROM GoogleTable
WHERE NOT EXISTS (SELECT 1 FROM TableName T2 WHERE T2.DateColName = GoogleTable.DateColName)

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now