0
votes

I am trying to insert a line into TABLE1 from a select from TABLE2. The problem is that one field from TABLE2 is longer than the field in TABLE1. Can I "crop" it and insert just the maximum field length into the target table?

INSERT INTO TABLE1
  SELECT ACT, PROD, DESCRIPTION, ADDRESS FROM TABLE2

In table2 DESCRIPTION field is 35 characters long, whereas in the first one it has only 30.

Many thanks!

1
Use LEFT(DESCRIPTION,30)Wocugon
if LEFT, then LEFT(DESCRIPTION,30) - see my answerdata_henrik
Column, not field.jarlh

1 Answers

2
votes

Why not apply SUBSTR to DESCRIPTION? Untested:

INSERT INTO TABLE1
  SELECT ACT, PROD, SUBSTR(DESCRIPTION,1,30), ADDRESS FROM TABLE2

That is the same as using LEFT with length 30:

INSERT INTO TABLE1
  SELECT ACT, PROD, LEFT(DESCRIPTION,30), ADDRESS FROM TABLE2