I am having a total brain cramp.
I have a query the populates a month_end_summary table from nightly_results table.
If the query runs correctly i want to run a query to delete the nightly_Results table.
but only if the first summary query runs with out error.
i can do the try catch on the first to catch an error, but blanking out on how to run the delete query if the try catch succeds.
Just execute the second query after the first within your try block.
If the first statement succeeds, the second statement will execute.
If the first statement fails, it will jump to the catch block w/o executing the second statement.
e.g.,
BEGIN TRY
SELECT 1/0;-- change me to 1/2 to see successful execution
EXEC sp_executesql N'SELECT * FROM sys.tables';
END TRY
BEGIN CATCH
THROW; -- Obvviously, you may not want to just rethow the error. Just an illustration
END CATCH
November 29, 2021 at 8:25 pm
ahhhh stupid me. It was a long weekend
May 6, 2023 at 2:07 pm
can we use the same method in databricks to create group, since for creating workspace local group it doesn't work as ' create group if not exists group_name ' i'm having trouble for a month to do that. kindly assist me. THANK YOU!
as below command?
BEGIN TRY
CREATE GROUP group_name;
END TRY
BEGIN CATCH
ALTER GROUP group_name ADD USER user@el.com
;
END CATCH
May 8, 2023 at 3:22 am
can we use the same method in databricks to create group, since for creating workspace local group it doesn't work as ' create group if not exists group_name ' i'm having trouble for a month to do that. kindly assist me. THANK YOU!
as below command?
BEGIN TRY CREATE GROUP group_name;
END TRY
BEGIN CATCH ALTER GROUP group_name ADD USER
user@el.com
;END CATCH
Look at your logic. If the create group works, there will be no error and so the Add User will never be executed.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply