I think this will do the trick:
// Example table - you don't have to do this step if the table already exists. But you should create
// a variable to point to it.
wafer_dt = New Table( "Wafer Numbers",
Add Rows( 9 ),
New Column( "Wafer Number",
Character,
Nominal,
Set Values(
{"XC6A49L410.1", "XC6A49L411.1", "XC6A49L412.1", "XC6A49L413.1",
"XC6A49L414.1", "XC6A49L415.1", "XC6A49L416.1", "XC6A49L417.1",
"XC6A49L418.1"}
)
)
);
// For example if your table is called Wafer Numbers this statement will assign a variable to that table
// wafer_dt = data table("Wafer Numbers");
// Store the wafer numbers in a list
wafer_list = column(wafer_dt, "Wafer Number") << get values;
dsn_string = "DSN=MEASdata;UID=USER;PWD=PASSWORD;DBQ=MDMANU.WORLD;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;BNF=F;BAM=IfAllSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=F;CSR=F;FWC=F;FBS=64000;TLO=O;MLD=0;ODA=F;TSZ=8192;";
// Create a SQL statement where the wafer number is a variable to be substituted in during the loop
sql_statement = evalinsert(
"\[ SELECT WaferNR,WIPSTATUS
FROM "DISCSET"
WHERE WaferNR = '^one_wafer^']\");
// Create a connection to the database
dbc = create database connection(dsn_string);
for (i = 1, i <= nitems(wafer_list), i++,
one_wafer = wafer_list[i];
// Name the table the same as the wafer. Change to suit your needs
tbl_name = one_wafer;
// Retrieve the data for one wafer
dt = execute sql(dbc, sql_statement, tbl_name);
);
// Now that we're done retrieving all of the wafers into separate tables
// close the connection to the database
close database connection(dbc);