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 August 20th, 2004, 10:41 AM
lauramccord lauramccord is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 180 lauramccord User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 3 m 58 sec
Reputation Power: 5
SQL query to update existing records and insert new

I am trying to come up with a query for ms sql to update any existing records but insert any new records.

The complexity is that I am writing a perl program that involve hashes within hashes.

Here is sample code of what some of my queries look like. This piece right now updates existing records that have a SystemNetName = ... and now I need to include inserting new records that also have SystemNetName = ... :

sub updateTest{
foreach my $table(keys %$HoH){
foreach my $field(keys %{$HoH->{$table}}){
if($table eq "CPU"){
my $CPUstatement = "Update CPU Set Name = '$HoH->{CPU}{$field}{Name}',
MaxClockSpeed = '$HoH->{CPU}{$field}{MaxClockSpeed}'
Where SystemNetName = '$HoH->{Host}{SystemNetName}' AND
CPUNumber = '$field'";

print "$CPUstatement\n";
if ($db->Sql($CPUstatement))
{
print "Error on SQL INSERT\n";
Win32::ODBC:umpError();
}
else
{
print "insert successful\n";
}
}
}
}
}

Any help will be appreciated

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > SQL query to update existing records and insert new


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


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





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