Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-15-2005, 06:40 AM   #1 (permalink)
leialeia
Registered User
 
Join Date: Jun 2005
Posts: 2
leialeia is on a distinguished road
passing array to embedded sql

I'd like to know if it's possible to insert multiple records with a single query. The values comes from an array of values.

let say, i have two arrays:
NAME[10]
AGE[10]

how do i loop 10 times to ADD the values to a DB2 table named TABLE2?

i have a code on how to add a single NAME & AGE.
SUBMIT SQL CONTINUE;
CONNECT TO DB2(SSID=&DB2ID);
EXECUTE(INSERT INTO &CREATOR.&TABLE2 (NAME, AGE)
VALUES('&NAME','&AGE')) BY DB2;
%PUT SQLXRC=&SQLXRC, SQLXMSG=&SQLXMSG;
%LET SQLDBRC=&SYSDBRC;
EXECUTE(COMMIT) BY DB2;
DISCONNECT FROM DB2;
QUIT;
ENDSUBMIT;

thanks!
leialeia is offline   Reply With Quote
Old 06-15-2005, 07:01 AM   #2 (permalink)
jeffro
Person of interest
 
jeffro's Avatar
 
Join Date: Mar 2003
Location: New Jersey
Posts: 102
jeffro is on a distinguished road
No you really can't do it with a single query. You can string multiple queries together and execute them consecutively, then the commit will make the changes to the database. So you could do this:

Code:
Query
Query
Query
Query
Commit
Rather than this:
Code:
Query
Commit
Query
Commit
Query
Commit
__________________
Jeffro
Linux counter#:213782
GnuPG ID: 406238E7
jeffro is offline   Reply With Quote
Old 06-16-2005, 01:50 AM   #3 (permalink)
leialeia
Registered User
 
Join Date: Jun 2005
Posts: 2
leialeia is on a distinguished road
thanks jeffro!

could you elaborate further? a sample code would be a great help!

in addition this, i also have to implement ROLLBACK.
let say, i'm inserting values of NAME[5] & AGE[5], and then an error happened.
i have to ROLLBACK, so that values of NAME[1] to NAME[5] and AGE[1] to AGE[5] won't be added to the TABLE.

thanks so much!
leialeia is offline   Reply With Quote
Old 06-17-2005, 06:24 AM   #4 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 661
DJMaze is on a distinguished road
in mysql/postgresql:

query: BEGIN;
your queries here
query: COMMIT;
on failure:
query: ROLLBACK;

in ms sql:

query: BEGIN TRANSACTION;
your queries here
query: COMMIT;
on failure:
query: ROLLBACK;

I don't know the exact command for ODBC/Access though
DJMaze is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with SQL and VB.NET doobiwan Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 4 06-10-2005 07:09 AM
Cobol : Embedded Sql the_ruthless Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 0 04-16-2005 01:06 AM
Sorting an array of any Comparable objects plague Java 1 03-14-2005 06:24 PM
Simple reverse programm silex Standard C, C++ 3 01-22-2005 08:03 AM


All times are GMT -8. The time now is 10:07 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting