Solved

Dynamically updating Table from query result in sql server 2005

Posted on 2011-09-20
4
212 Views
Last Modified: 2012-05-12
Hi,
I have an existing table in sql server 2005 database
Id (int, not null)
LoadDate (datetime, null)
Client  (nvarchar,null)
Location (nvarchar, null)
 client tableI want to update this table dynamically using the results of the following query;

Select  client Location
From RawData.NewData

The ID value to be incremented and the LoadDate value to be the date when the query is fired.

any help appreciated..Thanks
0
Comment
Question by:blossompark
  • 2
4 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 total points
ID: 36566041
0
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 400 total points
ID: 36566109
insert into [client table]
(loaddate,client,location)

Select  getdate(),client, Location
From RawData.NewData
where not exists (select client from [client table] as x where x.client=rawdata.newdata.client
 and x.location=rawdata.newdata.location)
0
 

Author Comment

by:blossompark
ID: 36566165
Hi angelII,  thanks for the link
Hi Lowfatspread, thanks for that, trying now, will update when complete
0
 

Author Closing Comment

by:blossompark
ID: 36566251
Hi AngelII, great info there that i will need to study, thank you...

Hi Lowfatspread, thanks for your input , table has loaded with the data.
I used the following code only for my requirement;
insert into [client table]
(loaddate,client,location)
Select  getdate(),client, Location
From RawData.NewData

I'm assuming
where not exists (select client from [client table] as x where x.client=rawdata.newdata.client
 and x.location=rawdata.newdata.location)

is to prevent duplicate combinations of  client/location from being entered into the client table?

If that is the case that is not a concern in this instance...
as the LoaDate/Client/Location is what needs to be unique
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Query Peformance + mulitple query plans 9 54
Oracle SQL - Query help 7 54
Mysql Left Join Case 10 49
Connection to multiple databases 13 18
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question