unicode characters writing to CSV issue - sql

I have this table in a database.
create table #temp
(
name nvarchar(max)
)
insert into #temp
(
name
)
values
('ปภวรินทร์ เฉื่อยไธสง')
select * from #temp
When I am seeing this data in the website. the data is displaying as
ชญา สวัสดิ์โยธ
But when I am exporting this data to csv it is displaying as
ปภวรินทร์ เฉื่อยไธสง
I want to export the data to csc from sqlserver in the same way that shows in WEB.
How can i do that ?
Thanks in advance.

Try to add N before inserting your values. You can insert UNICODE characters.
insert into #temp
(
name
)
values
(N'ชญา สวัสดิ์โยธ')

This is either (a) an issue with your UTF target (e.g. you are targeting UTF-32 on export rather than UTF-8 / 16) or (b) the db you are using requires a symbolic string for inserting these characters-- sort of like how "??!" is a trigraph for "|".

Related

special character data in sql server

I am having a special unicode character like smileys in a column, but i am not able to find out how many rows has such type of data?
Try something like this -
CREATE TABLE #Tmp_test(col NVARCHAR(1000));
INSERT INTO #Tmp_test(col) VALUES (N'My data has 😃')
,(N'My data has 😭')
,(N'My data has 😴')
,(N'No emoji');
SELECT COUNT(1)
FROM #Tmp_test WHERE CAST(col AS varchar(100)) != col;

Finding character values outside ASCII range in an NVARCHAR column

Is there a simple way of finding rows in an Oracle table where a specific NVARCHAR2 column has one or more characters which wouldn't fit into the standard ASCII range?
(I'm building a warehousing and data extraction process which takes the Oracle data, drags it into SQL Server -- UCS-2 NVARCHAR -- and then exports it to a UTF-8 XML file. I'm pretty sure I'm doing all the translation properly, but I'd like to find a bunch of real data to test with that's more likely to cause problems.)
Not sure how to tackle this in Oracle, but here is something I've done in MS-SQL to deal with the same issue...
create table #temp (id int, descr nvarchar(200))
insert into #temp values(1,'Now is a good time')
insert into #temp values(2,'So is yesterday')
insert into #temp values(2,'But not '+NCHAR(2012))
select *
from #temp
where CAST(descr as varchar(200)) <> descr
drop table #temp
Sparky's example for SQL Server was enough to lead me to a pretty simple Oracle solution, once I'd found the handy ASCIISTR() function.
SELECT
*
FROM
test_table
WHERE
test_column != ASCIISTR(test_column)
...seems to find any data outside the standard 7-bit ASCII range, and appears to work for NVARCHAR2 and VARCHAR2.

Hebrew field in text file issue

I am trying to import a txt file which has Hebrew customer names into a SQL Server Database, and for that NAME to be displayed in Hebrew for that COLUMN only.
I know how to insert it with this special insert statement below which works . If only I could grab that field from the txt file in Hebrew in SSIS .
create table #temp ( str Nvarchar(100) ) ;
insert into #temp(str)values(N'HEBREW SAMPLE IN HERE') ;
select * from #temp ;
drop table #temp;
The problem with SSIS is that all the import tasks put the Hebrew customer name in some junk format and I cant do anything then. Current collation on server, database, tables columns is ;
1. SQL_Latin1_General_CP1_CI_AS
2. SQL_Latin1_General_CP1_CI_AS
3. SQL_Latin1_General_CP1_CI_AS
Chane your database to HEBREW_CI_AS instead. You can do that at your database options for each database.
Choose property menu, then select options. First pulldown you can select sorter.

How can I INSERT data in TEXT datatype field? (Informix)

CREATE TABLE updater
(
nzp_up SERIAL PRIMARY KEY,
version VARCHAR(50),
status INT,
report TEXT
);
INSERT INTO updater (version, status,report) values ('TestVersion' , 0,"123123123");
-617 SQL error: A blob data type must be supplied within this context.
Using a | (pipe) delimited file, you can use the LOAD command to insert values into blob & text data types. I had the same problem in the past - go to link in my comment
See my question: Consistent method of inserting TEXT column to Informix database using JDBC and ODBC
It seems that some tools like ODBC drivers can insert text as TEXT while others like JDBC drivers must use PreparedStatent or other techniques.
INSERT INTO updater (version, status,report)
values ('TestVersion' , 0,"123123123");
and
INSERT INTO updater (version, status,report)
values ('TestVersion' , 0,'123123123');
have the same effect in mySql.So lets try without double quotes in SQL.

insert a BLOB via a sql script?

I have an H2 database (http://www.h2database.com) and I'd like to insert a file into a BLOB field via a plain simple sql script (to populate a test database for instance). I know how to do that via the code but I cannot find how to do the sql script itself.
I tried to pass the path, i.e.
INSERT INTO mytable (id,name,file) VALUES(1,'file.xml',/my/local/path/file.xml);
but this fails.
Within the code (java for instance), it's easy to create a File object and pass that in, but directly from a sql script, I'm stuck ...
Any idea?
For testing, you can insert literal hex bytes or use the RAWTOHEX(string) function, as shown below.
create table a(id integer, item blob);
insert into a values(1,'54455354');
insert into a values(2, RAWTOHEX('Test'));
select UTF8TOSTRING(item) from a;
TEST
Test
Addendum: For loading BLOB fields from a file, FILE_READ(fileNameString) may be a useful alternative.
insert into a values(3, FILE_READ('file.dat'));
Not h2database, but may help; https://blog.jerrynixon.com/2009/03/tsql-to-insert-imageblog.html
Example code from the linked blog article, should the link break again:
CREATE TABLE MyTable
(id int, image varbinary(max))
INSERT INTO MyTable
SELECT 1
,(SELECT * FROM OPENROWSET(
BULK 'C:\file.bmp', SINGLE_BLOB) as x )