Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating a view for updating

Posted on 2013-01-10
12
Medium Priority
?
251 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 29

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 29

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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 29

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 29

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
 
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 29

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 29

Accepted Solution

by:
Bill Bach earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
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…
Suggested Courses

783 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