In SQL while using aggregate function having the condition is not working in 11g Oracle. But where condition is working? - oracle11g

In SQL while using aggregate function having the condition is not working in 11g Oracle. But where condition is working.

Related

Upsert R Dataframe into SQL Server

I am trying to Insert and Update into a SQL Server from R.
I have a data frame (New_mtcars) which contains records that do not exist in the SQL Database table (dbo.mtcars) or do exist, but are different.
How do I insert and update (merge?) records from New_mtcars into the Microsoft SQL server table?
I have successfully created a connection string using dbConnect, and established a connection using ODBC.
However, I am struggling with the workflow and syntax beyond this point.

SQL query using 2 different database engines

I need to use the results from an Oracle query in a SQLServer query within ASP.NET. Can I do this without exporting the Oracle query results to a temp file, e.g. csv, and creating a new table in SQLServer using the csv file? Thanks!
There are probably several different ways to do this, including connecting the SQL Server to the Oracle server using Linked servers,
But if that's not possible for some reason, or if you need to use the Oracle resultset as well as the SQL Server resultset in your asp.net page, you can fill a DataSet with the Oracle query results, and send a DataTable as a table valued parameter to a stored procedure in the SQL Server.
Look at this page in MSDN, explaining how to use table valued parameters in sql server.
You can also look here for a step by step instruction on how to create and use table valued parameters in c#.

Invalid column definition error when using four part name to access Oracle DB as SQL Server linked server

I have setup a linked server in SQL Server 2008 R2 in order to access an Oracle 11g database. The MSDASQL provider is used to connect to the linked server through the Oracle Instant Client ODBC driver. The connection works well when using the OPENQUERY with the below syntax:
SELECT *
FROM OPENQUERY(LINKED_SERVER, 'SELECT * FROM SCHEMA.TABLE')
However, went I try to use a four part name using the below syntax:
SELECT *
FROM LINKED_SERVER..SCHEMA.TABLE
I receive the following error:
Msg 7318, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for linked server "LINKED_SERVER" returned an invalid column definition for table ""SCHEMA"."TABLE"".
Does anyone have any insight on what my be causing the four part name query to fail while the OPENQUERY one works without any problems?
The correct path to follow is to use OPENQUERY function because your linked server is Oracle: the four name syntax will work fine for MSSQL servers, essentially because they understand T-SQL.
With very simple queries, a 4 part name can accidentally work but not often if you are in a real scenario. In your case, the SELECT * is returning all the columns, and in your case one of the column definition is not compatible with SQL Server. Try another table or try to select a single simple column (e.g. a CHAR or a NUMBER), maybe it will work without problem.
In any case, using distributed queries can be tricky sometime. Database itself does some optimizations before executing commands, so it is important for the database to know what it can do and what it can't. If the DB thinks the linked server is MSSQL, it will take some action that may not work with Oracle.
When using four part name syntax with a linked DB different from MSSQL, you will have other problems as well, for example using database builtin functions (i.e. to_date() Oracle function will not work because MSSQL would want to use its own convert() function, and so on).
So again, if the linked server is not a MSSQL, the right choice is to use OPENQUERY and passing it a query that use a syntax valid against the linked server SQL dialect.
If you use the OLEDB provider for Oracle you can query without using openquery

Myob Odbc insert

Are there any functions/queries using MYOB ODBC to query the ID from MYOB Sale after doing INSERT ?
For example we can do SCOPE_IDENTITY() in SQL Server to get the ID value after performing INSERT operation. But are there any using MYOB ODBC ?
Unfortunately not. Behind the scenes the ODBC Driver is effectively just automating the manual MYOB import process. The best you could do is to query the database again to get the last invoice (but that is going to be problematic in a multi-user environment) or some other criteria to identify the invoice you've just inserted.
This should change in the next few months with the release of the API for MYOB AccountRight Live but until then, ODBC is what you're stuck with.
Mick

Bulk Insert multiple records and get identity for all using ADO.NET

I want to batch insert multiple records in sql server database using ADO.NET command/sqldataadapter and get identity value generated for all the rows in a single database trip.
What are my options?
If you're using either, SQL server 2005 and 2008 add support for the OUTPUT clause, which enables you to return a result-set from an UPDATE/INSERT/DELETE statement.

Resources