dbTalk Databases Forums  

dbaccess; insert in table2 depending to content of table1

comp.databases.informix comp.databases.informix


Discuss dbaccess; insert in table2 depending to content of table1 in the comp.databases.informix forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ralf Hackmann
 
Posts: n/a

Default dbaccess; insert in table2 depending to content of table1 - 12-10-2010 , 02:00 AM






Hallo,

I have 2 Tables

Table1 (our Articles with >30000 Records)

ArtNr
ABC
....

Table2 (This Table is emty)
ArtNr
MGK1
MGK2
MGK3
....

I must fill Table2 for all Articles with the dollowing conditions
ABC=A => MGK1=1
ABC=B => MGK1=2
ABC=C => MGK1=3

How do I have to create my sql Script in dbaccess?
If I make an insert, what must I do with the other fields of Table2,
mus I fill them with 0, so that they are initialices?

Greetings

Ralf

....

Reply With Quote
  #2  
Old   
Ian Goddard
 
Posts: n/a

Default Re: dbaccess; insert in table2 depending to content of table1 - 12-10-2010 , 04:43 AM






Ralf Hackmann wrote:
Quote:
Hallo,

I have 2 Tables

Table1 (our Articles with >30000 Records)

ArtNr
ABC
...

Table2 (This Table is emty)
ArtNr
MGK1
MGK2
MGK3
...

I must fill Table2 for all Articles with the dollowing conditions
ABC=A => MGK1=1
ABC=B => MGK1=2
ABC=C => MGK1=3

How do I have to create my sql Script in dbaccess?
If I make an insert, what must I do with the other fields of Table2,
mus I fill them with 0, so that they are initialices?

INSERT INTO table2(artnr, mgk1)
SELECT artnr, 1
FROM table1
WHERE abc="A"

and then repeat this for the other values of ABC and MGK1. Note that
table and column names are case-insensitive.

This assumes that
(a) the other columns of table2 allow nulls and
(b) the software that reads table2 doesn't expect non-null values.

You need to find out for yourself whether these assumptions are true.
If need to set the other columns then the SQL becomes:

INSERT INTO table2(artnr, mgk1, mgk2, mgk3)
SELECT artnr, 1, 0, 0
FROM table1
WHERE abc="A"

--
Ian

The Hotmail address is my spam-bin. Real mail address is iang
at austonley org uk

Reply With Quote
  #3  
Old   
Art Kagel
 
Posts: n/a

Default Re: dbaccess; insert in table2 depending to content of table1 - 12-10-2010 , 05:04 AM



Ralf,

insert into table2(artnr, mgk1)
select artnr, case abc when 'A' then 1 when 'B' then 2 when 'C' then 3 end
from table1;

If the remaining columns in table2 accept NULLs or have DEFAULT clauses in
their definitions, then this will work, otherwise you will have to provide
some reasonable value for those columns to the INSERT in the SELECT clause.

Art

Art S. Kagel
Advanced DataTools (www.advancedatatools.com)
IIUG Board of Directors (art (AT) iiug (DOT) org)
Blog: http://informix-myview.blogspot.com/

Disclaimer: Please keep in mind that my own opinions are my own opinions and
do not reflect on my employer, Advanced DataTools, the IIUG, nor any other
organization with which I am associated either explicitly, implicitly, or by
inference. Neither do those opinions reflect those of other individuals
affiliated with any entity with which I am affiliated nor those of the
entities themselves.



On Fri, Dec 10, 2010 at 3:00 AM, Ralf Hackmann <ralf.hackmann (AT) gmail (DOT) com>wrote:

Quote:
Hallo,

I have 2 Tables

Table1 (our Articles with >30000 Records)

ArtNr
ABC
...

Table2 (This Table is emty)
ArtNr
MGK1
MGK2
MGK3
...

I must fill Table2 for all Articles with the dollowing conditions
ABC=A => MGK1=1
ABC=B => MGK1=2
ABC=C => MGK1=3

How do I have to create my sql Script in dbaccess?
If I make an insert, what must I do with the other fields of Table2,
mus I fill them with 0, so that they are initialices?

Greetings

Ralf

...


_______________________________________________
Informix-list mailing list
Informix-list (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list

Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.