SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 openquery changing datatype
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

lappin
Posting Yak Master

182 Posts

Posted - 08/13/2013 :  07:28:11  Show Profile  Reply with Quote
I have a procedure which imports from Oracle tables using Openquery to do a Select Into tables in SQL Server. The SQL is dynamic-SQL where the table name is passed in and ran on a loop. The code fired for a particular table is:

SELECT * INTO myTempTable1
FROM OPENQUERY(myLink,'select * from table1)

The temp table is then used to update final table in SQL Server.
Then the temp table is deleted.

The problem is that a varchar2(30) column in Oracle is converted to nvarchar(30) in SQL Server. This is causing some data to be truncated.

Any suggestions?

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 08/13/2013 :  07:55:17  Show Profile  Reply with Quote
Refer this link http://docs.oracle.com/cd/E10405_01/doc/appdev.120/e10379/ss_oracle_compared.htm#i1026309
what type of data do you have in the varchar2(30) column ? i.e. BYTE or CHAR ?
As per my knowledge, Oracle's VARCAHR2(30) can be mapped to SYSNAME/VARCAHR(30) in SQL Server.

--
Chandu
Go to Top of Page

lappin
Posting Yak Master

182 Posts

Posted - 08/13/2013 :  10:36:26  Show Profile  Reply with Quote
Yes varchar2(30) needs to be mapped to varchar(30), but it is not happening automatically. Since this is a SELECT * INTO I am not specifying the column types, just relying on SQL Server to correctly chose the matching type. This is my problem: how to get SQL Server to realise that varchar2(30) should map to varchar(30) not nvarchar(30).

I found this:
https://forums.oracle.com/thread/1957428

But not sure how to proceed.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3706 Posts

Posted - 08/13/2013 :  13:14:38  Show Profile  Reply with Quote
If you insert data from a VARCHAR(30) column (or its Oracle equivalent, assuming it is equivalent) into an NVARCHAR(30) column, the data should not get truncated. If the data is getting trucated, the source of the problem may be somewhere else.

Do couple of experiements:

1. Remove the "INTO myTempTable1" part, do you see all the data coming through correctly?

2. For testing purposes, create the destination table and then use INSERT INTO myTempTable1 SELECT * FROM...

Do you get the correct data in either case?
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000