MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 12th, 2004, 01:11 PM
dwan dwan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 4 dwan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
simple query help?

Hi,

I hope this is an ok place to ask a very basic question, as I find myself in a position to need to write queries suddenly with no training or experience writing queries.

What I am trying to accomplish is this: A new pricing spreadsheet came from the manufacturer, I imported that info into an sql table in the database. Now I want to write a query that will look at my new table, compare it to an existing table and update any new or changed information in the existing table.
Below is what I have come up with so far, but I'm not even sure if I am on the right track. Any help at all would be appreciated.

Update IV00101
From Big_Boy2
Where IV00101.ITEMNMBR = Big_Boy2.SKU
where IV00101.GEDESC = BIG_BOY2.MANUFACTURER
where IV00101.currcost = big_boy2.netprice
where IV00101.stndcost = big_boy2.sellprice
where IV00101.itemdesc = big_boy2.descript


Thanks,

dwan

Reply With Quote
  #2  
Old January 12th, 2004, 04:27 PM
dwan dwan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 4 dwan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am learning slowly but surely. If they want me to do this I am going to need a good tutorial. Can anyone suggest a good one at a decent price?

With reguard to the above question, am i on the right track thinking I need to use an inner join statement?

Thanks in advanca for any help!

Dwan

Reply With Quote
  #3  
Old January 12th, 2004, 05:08 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 50 m 52 sec
Reputation Power: 9
--Insert
Insert into currTable
SELECT *
FROM oldTable
where oldTable.primaryKey NOT IN(SELECT currTable.primaryKey
FROM currTable)

--Update
update currTable
set currTable.col1 = newTable.col1
where currTable.primaryKey = newTable.primaryKey

--How are you handling deletes?
__________________
El éxito consiste en una serie de pequeñas victorias día a día

MySQL, MS SQL, MS ACCESS, Oracle Database Manager - http://victorpendleton.net/products/psdviewer.html

Last edited by victorpendleton : January 13th, 2004 at 09:06 AM.

Reply With Quote
  #4  
Old January 13th, 2004, 09:03 AM
dwan dwan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 4 dwan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
There should not be too many to delete. I am going to run a compare script and then just manually delte the few that turn up. Thank you so much for your help!
dwan

Reply With Quote
  #5  
Old January 13th, 2004, 09:05 AM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 50 m 52 sec
Reputation Power: 9
Did this SQL work for you?

Reply With Quote
  #6  
Old January 13th, 2004, 09:23 AM
dwan dwan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 4 dwan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
it almost worked! Insert did, Update did not. However I think I got it using this:

update IV00101
set IV00101.col1 = BIG_BOY2.col1

From IV00101, BIG_BOY2
where IV00101.primaryKey = BIG_BOY2.primaryKey



but am just now getting ready to test. I will let you know how it goes.

Thanks,

dwan

Reply With Quote
  #7  
Old January 13th, 2004, 10:12 AM
jstrohofer jstrohofer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Cincinnati, OH USA
Posts: 111 jstrohofer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 3 sec
Reputation Power: 6
You won't really want to use the FROM statement in your update.

You'll probably want something more along these lines:

update IV00101
set IV00101.col1 = BIG_BOY2.col1
where IV00101.primaryKey = BIG_BOY2.primaryKey

Good luck!

-- Jill

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > simple query help?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT