How to Insert korean text in ms-sql server? - sql-server

I tried to insert korean text into my ms sql server table, but it seems not working properly because all characters are broken like "????" as following:
The type of column is nvarchar, and I query as follow to put the data: insert into mytable values('텍스트'). And the collation is SQL_Latin1_General_CP1_CI_AS, but I wonder if the collation is the problem.
Please help me to find solution

Try this
While working with nvarchar datatype always use N'...'
insert into mytable values(N'텍스트');
This sqlfiddle example shows the difference if you don't use N'...'.
http://sqlfiddle.com/#!6/fab9a/1

Related

SQL Server to Teradata migration

We are migrating from SQL Server to Teradata database. All the views and tables are migrated. But the issue is that we aren't able to take the comments from each table.
In SQL Server we have a function called extended property which if used will get the comments from the respective tables/views. Badhri helped with providing a query for fetching the comment in Teradata in the same way but it doesn’t work in the expected way.
I tried inserting sample comments in columns and the below query is not fetching exact results. Can you please help?
Sample Query:
COMMENT ON COLUMN UtilityApp_DB.SQL_Views_Columns.ColumnNAME 'A Columnname for SQL Server!';
select 'COMMENT ON COLUMN '||trim(b.databasename)||'.'||trim(b.tablename) ||'.'||trim(b.columnname)||' IS '||''''||trim(b.commentstring)||''';'
FROM DBC.Columns b
WHERE b.CommentString IS NOT NULL
AND DatabaseName='UtilityApp_DB'
AND TableName in ('UtilityApp_DB.SQL_Views_Columns');
I created a table and tried inserting the values for the comment string in the table by copying the DBC Columns structure but still I can't get the comment string.
insert into UtilityApp_DB.commentstable (commentstring) values ('UtilityApp_DB.SQL_Views_Columns');
TableName in DBC.Columns does not include the database name and IS in your string concatenation should be AS.
SELECT 'COMMENT ON COLUMN '||trim(b.databasename)||'.'||trim(b.tablename) ||'.'||trim(b.columnname)||' AS '||''''||trim(b.commentstring)||''';'
FROM DBC.Columns
WHERE DatabaseName = 'UtilityApp_DB'
AND TableName IN ('SQL_Views_Columns');

Inserting arabic characters into sql server database from grails

I have a grails application that is intended to insert arabic characters from interface to sql server database. First I did it with field type varchar but it appears ???????. Then I found that the field type should be nvarchar but with, application simply fails to insert any row by giving the following error,
java.sql.SQLException: Cannot insert the value NULL into column 'id', table 'smsCampaigner.dbo.message'; column does not allow nulls. INSERT fails.
I know that this is constraints error that id cannot be null but this was not the case before changing the field type. Now I want to know whether we can specify fro config.groovy which encoding should be used in database ? any other type of help will be appreciated.
here you go..
when you create the domain class use String type for that column and that's it. you could insert any character it will accept.
for example TestDomain.groovy
class TestDomain {
String column1
}
In mysql you can set up the collation of the database/table/column to use utf8_unicode_ci and if I am not wrong that is valid to save arabic chars. Not sure how to do it with SQL Server but it should be something similar.
Change the collation of the database and tables and columns to Arabic_CI_AS
In Sql Server management studio (SSMS), Execute :
ALTER DATABASE DB06 COLLATE Arabic_CI_AS
where DB06 is the name of the database.
right-click on table, then click design, then select the desired column, in its properties, choose the collation to Arabic_CI_AS
by the way, the error :
Cannot insert the value NULL into column
is not related to Arabic, this is because you are trying to insert NULL in the column that does not allow NULL.

SQL Server unable to trim data of COLLATION type SQL_Latin1_General_CP1_CI_AS

We've two database one is the old one which has COLLATION - SQL_Latin1_General_CP1_CI_AS and the new one with COLLATION - Latin1_General_CI_AI (probably the default one).
There's a simple Table1 (ID (int), code(nvarchar(50))) in both the databases. What I'm suppose to do is compare both the tables for its data and find the missing or extra records.
Sample data in old table has code like : 'Code1 '
Sample data in new table has code like : 'Code1 '
What I need to be able to do is compare both the data (from the 'Name' column). I'm unable to trim the data from the old table -
EXAMPLE:
SELECT LTRIM(RTRIM([Name])) from [OLDDB].dbo.Table1
returns 'Code1 ' -- NOT as expected (probably due to mis-match in charset
SELECT LTRIM(RTRIM([Name])) from [NEWDB].dbo.Table1
'Code1' -- as expected
I hope it makes sense. Besides, even if I changes the COLLATION at column level still I was not able to get the ltrim / rtrim work!
Thanks.
If the CHAR(160) is the problem, then you don't have to change collation. Just replace those CHAR(160) with proper spaces and then RTRIM will work.
SELECT LTRIM(RTRIM(REPLACE([Name], CHAR(160), ' '))) from [OLDDB].dbo.Table1
Try the below update, Hope this will fix the issue.
update [OLDDB].dbo.Table1 set Name RTRIM(replace(NAME, char(160), char(32)))

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