Solved

Creating a view for updating

Posted on 2013-01-10
12
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Read about achieving the basic levels of HRIS security in the workplace.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

740 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