Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

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?

Flowing Fount of Yak Knowledge

2242 Posts

Posted - 08/13/2013 :  07:55:17  Show Profile  Reply with Quote
Refer this link
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.

Go to Top of Page

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:

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

James K
Flowing Fount of Yak Knowledge

3873 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  
 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.02 seconds. Powered By: Snitz Forums 2000