?
Solved

Convert SQL to Interbase

Posted on 2003-02-25
7
Medium Priority
?
392 Views
Last Modified: 2013-12-09
I have a SQL statement which I need to convert to work with Interbasse:

UPDATE Table1 SET Table1.AField = Table2.AField FROM Table1 INNER JOIN Table2 ON Table1.FieldID = Table2.FieldID WHERE Table1.AField IS NULL OR Table1.AField = ''

the query updates a field in table 1 from the same field in table 2 only on records where table 1 does not already have data populated in that field
0
Comment
Question by:SharonBrindley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
BAlexandrov earned 200 total points
ID: 8023624
Infortunatelly this is not standart ANSI SQL and IB does not support it.
Alternative is:

UPDATE Table1
SET Table1.AField =
 (Select Table2.AField
  FROM Table2
  WHERE Table2.FieldID = Table1.FieldID)
Where
 Exists(Select 1
        FROM Table2
        WHERE Table2.FieldID = Table1.FieldID) and
 (Table1.AField IS NULL OR Table1.AField = '')

This is more easy done in Stored procedure. If you are not familiar with that - ask again.


0
 
LVL 1

Expert Comment

by:vogonPoet
ID: 8039783



 UPDATE Table1 SET Table1.AField =

 ( select Table2.AField
   FROM Table1 INNER JOIN Table2
   ON Table1.FieldID = Table2.FieldID )

 WHERE Table1.AField IS NULL OR Table1.AField = ''


Pseudo - SQL :

update all rows in Table1  where AField is null OR AField is empty string.

Table1.AField gets the value of Table2.AField where there is one row that matches FieldID between both.

The relationship between 'Table1.FieldID = Table2.FieldID'
must be 1 to 1, or you'll may probably get a "multiple rows in a singleton select" error.

I see that  BAlexandrov has recommended a stored procedure, which is probably the best way to handle it in a controlled manner.

Good Luck!
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 8039863
As you(vogonPoet) have wrote:

UPDATE Table1 SET Table1.AField =
( select Table2.AField
  FROM Table1 INNER JOIN Table2
  ON Table1.FieldID = Table2.FieldID )

And if we have the case that in Table1.AField = '' but there is no data in Table2 either to what value will be set
Table1.AField if the inner select does not return nothing?
May be it will become null, there was a case in IB 6.2 that when you join with stored procedure that does not return nothing it causes server to restart...
For this reason I have added the second select in the where clause that checks if there is data in table2.
0
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
LVL 1

Expert Comment

by:vogonPoet
ID: 8042515
Good point, BAlexandrov.

I was looking at it much too late at night.
0
 
LVL 10

Expert Comment

by:kacor
ID: 9795403
Hi SharonBrindley,

if you got the needed answer, please accept it by clicking on Accept in the header of the good answer. By this way you can express thanks for expert's support

with best regards

Janos
0
 
LVL 10

Expert Comment

by:kacor
ID: 9830238

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to accept BAlexandrov's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

kacor
EE Cleanup Volunteer
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question