Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird 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 July 15th, 2005, 01:58 PM
frrobert frrobert is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 38 frrobert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 52 m 45 sec
Reputation Power: 4
proper syntax for update query

I am trying to write an update query and I am having problems with
the firebird syntax.

The query involves 2 tables that are identical in structure but one
has updated data from another database


I want to match up the keys then update the data from the one table
to the second table

An example that works in a Access but not in firebird is as follows

Code:
UPDATE Contacts INNER JOIN Contacts1 ON Contacts.ContactID =
Contacts1.ContactID SET Contacts.FirstName = Contacts1.FirstName,
Contacts.LastName = Contacts1.LastName;


What would be the proper syntax for Firebird.

Thanks,

Fr. Robert

Reply With Quote
  #2  
Old July 16th, 2005, 12:47 PM
irie irie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Hamburg - Germany
Posts: 61 irie User rank is Private First Class (20 - 50 Reputation Level)irie User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 h 29 m 50 sec
Reputation Power: 7
this way you'll succeed:

Code:
UPDATE Contacts C
   SET C.FirstName=(SELECT C1.FirstName FROM Contacts1 C1
                     WHERE C.ContactsID=C1.ContactsID),
       C.LastName==(SELECT C1.LastName FROM Contacts1 C1
                     WHERE C.ContactsID=C1.ContactsID)


Lutz

--
web based Firebird and InterBase administration: http://www.ibwebadmin.net
__________________
web based Firebird and InterBase administration: http://ibwebadmin.sf.net

Reply With Quote
  #3  
Old July 18th, 2005, 09:20 AM
frrobert frrobert is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 38 frrobert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 52 m 45 sec
Reputation Power: 4
I tried the above syntax for some reason I had to refer to the first table in the select statement. The statement generates another error
multiple rows in singleton select.

It seems the syntax only works if you want to update one record.

What syntax would you use if you had multiple records to update?

Thanks,

Fr. Robert

Reply With Quote
  #4  
Old July 18th, 2005, 01:30 PM
irie irie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Hamburg - Germany
Posts: 61 irie User rank is Private First Class (20 - 50 Reputation Level)irie User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 h 29 m 50 sec
Reputation Power: 7
No, the syntax is working for multiple records. The 'multiple rows in singleton select' error means that the query fails because the subquery returns more than one value for a distinct record. It will work if you make sure that the subqueries return exact one value for every row.

Lutz

--
web based Firebird and InterBase administration: http://www.ibwebadmin.net
Comments on this post
pabloj agrees!

Reply With Quote
  #5  
Old July 25th, 2005, 02:49 PM
frrobert frrobert is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 38 frrobert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 52 m 45 sec
Reputation Power: 4
Thanks got it to work.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > proper syntax for update query


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 5 hosted by Hostway