How can I execute the GET_CONTINUOUS_LOADID stored procedure in Azure SQL deployment using cross-databvase query?
D
Derek Leung
started a topic
over 2 years ago
In Azure SQL, if you want to execute GET_CONTINUOUS_LOADID stored procedure (which resides in the "Semarchy Repository" database) from the "Data Location" database, you need to usecross-database-query feature. Here are some sample coding showing how to do it.
Best Answer
C
Cédric BLANC
said
over 2 years ago
1. Create a procedure at the Semarchy Repository that wraps the existing GET_CONTINUOUS_LOADID stored procedure, the idea is to return the loadid as a result set at the end of the stored procedure.
create or alter PROCEDURE GET_CONTINUOUS_LOADID_WRAPPED
@P_CONTINUOUS_LOAD_NAME varchar(max)
WITH EXECUTE AS OWNER
AS
BEGIN
DECLARE
@LOAD_ID numeric ;
EXEC GET_CONTINUOUS_LOADID @LOAD_ID OUTPUT, @P_CONTINUOUS_LOAD_NAME
SELECT @LOAD_ID;
RETURN
END
2. Create the scoped credentials and external data source
-- credential maps to a login or contained user used to connect to remote database
CREATE DATABASE SCOPED CREDENTIAL semarchy_repository_cred -- credential name
WITH IDENTITY = 'semarchy_repository', -- login or contained user name
SECRET = 'yourpassword'; -- login or contained user password
-- data source to remote Azure SQL Database server and database
CREATE EXTERNAL DATA SOURCE SemarchyRepository
WITH
(
TYPE=RDBMS, -- data source type
LOCATION='yourserver.database.windows.net', -- Azure SQL Database server name
DATABASE_NAME='semarchy_repository', -- database name
CREDENTIAL=semarchy_repository_cred -- credential used to connect to server / database
);
3. Then you can execute the new stored procedure using sp_execute_remote
1. Create a procedure at the Semarchy Repository that wraps the existing GET_CONTINUOUS_LOADID stored procedure, the idea is to return the loadid as a result set at the end of the stored procedure.
create or alter PROCEDURE GET_CONTINUOUS_LOADID_WRAPPED
@P_CONTINUOUS_LOAD_NAME varchar(max)
WITH EXECUTE AS OWNER
AS
BEGIN
DECLARE
@LOAD_ID numeric ;
EXEC GET_CONTINUOUS_LOADID @LOAD_ID OUTPUT, @P_CONTINUOUS_LOAD_NAME
SELECT @LOAD_ID;
RETURN
END
2. Create the scoped credentials and external data source
-- credential maps to a login or contained user used to connect to remote database
CREATE DATABASE SCOPED CREDENTIAL semarchy_repository_cred -- credential name
WITH IDENTITY = 'semarchy_repository', -- login or contained user name
SECRET = 'yourpassword'; -- login or contained user password
-- data source to remote Azure SQL Database server and database
CREATE EXTERNAL DATA SOURCE SemarchyRepository
WITH
(
TYPE=RDBMS, -- data source type
LOCATION='yourserver.database.windows.net', -- Azure SQL Database server name
DATABASE_NAME='semarchy_repository', -- database name
CREDENTIAL=semarchy_repository_cred -- credential used to connect to server / database
);
3. Then you can execute the new stored procedure using sp_execute_remote
Derek Leung
In Azure SQL, if you want to execute GET_CONTINUOUS_LOADID stored procedure (which resides in the "Semarchy Repository" database) from the "Data Location" database, you need to use cross-database-query feature. Here are some sample coding showing how to do it.
1. Create a procedure at the Semarchy Repository that wraps the existing GET_CONTINUOUS_LOADID stored procedure, the idea is to return the loadid as a result set at the end of the stored procedure.
2. Create the scoped credentials and external data source
3. Then you can execute the new stored procedure using sp_execute_remote
Cédric BLANC
1. Create a procedure at the Semarchy Repository that wraps the existing GET_CONTINUOUS_LOADID stored procedure, the idea is to return the loadid as a result set at the end of the stored procedure.
2. Create the scoped credentials and external data source
3. Then you can execute the new stored procedure using sp_execute_remote
-
Import Data Into Entities via Azure Data Lake
-
Recover Deleted(soft Delete) Record and Configure in Application
-
Data Quality in batch mode and real-time integration
-
Integration with analytics tools
-
Query/Load/Delete data with the REST API
-
Does the Done Tab in Inbox have a limit?
-
How Can I Trigger Enricher or Sql Procedure when deleting?
-
Matching Rules But Only The Latest Record Creates a Golden Record
-
Unstructured and Semi Structured Data in Semarchy?
-
Read CSV files from AWS S3
See all 73 topics