Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle 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 June 17th, 2009, 08:25 AM
jesss jesss is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 2 jesss User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 12 sec
Reputation Power: 0
Update statement issue

Hi

I am trying to write an update statement which updates the User IDs in one table with the User IDs in another table. However I need to update statement to ignore any duplicates that are in the tables.

Does anyone know how to do this?

Thank you


Jesss

Reply With Quote
  #2  
Old June 17th, 2009, 01:34 PM
jzd's Avatar
jzd jzd is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2007
Posts: 933 jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 14 h 13 m 6 sec
Reputation Power: 792
You are leaving something out. Are you updating users from one table to another based on User Id or are you actually changing the Ids? Which table might have duplicates?

What do you have so far?

Bigger question, why do you have duplicate information, sounds like you need to get rid of one set and just JOIN in your queries.

Reply With Quote
  #3  
Old June 17th, 2009, 01:52 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,687 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 9 h 27 m 54 sec
Reputation Power: 2458
which database system is this? you may have some options in the sql syntax available to you

for example, mysql has INSERT IGNORE ...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #4  
Old June 18th, 2009, 03:15 AM
jesss jesss is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 2 jesss User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 12 sec
Reputation Power: 0
Thank you replying

I am using an Oracle database. I sorry i got in wrong what we are actually tryign to do is update the User Ids in one table with the user IDs which are stored in a variable.

The table we need to update has two columns User Id and Permit ID but it has duplicate data, however we for some reason need to update the data first then delete the duplicates. So Far i created an update statement which updates the User IDs however it keeps giving an error message about the duplicates. So far we have:
UPDATE tblRoomsUsers
SET UsrId=@NewID
FROM tblRoomsUsers t1 LEFT JOIN tblRoomsUsers t2 ON t1.UsrId = t2.UsrId
tblRoomsUsers t1 LEFT JOIN tblRoomsUsers t2 ON t1.permit_id = t1.permit_id
WHERE UsrID=@OldId
AND NOT UsrId IN (SELECT UsrID
FROM tblRoomsUsers WHERE
DelUsrId=@NewID)

SET @count=@@rowcount
IF NOT (@count=0)
BEGIN
PRINT ' FAILED'
SELECT @errorencountered=1
SELECT @errormessages=@errormessages + 'Error updating Room Users table. '
END

Do you know of any way to get this statement to ignore the duplicates in th table?

Thank you


Jessica

Reply With Quote
  #5  
Old June 18th, 2009, 07:33 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,687 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 9 h 27 m 54 sec
Reputation Power: 2458
moved to oracle forum
Comments on this post
LKBrwn_DBA disagrees: SQL posted by OP is NOT Oracle.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Update statement issue


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 2 Hosted by Hostway
Stay green...Green IT