Solved

Creating a view for updating

Posted on 2013-01-10
12
243 Views
Last Modified: 2013-01-23
I have the following view that I'm creating in a Pervasive database

create view UPS_TRACKING as
SELECT NUMBER,PO_NO AS UPS_TRACK FROM SALES_HISTORY_HEADR
UNION ALL
SELECT NUMBER,REF_NO AS UPS_TRACK FROM PURCHASE_ORDER_HEADR

Open in new window


When I do the following update I get "View cannot be updated"

update UPS_TRACKING SET UPS_TRACK = 'UPS Tracking Number'
where number = '0000100598'

Open in new window


When I create the view without the UNION ALL then it works to update it

create view UPS_TRACKING as
SELECT NUMBER,PO_NO AS UPS_TRACK FROM SALES_HISTORY_HEADR

Open in new window


Any ideas how I can make this work?
0
Comment
Question by:Gerhardpet
  • 6
  • 6
12 Comments
 
LVL 28

Expert Comment

by:Bill Bach
ID: 38765531
Pervasive does not support updating a view like this.  From the current (PSQLv11) manual:
The UPDATE statement can update only a single table at a time.
0
 
LVL 28

Expert Comment

by:Bill Bach
ID: 38765534
The only way to get this to work would be to write a simple stored procedure that checks to see which table should be updated procedurally, then call the appropriate SQL statement to do the update itself.
0
 
LVL 1

Author Comment

by:Gerhardpet
ID: 38765539
The problem is that I'm on an Sage BusinessVision using the btrieve connection. As far as I know when using a btrieve connection I can't use a stored procedure.

Is that correct?
0
 
LVL 28

Expert Comment

by:Bill Bach
ID: 38765555
Which ODBC Driver are you using?  I am not as familiar with BusinessVision, so I am not sure of their limitations.
0
 
LVL 1

Author Comment

by:Gerhardpet
ID: 38765567
I'm using DDF's and then using the Pervasive ODBC Client Interface driver

Is that what you mean?
0
 
LVL 28

Expert Comment

by:Bill Bach
ID: 38767022
Yes. If you are using DDFs and the Pervasive ODBC DRiver, then you are definitely using the PSQL "SQL" engine. You should be able to write a short stored procedure to do this.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Comment

by:Gerhardpet
ID: 38767204
I remember that at one point I tried to create a trigger which did not work because of the btrieve connection

So then stored procedure should not be a problem?
0
 
LVL 28

Expert Comment

by:Bill Bach
ID: 38767439
Correct.  Triggers are not yet "universal" -- if you create a SQL trigger, then it prevents that same Btrieve operation from functioning.  However, SP's are completely running in SQL, and work just fine.
0
 
LVL 1

Author Comment

by:Gerhardpet
ID: 38769853
I'm integrating with UPS Worldship. They require an ODBC connection to my database and I don't know if they can execute SP's when they write back to PSQL. I have asked them and waiting for an answer.

If they can what would the store procedure look like? I need to have them write the UPS tracking number to the PO table if it is a PO number and SO table if it is a invoice number

I have some experience in SQL but have never written a SP
0
 
LVL 28

Accepted Solution

by:
Bill Bach earned 500 total points
ID: 38774746
A simple SP would likely work:

CREATE PROCEDURE UpdateTrack(:TrackNo VARCHAR(30))
AS
BEGIN
    UPDATE SALES_HISTORY_HEADR SET PO_NO = :TrackNo WHERE Number = '0000100598';
    UPDATE PURCHASE_ORDER_HEADR SET REF_NO = :TrackNo WHERE Number = '0000100598';
END;

Open in new window

You may need to alter the data type of the input variable, based on the exact data type of the two fields you are trying to edit.  If the two fields are different types, then you should use the CAST() function to perform an explicit conversion.

Call the function like this:  CALL UpdateTrack('1Z84736352878729');
0
 
LVL 1

Author Comment

by:Gerhardpet
ID: 38775112
I will talk to UPS to see if they can call for a SP and it that works I will give your suggestion a try.

I'll post back once I know. Thanks
0
 
LVL 1

Author Closing Comment

by:Gerhardpet
ID: 38810173
Thanks for your help on this. The stored procedure will work.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now