Ciao!
Ho una tabella dati prodotta tramite uno script che esegue due query separate (che forniscono dati da due fonti diverse) che vengono poi unite per formare una tabella dati. La mia domanda riguarda l'aggiornamento quotidiano di questa tabella in modo che lo script non debba essere eseguito nuovamente dall'inizio e che eventuali pulizie/aggiustazioni/nuove colonne possano essere mantenute. Vedo che sulla barra laterale c'è sia un "aggiornamento dal database" che un "aggiornamento dal database2". Posso eseguirne uno, ma eliminerà le colonne che non sono incluse da quella fonte (ovvero, se eseguo "aggiornamento dal database", che è per la prima query, eliminerà le colonne TVC, VI, AC e DC dalla query 2 insieme ad altre colonne di calcolo/immissione manuale che aggiungo alla tabella dopo averle unite nello script originale).
Ho provato a copiare insieme i due script di aggiornamento in uno script (vedi sotto) ma ho il problema per cui quando viene eseguito il primo tenterà di eliminare le colonne prima di eseguire il secondo. Non sono sicuro se l'approccio migliore sarebbe quello di combinare le tabelle e quindi provare ad aggiornare o se esiste qualcosa di più semplice (magari un modo per aggiornarlo senza eliminare i dati che non provengono da quella fonte)? Ho rimosso le informazioni di connessione e modificato i nomi nel codice seguente, ma spero che questo aiuti a dare un'idea. Qualcuno ha già affrontato un problema simile? Grazie!
New SQL Query(
Version( 130 ),
Connection(
""
),
QueryName( "query1" ),
Select(
Column( "Assay", "t1" ),
Column( "Experiment", "t1" ),
Column( "Date", "t1", Numeric Format( "m/d/y h:m:s", "0", "NO", "" ) ),
Column( "G", "t1" ),
Column( "L", "t1" ),
Column( "N", "t1" ),
Column( "K", "t1" ),
Column( "C", "t1" ),
Column( "H", "t1" ),
Column( "O", "t1" ),
Column( "C", "t1" ),
),
From( Table( "Runs", Schema( "schema1" ), Alias( "t1" ) ) ),
Where(
Contains(
Column( "Experiment", "t1" ),
"E001",
UI(
Contains(
Base(
"Categorical",
Prompt(
"Experiment ID:",
Character,
PromptName( "t1.Experiment_1" )
)
)
)
)
) & Does Not Contain(
Column( "Assay, "t1" ),
"xxx",
UI(
Contains(
Base(
"Categorical",
Prompt(
"Add a filter for names (optional) or put xxx:",
Character,
PromptName( "t1.AssayId_1" )
)
)
)
)
) & GE(
Column(
"Date",
"t1",
Numeric Format( "m/d/y h:m:s", "0", "NO", "" )
),
0,
UI(
Comparison(
Base(
"Continuous",
Prompt(
"Date range:",
Character,
PromptName( "t1.RunDate_1" )
)
)
)
)
)
)
) << Run Foreground( UpdateTable( Current Data Table() ) );
New SQL Query(
Version( 130 ),
Connection(
""
),
QueryName( "query2" ),
Select(
Column( "Assay", "t2" ),
Column( "Experiment", "t2" ),
Column( "Date", "t2", Numeric Format( "m/d/y h:m:s", "0", "NO", "" ) ),
Column( "TVC", "t2" ),
Column( "VI", "t2" ),
Column( "AC", "t2" ),
Column( "AD", "t2" )
),
From( Table( "Runs", Schema( "schema2" ), Alias( "t2" ) ) ),
Where(
Contains(
Column( "Experiment", "t2" ),
"E001",
UI(
Contains(
Base(
"Categorical",
Prompt(
"Experiment ID:",
Character,
PromptName( "t2.Experiment_1" )
)
)
)
)
) & Does Not Contain(
Column( "Assay", "t2" ),
"xxx",
UI(
Contains(
Base(
"Categorical",
Prompt(
"Add a filter (optional) or put xxx:",
Character,
PromptName( "t2.AssayId_1" )
)
)
)
)
) & GE(
Column(
"Date",
"t2",
Numeric Format( "m/d/y h:m:s", "0", "NO", "" )
),
0,
UI(
Comparison(
Base(
"Continuous",
Prompt(
"Date range:",
Character,
PromptName( "t2.RunDate_1" )
)
)
)
)
)
)
) << Run Foreground( UpdateTable( Current Data Table() ) )
Sono abbastanza sicuro che quello che vedi è che se aggiungi colonne a una tabella che è stata creata da una nuova query SQL, otterrai un nuovo datatable quando esegui un aggiornamento dal database. Cioè, non puoi riutilizzare la tabella importata poiché hai modificato i metadati (colonne aggiunte).
Penso che quello che puoi fare è importare le tue 2 tabelle dai database utilizzando File->Database->Query Builder (non salvare le tabelle di dati) Quindi eseguire Tabelle->JMP Query Builder per combinare le 2 tabelle . Assomiglierà a qualcosa del tipo:
New SQL Query(
Version( 130 ),
Connection( "JMP" ),
JMP Tables(
["Big Class Families" =>
"Source(New SQL Query(
Connection(
""
),
QueryName( \!"Big Class Families\!" ),
Select,
From( Table( \!"Big Class Families\!", Schema( \!"SQBTest\!" ), Alias( \!"t1\!" ) ) )
) << Run Foreground)",
"g4_bigclass" =>
"Source(New SQL Query(
Connection(""),
QueryName( \!"g4_bigclass\!" ),
Select,
From( Table( \!"g4_bigclass\!", Schema( \!"SQBTest\!" ), Alias( \!"t1\!" ) ) )
) << Run Foreground)"
]
),
QueryName( "SQLQuery3" ),
Select(
Column( "picture", "t1" ),
Column( "name", "t1" ),
Column( "age", "t1" ),
Column( "sex", "t1" ),
Column( "height", "t1" ),
Column( "weight", "t1" ),
Column( "sibling ages", "t1" ),
Column( "sports", "t1" ),
Column( "countries visited", "t1" ),
Column( "family cars", "t1" ),
Column( "reported illnesses", "t1" ),
Column( "age vector", "t1" ),
Column( "pet", "t1" ),
Column( "name", "t2", Alias( "name 2" ) ),
Column( "age", "t2", Alias( "age 2" ) ),
Column( "sex", "t2", Alias( "sex 2" ) ),
Column( "height", "t2", Alias( "height 2" ) ),
Column( "weight", "t2", Alias( "weight 2" ) )
),
From(
Table( "Big Class Families", Alias( "t1" ) ),
Table(
"g4_bigclass",
Alias( "t2" ),
Join(
Type( Left Outer ),
EQ( Column( "name", "t2" ), Column( "name", "t1" ) ) &
EQ( Column( "age", "t2" ), Column( "age", "t1" ) ) &
EQ( Column( "sex", "t2" ), Column( "sex", "t1" ) ) &
EQ( Column( "height", "t2" ), Column( "height", "t1" ) ) &
EQ( Column( "weight", "t2" ), Column( "weight", "t1" ) )
)
)
)
) << Run;
Ciò che accade è che JMP Query Builder estrae lo script sorgente da ciascuna tabella non salvata per creare il proprio script. Ciò significa che ogni volta che viene eseguito lo script New SQL Query, verranno importati nuovi dati dalle origini dati in ciascuna delle tabelle dipendenti.