Home Page for the TeradataForum

Archives of the TeradataForum

Message Posted: Fri, 20 Mar 2003 @ 21:18:13 GMT

  <Prev Next>   <<First <Prev Next> Last>>  

Subj:   Re: Default database name in bteq
From:   McCall, Glenn D

You don't say what platform you are running on (which can be helpful).

Assuming you have access to perl (typically an every unit item on Unix systems, and freely available on windows and other platforms) you could try something like this.


$i = 1;

open (BTEQ, "| bteq") || die "Can't open destination\n$!\n";
while ($i <= 20) {
    $number = sprintf ("%02d", $i);
    print BTEQ ".logon cm3_u$number, cm3_u$number\n";
    print BTEQ "modify user cm3_u$number as default database =
    print BTEQ ".remark other sql goes here\n";
    print BTEQ ".logoff\n";
close (BTEQ);

The above script is a script I used to log on to 20 different users and reset there environments prior to a training class.

The output of the above script is
.logon cm3_u01, cm3_u01
modify user cm3_u01 as default database = cm3_u01base;
.remark other sql goes here

.logon cm3_u02, cm3_u02
modify user cm3_u02 as default database = cm3_u02base;
.remark other sql goes here

And so on up to 20. Each line is sent to bteq and submitted for processing.

I know you want to access different databases, but the principle is still valid. You might replace my print BTEQ statements with something like this:

if (somecondition) {
    $prefix = "first";
else {
    $prefix = "sustain";

$db_A = "$prefix_core";
$db_B = "$prefix_lookup";
print BTEQ "select a.c1, b.c2\n";
print BTEQ "  from $db_A.some_table a join $db_B.some_table b on\n";
print BTEQ "         b.c1 = b.c2;\n";

Or whatever query you want. To make it even more readable you could use the following print to get the query to bteq

print BTEQ <<"EOI";
select a.c1, b.c2
  from $db_A.some_table a join $db_B.some_table b on
         b.c1 = b.c2;

Both examples send something like this to bteq

select a.c1, b.c2
  from first_core.some_table a join first_lookup.some_table b on
         b.c1 = b.c2;

I hope this helps

Glenn Mc

  <Prev Next>   <<First <Prev Next> Last>>  
  Top Home Privacy Feedback  
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 28 Jun 2020