Avatar of Simon Green
Simon Green
 asked on

SQL Query Needed

Hi Experts!

Hope somebody could possibly help here? Im no SQL Expert and pulling my hair out trying to find an answer!

We have a SQL Database which has a Link Database to Google BigQuery. On the SQL Server I can run the following query which returns all the data.

SELECT * FROM OPENQUERY([BQ], 'SELECT * FROM dataviews.salesdata')

What I would like to be able to do is import all this data into a table in our SQL Database called SalesData.

I only want to insert the fields that have changed though (or don't exist).

Could somebody possibly help me with a SQL Statement

Thanks in advanced for any Help offered!
DatabasesMicrosoft SQL ServerSQL

Avatar of undefined
Last Comment
Mark Wills

8/22/2022 - Mon
SOLUTION
Mark Wills

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
arnold

Echo Mark's suggestion to bring the data on board where direct subsequent queries can be run.

Your question does not include enough detail dealing with logic, business process on whose basis the data you want versus the data you don't.

You further seem to be looking at comparing data  ........
An update using join to compare, update.

A sample illustration of data from one and sat from the other describing what the resulting data would look like, might help clarify your need and what the possible solution might be.
SOLUTION
Scott Pletcher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Simon Green

ASKER
Hi All!

Many thanks for everyones response.

To answer some of the questions ...

Mark Wills - Yes, SalesData Table already exists and is like for like on what will come from the BQ Query.
                      Table has the following Feilds
                      Data_1
                      Data_2
                      Data_3
                      Data_4
                      Data_5
                      Data_6
                      Data_7
                      Data_8
                      Data_1 is always Unique                    

Scot Pletcher - BigQuery seems to be a Royal PITA. I don't think at present (Maybe wrong) you can check for changes in the last x minutes.

Basically anything in the DB within BigQuery could change except Coloum_1 (Data_1)

The aim is to have onsite SQL with the data in. People will then query the SQL Box onsite. We have some site which have extremely low bandwidth and pulling the data live is just becoming un-workable.

Cheers!
ASKER CERTIFIED SOLUTION
Mark Wills

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck