473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Sybase Event query (Multiple Inserts based on Select)

gchq
96
Hi there

This was the closest to Sybase I could see....

If I wanted to perform a multiple insert based on values in a table using, say a web app, I'd define a DataTable and bring in the elements using the where query, then iterate though the table using a for - next statement based on the total rows and insert new rows each time the code passed through the for - next loop...

I can build an event that will perform Inserts - but is it possible to carry out multiple inserts as in the first scenario?

Stumped!
Feb 22 '08 #1
2 2631
gchq
96
I'm now part way there...

Expand|Select|Wrap|Line Numbers
  1.  
  2. BEGIN
  3. FOR names as curs CURSOR FOR SELECT Pre_Amount FROM Test_Nominal WHERE Pre_Months > 0 
  4. DO
  5. INSERT INTO Test_Nominal (Normal_Credit, Trans_Date) VALUES (Pre_Amount, current date);
  6. END FOR;
  7. end
  8.  
  9.  
This will now perform the multiple inserts, but it is NOT inserting the value from the select statement....

Getting closer..
Feb 22 '08 #2
gchq
96
OK - got it working now...

Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE EVENT "Update_Sales_Prepayments"
  3. SCHEDULE "Update_Sales_Prepayments_1" START TIME '07:00' ON ( 1 ) START DATE '2008-03-01'
  4. HANDLER
  5. BEGIN
  6.  
  7. FOR names as curs CURSOR FOR 
  8.  
  9. SELECT Sales_Pre_Amount AS vAmount, Nominal_Code as vNominal FROM Nominal WHERE Sales_Pre_Months > 0 
  10.  
  11. DO
  12.  
  13. INSERT INTO Nominal (Type, Ref, Details, Amount_Net, Ref2, Paid, Nominal_Code, Item_Date, Normal_Debit, Control_Debit, Control_Type) VALUES ('JD', 'System', 'Prepayment Adjustment', vAmount, vNominal, 'y',  '5003', current date, vAmount, vAmount, '1103');
  14.  
  15. INSERT INTO Nominal (Type, Ref, Details, Amount_Net, Ref2, Paid, Nominal_Code, Item_Date, Normal_Credit, Control_Credit, Control_Type) VALUES ('JC', 'System', 'Prepayment Adjustment', vAmount, '5003', 'y',  vNominal, current date, vAmount, vAmount, '1100');
  16.  
  17. END FOR;
  18.  
  19. UPDATE Nominal SET Sales_Pre_Months = (SELECT Sales_Pre_Months) - 1 WHERE Sales_Pre_Months > 0;
  20.  
  21. end
  22.  
  23. ;
  24.  
  25.  
Feb 22 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ashish | last post by:
Hi, I am using PHP 4.2.3 and Sybase 12.0 I want to insert records in multiple tables in a database. I also want to use transactions so that I can rollback in case there was a problem. I...
1
by: Burton Figg | last post by:
I have a SELECT statement which holds a list of times (for adding appointments to a database): e.g. <select name="time" id="time" size="3" multiple> <option value="00:00">00:00</option>...
2
by: Joe | last post by:
Hey, I'm going to give some background on my situation in case anyone can point out a way around my problem altogether... for the problem itself, please skip to the bottom of the post. thanks....
3
by: sandip | last post by:
Hi all, I am facing a problem while migrating a Sybase SQL query to DB2 UDB. The query involves left outer joins. The Sybase query syntax is as follows : select * from A, B, C where A.id1...
10
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
9
by: dan | last post by:
within a loop i am building a sql insert statement to run against my (programatically created) mdb. it works but it seems unreasonably SLOW! Sorry, dont have the code here but the jist is very...
0
by: das | last post by:
Hello all, I am using the SqlDependency to subscribe to any new inserts into a database table, I enabled the DB to be borker ready and subscrbed to Query notifications on the database. My C#...
3
by: assgar | last post by:
Hi I am having problem with my loping. I don't know if I have chosen the correct approach. GOAL: I need to insert into a table event types for a specific date range. The calendar the event...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.