Home create a temporary variable in db2/400 (v5R4) within a RUNSQLSTM source file member?
Reply: 1

create a temporary variable in db2/400 (v5R4) within a RUNSQLSTM source file member?

Mustapha George
1#
Mustapha George Published in 2017-12-05 20:43:25Z

Can I create a temporary variable in db2/400 (v5R4) within a RUNSQLSTM source file member? Maybe something like this?

CREATE VARIABLE myVar1 INT DEFAULT (RAND() *100)    
CREATE VARIABLE myVar2 INT DEFAULT (RAND() *100)    
CREATE VARIABLE myVar3 INT DEFAULT (RAND() *100)    

INSERT INTO file1 VALUES(myVar1, myVar2, myVar3)
INSERT INTO file1 VALUES(myVar1, myVar2, myVar3)
etc... 

The goal is to quickly generate some random test data. Example above is simplified.

jmarkmurphy
2#
jmarkmurphy Reply to 2017-12-06 17:20:21Z

Yes. You might want to add or replace to the create command so you can run it over if necessary. Also note the semi-colons;, they are important. This actually creates a global variable in the schema. Here is what I tested.

CREATE or replace VARIABLE myVar1 INT DEFAULT (RAND() *100);
CREATE or replace VARIABLE myVar2 INT DEFAULT (RAND() *100);
CREATE or replace VARIABLE myVar3 INT DEFAULT (RAND() *100);

create or replace table file1 (
  field1 integer,
  field2 integer,
  field3 integer);

INSERT INTO file1 VALUES(myVar1, myVar2, myVar3);
INSERT INTO file1 VALUES(myVar1, myVar2, myVar3);

My results looked like this:

select * from file1;


field1  field2  field3
19      69      60
19      69      60
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310261 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO