You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to execute a fairly large piece of script on SQL server. The script creates temporary tables and goes like the follows
if OBJECT_ID('tempdb..#table_step1') is nullbeginselect
o1.*, o2.f3, o2.f4
into #table_step1from original1 o1
join original2 o2
ono1.f1=o2.f1whereo1.f2>o2.f2and etc etc
;
end;
if OBJECT_ID('tempdb..#table_step2') is nullbeginselect
s1.*, o3.f3, etc
into #table_step2from#table_step1 s1join original3 o3
ons1.f1=o3.f1whereo1.f2>o2.f2and etc etc
;
end;
/*more temp tables and steps*/droptable if exists #final_table;select
etc
into #final_tablefrom#table_stepN sNwhere etc
;
I use ODBC.execute! to send the above script to SQL server. What I found is that, if none of the temp tables #table_stepN exists, the script runs fine. However, if any of the temp tables are already there the script fails to generate the final table. It could be time consuming to create some of the temp tables. So it is economical to leave the temp tables on the server and reuse them.
How should I change the script to make it work? Or maybe I should split the script and execute a smaller piece each time. Any ideas or suggestions? Thank you!
The text was updated successfully, but these errors were encountered:
By the way, I don't get any error message from julia/ODBC. It seems SQL server simple skips the script without running it if any of the if statement wasn't true.
This seems like a problem specific to how you're using SQL server; most of the times, databases will support statements like create table if not exists ... to allow running idempotent create table statements.
I was trying to execute a fairly large piece of script on SQL server. The script creates temporary tables and goes like the follows
I use
ODBC.execute!
to send the above script to SQL server. What I found is that, if none of the temp tables#table_stepN
exists, the script runs fine. However, if any of the temp tables are already there the script fails to generate the final table. It could be time consuming to create some of the temp tables. So it is economical to leave the temp tables on the server and reuse them.How should I change the script to make it work? Or maybe I should split the script and execute a smaller piece each time. Any ideas or suggestions? Thank you!
The text was updated successfully, but these errors were encountered: