Case sensitivity issue on SQL server - sql

I have a Dblink in place between my Oracle database and Microsoft SQL Server, fetching data from SQL server while on Oracle. Connectivity is fine but I am getting invalid column names whenever I try to include any column name in my select query.
On Oracle with Dblink:
select COLUMN1 from table1#dblink
Fails with:
ORA-00904: COLUMN1: invalid identifier
On Oracle with Dblink, this works fine.
select "COLUMN1" from table1#dblink
On SQL server this works fine:
select column1,COLUMN1 from table1
Seems case sensitivity is not enforced when on SQLserver, however, while trying from oracle it is enforced, any idea how I can bypass this,
The collation on my SQL server is SQL_Latin1_General_CP1_CI_AS.

Related

Microsoft SQL Server and Oracle SQL Developer

I linked an Oracle Database to my SQL Server in Microsoft SQL Server Management Studio 18. Server Objects -> Linked Servers.
I have a SQL Statement that when I run on the Oracle Developer Tool/Platform it returns the information as expected. But when I run the exact same query on the SQL Server it returns the incorrect results (The actual values in the rows and columns do not match).
What I know.
The table I am query in lives in the Oracle Database.
I can get the same/matching results on the Oracle Developer and SQL Server if I exclude in my WHERE statement anything involving a DATE.
Any thoughts?
The example of the query below.
Works on Oracle Developer but not on MSSQL
SELECT * FROM TABLE1
WHERE status = 'Deviation' and trunc(SRC_ROW_UPDT) BETWEEN TO_DATE('01/03/2020', 'DD/MM/YYYY') AND TO_DATE('10/12/2020','DD/MM/YYYY');
The example of the query below.
Works on both Oracle Developer and MSSQL
SELECT * FROM TABLE1
WHERE status = 'Deviation' and BATCHID = 'ThisBAtchID';
You cannot use ORACLE specific functions like TO_DATE in SQL Server calls. You have to execute them remotely using OPENQUERY. OPENQUERY in MSDN
SELECT * FROM OPENQUERY (OracleSvr, 'SELECT * FROM TABLE1
WHERE status = ''Deviation'' and trunc(SRC_ROW_UPDT) BETWEEN TO_DATE(''01/03/2020'', ''DD/MM/YYYY'') AND TO_DATE(''10/12/2020'',''DD/MM/YYYY'');');

How to use GROUP BY for multiple columns in SQL server

I am working on existing project which is developed on Laravel + Mysql. Now, I have migrated my database from Mysql to Sql server. So all the queries written in project using Mysql syntax.
Now, I have an query given below:
SELECT table_1.*, table_3.date as sem1date
FROM table_1, table_2, table_3
WHERE table_3.ID=table_2.DID AND block_datelu.BID=table_1.final_exam_date AND table_1.centreid=1234 AND table_1.course=1
GROUP BY table_1.start_date, table_1.end_date
When I am converting above query into sql server syntax, then sql server giving me error msg "Column 'table_1.Id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."
Can anyone tell me how can I use group by for multiple columns having joins?

SQL Server 2008 JOIN with Oracle 11g

I have successfully linked an Oracle 11g database to SQL Server 2008. I can run a simple query in SQL Server which displays Oracle data:
SELECT PRODUCT_CODE
FROM [ORACLE-LINK]..ORACLE_SCHEMA.PRODUCTS_TABLE
This does exactly what I would expect it to do.
The problem comes when I try to do a simple join:
SELECT ProductName, [ORACLE-LINK]..ORACLE_SCHEMA.PRODUCTS_TABLE.PRODUCT_NAME
FROM SqlServer_table
INNER JOIN [ORACLE-LINK]..ORACLE_SCHEMA.PRODUCTS_TABLE
ON SqlServer_table.Product_ID=[ORACLE-LINK]..ORACLE_SCHEMA.PRODUCTS_TABLE.PRODUCT_CODE
This causes a 'The multi-part identifier could not be bound' error on the Oracle part of the JOIN statement. I know from research that the syntax has to be exact, and I think I've tried almost every permutation. Perhaps there's something in the SQL Server settings/registry...
Following #shiva's helpful suggestion I reformatted the query with aliases. This threw a server collation mismatch error, which proved much more illuminating than the 'The multi-part identifier' message I had been getting earlier. It turns out the joined columns had different collations (SQL_Latin1_General_CP1_CI_AS vs Latin1_General_CI_AS). Adding a simple COLLATE to the end of the JOIN AS part of the query sorted this out.
Have you tried alias-ing the table names? Like so
SELECT SqlSvr.ProductName AS Sql_ProductName
, Orcl.PRODUCT_NAME AS Orcl_ProductName
FROM SqlServer_table AS SqlSvr
INNER JOIN [ORACLE-LINK]..ORACLE_SCHEMA.PRODUCTS_TABLE AS Orcl
ON SqlSvr.Product_ID = Orcl.PRODUCT_CODE

Create table as select * from sql server with 'ntext' datatype

I have a db-link from an oracle 11 database to a SQL server database. I am trying to perform a ctas from a table in the SQL server database, however for every table with a column of datatype ntext I get the error:
ORA-00997: illegal use of LONG datatype.
How can I solve this issue? Even if I was willing to forget about those specific columns, I have about 300 tables to perform the same action on.

Viewing SQL Server data to Oracle

Hello I have created a Database Link from Oracle to SQL Server 2008 using Oracle Gateway.
DB LINK:
create public database link mssql
connect to "user" identified by "password"
using 'gateway-SID';
When I use a simple query as SELECT * FROM TABLE#MSSQL the results are clearly ok.
The problem occurs when I select a distinct column from a table e.g.
SELECT COLUMN_NAME FROM TABLE#mssql
I get a query error from my SQL Developer saying:
ORA-00904: "CUSTOMERID": invalid identifier
00904. 00000 - "%s: invalid identifier"
Cause:
Action:
Error at Line: 1 Column: 8
Can anyone help me on this please?
(Disclaimer: I'm no SQL Server expert, but I'll give it a go)
SQL Server is case sensitive - you have to quote your column names, so instead of
SELECT COLUMN_NAME FROM TABLE#mssql
you need
SELECT "COLUMN_NAME" FROM TABLE#mssql
or even
SELECT "COLUMN_NAME" FROM "TABLE"#mssql
See Oracle forums on SQL Server, Oracle Gateway and ORA-00904