Solved

Creating a view for updating

Posted on 2013-01-10
12
244 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

919 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

18 Experts available now in Live!

Get 1:1 Help Now