HomeForum
Welcome, Guest

SQL function
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: SQL function

SQL function 3 years, 10 months ago #495

  • gavinm
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Karma: 0
I am evaluating VIES 7.5.6

When doing the mapping for an import you can call a SQL function against a field.
Is there anyway to do this to a SQL statement held in a file rather than a SQL function held in the DB.

Rgds
Gavin

Re:SQL function 3 years, 10 months ago #496

  • admin
  • OFFLINE
  • Moderator
  • Posts: 1931
  • Karma: 11
Hello.

Can you give us more detailed example please

What do you mean by SQL statement held in a file?

John,
Support team

Re:SQL function 3 years, 10 months ago #498

  • gavinm
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Karma: 0
Hi John

We have a delimited text data file. During the import we have to check for new records and update existing records.

During the import we have a primary key that must be incremented by one each time a new record is inserted. This can be done with a SQL function in the database. Your application would allow us to call that sql function. However it would more useful if we could call a sql script stored in a file that would do the same plus any other additional tasks. You do have a sql script area in your application but it appears to run before the improt or after the import and not during the input. I need it to run for each field that we map to a script. Is this possible?

Rgds
Gavin

Re:SQL function 3 years, 10 months ago #499

  • admin
  • OFFLINE
  • Moderator
  • Posts: 1931
  • Karma: 11
Gavin.

Somehow you need to be able to pass paramaters to

your script and it should return value as well.

So I think you have to use stored procedure/ function anyway.

can you post you sql script here please.

John

Re:SQL function 3 years, 10 months ago #502

  • gavinm
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Karma: 0
Hi John

I don;t have script. I was trying to work out the right way to do this.
This is my table I am importing to.

Column Name Data Type Nullable Default Primary Key
POHEADERID NUMBER No - 1
PROJECTCODE VARCHAR2(30) Yes - -
PURCHASEORDERNO VARCHAR2(50) Yes - -
PURCHASEORDERDATE DATE Yes - -
POISSUEDATE DATE Yes - -
CLIENTNADID VARCHAR2(30) Yes - -
COLLECTIONNADID VARCHAR2(30) Yes - -
VENDORCODE VARCHAR2(30) Yes - -
VENDORADDRESSLINE1 VARCHAR2(50) Yes - -
VENDORADDRESSLINE2 VARCHAR2(50) Yes - -
VENDORADDRESSLINE3 VARCHAR2(50) Yes - -
VENDORADDRESSLINE4 VARCHAR2(50) Yes - -
VENDORADDRESSLINE5 VARCHAR2(50) Yes - -
VENDORADDRESSLINE6 VARCHAR2(30) Yes - -
VENDORCOUNTRY VARCHAR2(50) Yes - -
VENDORCOUNTRYCODE VARCHAR2(20) Yes - -
VEDORTELNO VARCHAR2(30) Yes - -
VENDORFAXNO VARCHAR2(30) Yes - -
VENDOREMAIL VARCHAR2(50) Yes - -
SUBVENDORNADID VARCHAR2(30) Yes - -
COLLECTREF VARCHAR2(50) Yes - -
POCURRENCYCODE VARCHAR2(3) Yes - -
POGENDESC VARCHAR2(254) Yes - -
POINSPECTIONDATE DATE Yes - -
POFINALDATE DATE Yes - -
PORECEIVEDDATE DATE Yes - -
POREVISIONDATE DATE Yes - -
POREVISIONNUMBER VARCHAR2(3) Yes - -
REQUISITIONNO VARCHAR2(50) Yes - -
REQUISTIONDATE DATE Yes - -
ROSDATE DATE Yes - -
SHIPPERNADID VARCHAR2(30) Yes - -
POTERMS VARCHAR2(30) Yes - -

POHeader_ID is the primary key and is not null. Our application calculates the unique reference so the is no sequence I can call on. The delimeted text file I am trying to import has no mapping to POHEADERID. So on data import I have to check to see if PURCHASEORDERNO exits then update the row and if PURCHASEORDERNO does not exist then I have to get the max value of POHEADERID increment by 1 and insert new row. Of course this needs to be tested for each row. Apart from this issue I can see that VIES will be good for us.

I have attched a screenshot of VIES with the table and mapping for you.

Re:SQL function 3 years, 10 months ago #503

  • admin
  • OFFLINE
  • Moderator
  • Posts: 1931
  • Karma: 11
OK.

I understand now what you are trying to achieve.

There are two ways of doing it


Number one

Create two import scripts
First script will update existing data (Transformation=Update Records)

Second one will add new records. (Transformation=Add new Records)

enter following sql in SQL Before for second script

VARIABLE x NUMBER
BEGIN
select max ( POHEADERID ) into : X from yourtable;
execute immediate 'create sequence tmp_seq start with '||to_char( : X );
END;
/


and enter


drop sequence tmp_seq;

in SQl after.

than for POHEADERID field set mapping type to sql function and type tmp_seq.nextval

This way will work if you allowed to create sequences in your database and nobody is adding records to the database except you.

Number two

Create two import scripts
First script will update existing data (Transformation=Update Records)

Second one will add new records. (Transformation=Add new Records)

You must use ODBC connection for second script.


For second script, for POHEADERID field set mapping type to sql function and type (select max(POHEADERID)+1 from yourtable)

Second way is slower than first one.

Let us know the outcome

John
  • Page:
  • 1
  • 2
Time to create page: 0.19 seconds

Testimonials

"Using Active Table Editor is the easiest way of editing lookup tables  I've ever seen. A free 30-day trial is available on their Web site; the only issue is that when the 30 days are up, you're going to want to buy it."
- Moo Ling, Software Enginier

User Login

You only need to log in or register to use our support forum



Our customers

BP

BBC

HSBC


Databases we work with

Go to top