Azure - How to execute UDF from external data source in select statement - sql-server

I have an external data source created in DB1 and its pointing to DB2 database in Azure.
I want to query a UDF defined in DB2 from DB1.
Following syntax works, from DB1:
EXEC sp_execute_remote
N'Ext_DB2',
N'SELECT Result'
But I want to use following syntax:
select C1, C2, < function_in_DB2 >
from t1
I tried searching web, this format is not mentioned anywhere, is it not supported? Any pointers will help.
Thanks !

Just per my experience, I think Azure SQL database doesn't support it. As we know, we can't do cross database query directly.
Since none document talk about this, I would suggest you ask Azure SQL support to get more support, ref: How to create an Azure support request.
Hope this helps.

Related

Define Federated Object on DB2

I'm currently learning the basics of DB2 in school.
Right now we are working on Federated Data Sources.
I've been trying to solve this one exercise, but I'm stuck:
In database DB001, table SH1.TB001 is to be included as a Federated Data Source.
The Federated Object should have the name NTAB (the nickname) and be defined in schema SH1.
I'm searching a solution on the IBM Knowledge Center, but I couldn't find anything.
I have to work essentially directly on my CentOS server, with the terminal. The only "external" programm I can use is DBeaver.
Since I have no experience with this, any type of help or advice is appreciated!
there is two way to access remote data in DB2:
1.create a nickname, and use it as local table:
Create NICNAME SCHMx.NICKNAMEx for <remote server>.<remote schema>.<remote table>
then you can use SCHMx.NICKNAMEx as a local table:
select count(*) from SCHMx.NICKNAMEx
2.Use Federated three-part names:
select count(*) from <remote server>.<remote schema>.<remote table>
you can find the documentation her: https://www.ibm.com/support/producthub/db2/docs/content/SSEPGG_11.5.0/com.ibm.data.fluidquery.doc/topics/iiyfq3pnintro.html

DB Link from Oracle to MS Server

I am new to this forum and already searched for 45 minutes to find a solution for my problem. I hope you can help me.
A Gateway to a remote Microsoft SQL Database was installed on a Oracle Server (Oracle 12c). The tsnnames.ora file was appropiately set up.
For the connection, I created a database link (In the Oracle DB) as follows:
CREATE DATABASE LINK TEL CONNECT TO "fb_B2C" IDENTIFIED BY "passwort" USING 'dg1msql';
When I now execute the Select statement:
SELECT "name" FROM "sys"."databases"#TEL
it shows me the according databases. Among others, I can see the AB_Colors database.
Now, I want to select a view in the AB_Colors database.
Due to the fact I can connect to this database via Excel, I know that in the database AB_Colors, there are 10 Views(A,B,C,..). I would like to select the View C from the database AB_Colors via the DB LInk.
Owner of the View is b2b.
How do i need to formulate the select statement to do it?
I already tried different writings:
SELECT * FROM b2b.C#TEL;
SELECT * FROM "AB_colors"."b2b"."C"#TEL;
SELECT * FROM [AB_Colors].[b2b].[C]#TEL;
The common error message is: View/Table does not exist
I highly appreciate your help,
Fedja
This is the correct format
SELECT * FROM "b2b"."C"#TEL;
The issue maybe because the database you want to select from is not the one specified in the gateway for dg1msql. You can't add the database name to the query so you must specify it in the gateway connection.
This is defined in
$ORACLE_HOME/dg4msql/admin/initdg4msql.ora
where you should check HS_FDS_CONNECT_INFO

Getting data from another Database within procedure in DB2

I have two databases DB1 and DB2 and I want to call a stored procedure in DB1 and get data from DB2.
Create procedure diffdbtest()
LANGUAGE SQL
DYNAMIC RESULT SETS 1
BEGIN
DECLARE C1 CURSOR WITH RETURN FOR
SELECT * FROM Db2.myschema.tabletest;
OPEN C1
END#
I get Db2.myschema.tabletest is not defined.
Both DBs have the same user and password (if possible how can I use different users?)
Any idea what is wrong?
Running DB2 Express v10.5 Windows
Thanks.
The only way as far as I know is you have to use federation. You need to:
create server wrapper to DB #2
create nickname on table that is referring the table tabletest
create user mapping
etc.
Then, you can access that table via nickname.
Details on how to do this can be found in knowledge center: https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.data.fluidquery.doc/topics/tlsdb201.html
Hope this helps.
Kevin See
Db2 Hybrid Cloud Security Dev Team

Call SQL Server functions via Oracle database link

Is there a way to execute the following statement from Oracle using a database link to a SQL Server instance without having to create a view on the target instance?
select db_name(), ##SERVERNAME
I have tried
"select db_name(), ##SERVERNAME"#DbLink
but that did not succeed.
Any help would be greatly appreciated
Here:
select dbo.FunctionName#dblink('value') from dual;
But you need to tell the dblink which functions must be available through the dblink. See the manual at: http://docs.oracle.com/cd/E11882_01/server.112/e11050/admin.htm#i1007467

how can I enumerate the databases of a sql server

Given an instance of SQL server, what's the best way to enumerate the databases?
In SQL Server 2000+:
select * from sysdatabases
In SQL Server 2005+:
select * from sys.databases
The difference is subtle and barely worth mentioning for a one-liner like this. But depending on how much you're going to be accessing the system catalog, you may get some use out of this article:
Querying the SQL Server System Catalog
You can also execute sp_helpdb without an argument to get basic information about all databases. (Pass in a database name as an argument to get more detailed information about that database).
Try this:
SELECT [name] FROM sys.sysdatabases
You could also get this from exec sp_databases;
These commands will work from SQL 2000+.
EXECUTE master.sys.sp_MSforeachdb 'USE [?]; EXEC sp_spaceused'

Resources