Casting DB2 column to accept multi lingual characters in Open query - sql-server

I am using open query to retrieve data from IBM db2 to SQL server.
Below is the sample query used
select top 10 * from OpenQuery(Link server, 'Select columnName from table where column2=15' )
The columnName needs to be converted / cast in Unicode format to accept multi lingual characters. How to use casting in the inner query?
My issue is similar to that of https://www.sqlservercentral.com/forums/997384/linker-server-to-as400-db2-character-translation-problems
I want to retrieve the data in Thai and Chinese characters. I have rows of data which are to be in Thai and Chinese characters. But the data shows as garbled when I use the command which I have provided. The column type in sql server is defined as nvarchar.

Cast your column with the CCSID code xxxx corresponding to your language :
select cast(columnName as char(14) CCSID xxxx) from ...

Related

Dealing with &#x0D in SSIS

In SSIS, I have a package that deals with dumping data from one table to another. However after the package finishes executing I notice that my column has &#x0D in place of carriage returns.
Below is part of the query that handles this column.
(select cast((text) as varchar(max)) from [table]
where columna = x.columna for xml path (''), type)
Using the type keyword fixed this issue when I was testing this query on the SSMS.
I also encountered another error before then, where I got the message
Column "MyColumn" cannot convert between unicode and non-unicode string data types.
So I had to modify the affected column to output to Unicode Text Stream (DT_NTEXT) in order to avoid any errors (using Unicode String will cause truncation).
in SSIS package, i will assume that you are using OLEDB Source to read data from Sql server.
you can simply use the same sql query as datasource instead of using a Table name
Adding .value('.',nvarchar(max)') to the end of this statement removes all the &#x0D that appears in the result.
Final query should like the following:
(select cast((text) as varchar(max)) from [table1]
where columna = [table2].columna for xml path (''), type).value('.',nvarchar(max)')
This was to fix another issue I was having in SSIS when dealing with special characters and unicode.
The site containing the solution can be found here.

SQL Server nchar column data equality

I have a strange problem. In my SQL Server database there is table containing an nchar(8) column. I have inserted several rows into it with different Unicode data for nchar(8) column.
Now when I fire a query like this
select *
from table
where nacharColumnName = N'㜲㤵㠱㠷㔳'
It gives me a row which contains 㤱㔱㄰〴㐰' as unicode data for nchar(8) column.
How does SQL Server compare unicode data?
You should configure your column (or entire database) collation, so that equality and like operators work as expected. Simplified Chinese of whatever

Missing nvarchar columns when reading SQL Server database table from Oracle

I have a SQL Server database with a table that has a column of nvarchar(4000) data type. When I try to read the data from Oracle through a dblink, I don't see the nvarchar(4000) column. All the other column's data is displayed properly.
Can anyone help me to find the issue here and how to fix it?
Appendix A-1 ...
ODBC Oracle Comment
SQL_WCHAR NCHAR -
SQL_WVARCHAR
NVARCHAR - SQL_WLONGVARCHAR LONG if Oracle DB Character Set = Unicode.
Otherwise, it is not supported
Commonly nvarchar(max) is mapped to SQL_WLONGVARCHAR and this data type can only be mapped to Oracle if the Oracle database character set is unicode.
To check the database character set, please excuet:
select * from nls_parameters;
and have a look at: NLS_CHARACTERSET
UPDATE
NLS_CHARACTERSET needs to be a unicode character set - for example AL32UTF8(Do this if you know what you are doing or ask you r DBA to do it.)
NCHAR character set isn't used as the mapping is to Oracle LONG which uses the normal database character set.
A 2nd solution would be to create on the SQL Server side a view that splits the nvarchar(max) to several nvarchar(xxx) and then to select from the view and to concatenate the content again in Oracle.(If you have problem with changing the character set to unicode then this approach is the beset way to go.)

How to show CLOB type in a SELECT in SQL Server?

I have a table with one column of CLOB type data, they are all very short no more than 20 bytes, however I cannot see the actual string in the CLOB data.
For example if I use SELECT *, under the CLOB type every data is like:
CLOB, 8 Bytes
CLOB, 15 Bytes
CLOB, 9 Bytes
But I just want to see the content of the CLOB data.
I tried:
SELECT DBMS_LOB.SUBSTR(ClobColumnName, 20 ,1)
And it doesn't work, error is:
Error Code: 4121, SQL State: S1000
Cannot find either column "DBMS_LOB" or the user-defined function or aggregate "DBMS_LOB.SUBSTR", or the name is ambiguous.
So can I ask what's the syntax for direct display a CLOB data in a query?
I'm using SQL Server with dbVisualizer.
I figured out one solution. There should be better ways, please show more possible solutions in the comments.
SELECT CAST(ClobColumnName AS VARCHAR(50)) AS ClobColumnName ;
I have table with one column has CLOB data type(1000K), after storing message/data into CLOB column and found one solution see the actual data in CLOB column.
SELECT CAST(T.CLOB_COLUMNNAME AS VARCHAR(1000)) AS SAMPLEDATA
FROM TABLE_NAME AS T
The above query CAST the CLOB(Character Large Objects) into a normal String.
To see it in DbVis you just have to change it in the options.
There is an entry for the display of CLOB columns.
I presume you are using jDTS driver to connect to the SQL Server.
In the driver properties of the connection you can set the "USELOBS" to False to automatically cast them to string.
I had the same problem and solved it by using DBeaver (http://dbeaver.jkiss.org/) instead of dbVisualizer.
When I use DBeaver and do a select * from my SQLServer I can just double-click the CLOB in the result set and it opens in a new window with the content. Very slick.

How to Show Eastern Letter(Chinese Character) on SQL Server/SQL Reporting Services?

I need to insert chinese characters in my database but it always show ???? ..
Example:
Insert this record.
微波室外单元-Apple
Then it became ???
Result:
??????-Apple
I really Need Help...thanks in regard.
I am using MSSQL Server 2008
Make sure you specify a unicode string with a capital N when you insert like:
INSERT INTO Table1 (Col1) SELECT N'微波室外单元-Apple' AS [Col1]
and that Table1 (Col1) is an NVARCHAR data type.
Make sure the column you're inserting to is nchar, nvarchar, or ntext. If you insert a Unicode string into an ANSI column, you really will get question marks in the data.
Also, be careful to check that when you pull the data back out you're not just seeing a client display problem but are actually getting the question marks back:
SELECT Unicode(YourColumn), YourColumn FROM YourTable
Note that the Unicode function returns the code of only the first character in the string.
Once you've determined whether the column is really storing the data correctly, post back and we'll help you more.
Try adding the appropriate languages to your Windows locale setings. you'll have to make sure your development machine is set to display Non-Unicode characters in the appropriate language.
And ofcourse u need to use NVarchar for foreign language feilds
Make sure that you have set an encoding for the database to one that supports these characters. UTF-8 is the de facto encoding as it's ASCII compatible but supports all 1114111 Unicode code points.
SELECT 'UPDATE table SET msg=UNISTR('''||ASCIISTR(msg)||''') WHERE id='''||id||''' FROM table WHERE id= '123344556' ;

Resources