5 pts.
 Multiple SQL For (AS/400)
For (AS/400) I need to create a source member with multiple sentences of sql: i.e. update aa.... update bb.... update cc.... , and then run these source member with runsqlstm. Is it possible? which is the character to separate between sentences? Thanks in advance

Software/Hardware used:
ASKED: July 24, 2008  7:42 PM
UPDATED: October 18, 2011  10:53 PM

Answer Wiki:
Semicolon is the character for separating SQL sentences: Update file1 set field1=value1; Update file2 set field2=value2
Last Wiki Answer Submitted:  July 24, 2008  8:49 pm  by  Alopez1571   150 pts.
All Answer Wiki Contributors:  Alopez1571   150 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Hi,

This is no problem to do with RUNSQLSTM. Remember to end each statement with the semi-colon (;) and this should work fine.

Regards,

Martin Gilbert.

 23,625 pts.

 
Hi Gilbert, I have a file with 10 records like
fieldone
x1
x2
x3
x4
x5
x6
y10
y11
y12
y13


How can i Execute a RUNSQLSTM for this example:

Update file1 set fieldtwo = 'changed' where fieldone = 'x1'  or
Update file1 set fieldtwo = 'changed' where fieldone = 'x2'  or
Update file1 set fieldtwo = 'changed' where fieldone = 'x3'  or
Update file1 set fieldtwo = 'changed' where fieldone = 'x4'  or
Update file1 set fieldtwo = 'changed' where fieldone = 'x5'  or
Update file1 set fieldtwo = 'changed' where fieldone = 'x6' 

Thanks.
 610 pts.

 

It’s not clear what you are looking for.

Do you have two tables? The first table seems to have a column named fieldone, and another table seems to be named file1 with a column named fieldtwo. Or is there only one table that has both columns?

If there are two tables and both tables have a column like fieldone, it seems like you want a basic subselect in your WHERE clause. But we’d need to know a little more about what columns are available.

Tom

 107,735 pts.

 
Sorry Friends...

I have only one table called FILE1 and have two fields fieldone and fieldtwo. and I run a CL with a only sentence            RUNSQLSTM  SRCFILE(MYLIB/QCLSRC) SRCMBR(PROGRAM1) + 
                        COMMIT(*NONE)                               

IF the fieldone have x1,x2...x6 I Update the field fieldtwo with "changed".
 610 pts.

 

Then you possibly want something like this:

Update file1 set fieldtwo = ‘changed’ where fieldone in( 'x1', ‘x2′, 'x3', 'x4', 'x5', 'x6' )

The IN() expression can be a list or it can be a subselect. You might use a subselect if you had the values stored in a second table. Since you only have one table and you have a small, fixed list of values, you can put the list right in the expression.

BTW, when you use the {code} button, you can type your entire question, then select just the piece that is code and then click the {code} button.

Alternatively, you can click {code} at the beginning of a piece of code and again at the end of the piece of code.

The first method puts both beginning and ending tags at the same time. The second method does one tag at a time, but it’s easy to forget to click it a second time.

Tom

 107,735 pts.