|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > SQL query to update existing records and insert new |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|