This is my first time trying to execute function within Oracle 11g package from SQL Server. I begin with information that both databases sit on different servers.
Here goes. There are three functions to be executed that should return values from each function. I managed to run one function using SSIS returning value by way of debugging the SQL Execute Task.
Below is the SQL statement I wrote;
SELECT <Database_name>.<Package_name>.<Function_name>(?, ?, ?) FROM dual
I also specified 3 parameters for input.
Help me out to execute 2 more functions together. Thanks a lot.
Related
I came across a good SSIS and SQL Problem. How do I in SSIS create a package that will execute a SQL query in management studio and grab the results of that query (the query results are "Insert INTO statements") and run that insert into statement query results into another sql database within SSIS that updates a table in another server? (The first query runs in one database and the second query runs in a different database)
First of all, sql queries execute on the database, not management studio. Management studio is visual interface for configuring,managing and administer databases.
To me it doesn't sound like there's any problem here at all. Create one connection manager for each DB. Then create two "Execute SQL Tasks", put your insert statements in them use use your connection manangers you've created.
Run the first query in an Execute SQL task and store the results in a string variable.
Then run a second Execute SQL task, using the variable as your SQL command.
Create Connection Managers for each of the databases you need, your source and both (or all) destinations.
Create a Data Flow Task.
In your OLEDB Source, execute your SELECT statement.
Pump the results into a MultiCast Transformation. This allows you to send the exact same result set to multiple destinations.
Create a Destination for each table you want to write to, and connect them to the MultiCast.
Bob's your uncle.
I got a big file contains with 10000 lines table rows data, and I had to insert it with a SQL method in my project, so I generated a very long SQL after parsing it. But it doesn't allow me to execute this at one time.
I think it should be placed in a transaction, and I got the way to use transaction with one short SQL in this doc. What method should I use in its document?
Hope you could process at SQL Server side using Bulk insert or OLEDB
ODBC CONNECT TO database_name;
SQL
EXEC procedure_name arg_1, arg_2
I use above code in Qlikview to retrieve the return tables from SQL Server.
However, there are three tables returned from the procedure.
Qlikview shows only one table and its columns.
How to retrieve more than one tables from a procedure?
Thank you very much!
The query results are returned as a multiple result set. The documentation below may help you navigate a multiple result set from Sql server using qlik.
Using multiple result sets served by SQL Server stored procedures
I have a single SQL query that I need to run against ~25 different databases- each residing on a separate SQL server on the network. The query will run from a single central SQL server management studio, and the 24 other SQL server instances are linked. I have the query I need, and I tested that it works- however the goal is to create a script that queries each of the 25 separate SQL instances.
Instead of writing the query out 25 separate times within the script, I'm wondering if there's a way to utilize the single block of code to query each of the linked instances using an array, variables, DO/WHILE, a function or any other method.
Here's the query:
SET NOCOUNT ON
PRINT 'local server';
SELECT isc.ini_schema_name[Device], count(*) [Count]
FROM pharos.dbo.edi_pharos_stations eps, pharos.dbo.ini_schemas isc
WHERE eps.ini_schema_id = isc.ini_schema_id
GROUP BY isc.ini_schema_id, isc.ini_schema_name
For the purpose of this example, if I were to utilize the less-graceful approach of writing out the block of code 24 more times, this would be the next query in the script (to query SQL server hostnamed pharos90-2008).
PRINT 'Pharos90-2008';
SELECT isc.ini_schema_name[Device], count(*) [Count]
FROM [pharos90-2008].pharos.dbo.edi_pharos_stations eps, [pharos90-2008].pharos.dbo.ini_schemas isc
WHERE eps.ini_schema_id = isc.ini_schema_id
GROUP BY isc.ini_schema_id, isc.ini_schema_name
As you can see, the query / code is exactly the same except for the fact that it is referencing a separate linked SQL Server (query being run from a central SQL Server Management Studio).
The ultimate goal is to output the queried data for each SQL instance to a single .txt file; format being, print the name of each particular SQL server followed by the corresponding queried data.
Any advice as to how one would accomplish such a task?
Thanks in advance.
Well, one way would be to create a cursor to iterate all of your linked servers. (You can find linked servers like this...)
SELECT * FROM sys.servers WHERE is_linked = 1
Then, you could use the undocumented sp_MSForEachDB stored procedure to run a dynamic version of your query (changing the server on each iteration) on each database in the cursor's current server. If you search for sp_MSForEachDB you can find plenty of information. But here's one link to save time.
I've encountered quite a strange problem
I'm trying to run a stored procedure via entity framework to work out the counts of various people with a date of birth within a certain range
I'm running the following code
select count(*), groupId from app_people p
where p.DOB >= '2012-10-02'
and p.DOB <= '2013-10-01
group by groupId
The issue I'm getting is that the same stored procedure executed via ssms returns 70 whereas entity framework returns 59
I'm inserting the result of the above query into a temp table before updating an existing table with the results.
Any suggestions as to why this would be happening?
Both are being passed the same parameters.
Using the following code to execute the proc via Entity framework, the procedure has been imported from the database and is included in the datamodel.
DatabaseContext.TestProcedure(false);
This could be a permissions issue as HLGEM pointed out. If the connection to SQL Server in code uses a different login than your SQL Server Management Studio SSMS login (e.g. windows credentials) you may see different results.
You can use the following TSQL to execute a query from another security context within SSMS. You could do this to compare the results of the same query for different users.
-- Execute as another user: https://learn.microsoft.com/en-us/sql/t-sql/statements/execute-as-transact-sql
EXECUTE AS USER = 'testuser';
-- TSQL with inconsistent results between code and ssms.
SELECT COUNT(*), groupId FROM app_people;