I retrieve a data, whose datatype is varbinary from database and display it, but the data display is totally different
The data in database is
0x0400000000200040000000000018
But when it display is
BAAAAAAgAEAAAAAAABg=
Is there anywhere to display it as
0x0400000000200040000000000018?
Then simply you can do is
Change your datatype from
varbinary
to
varchar(500)
OR
Try this Also
CONVERT(VARCHAR(500),coulmn_name,2)
that will solve your issue
EDIT
You can do simply like this
SELECT *,CONVERT(VARCHAR(500),coulmn_name,2) FROM TB_USER
Related
I'm working on ssis package which exports data from SQL Server to Excel. I had a problem converting non-unicode to unicode string data types. So I created a derived Column task and converted to Unicode string [DT_WSTR] 4 columns which have a type Varchar(40) in SQL Server table. It worked with these columns. But I also have a Description column of type varchar(max) and I tried to convert it to Unicode text stream [DT_NTEXT]. It did not work.
If your source is SQL Server (as you said), you can convert it directly in your SQL Query
SELECT
CONVERT(NVARCHAR(40), 'att1')
,CONVERT(NTEXT, 'att2')
Convert your VARCHAR into NVARCHAR
Convert your TEXT into NTEXT
it's faster.
P.S. To test it (Do not forget to delete or reset your previous OLE DB Input component) -> It will be forced to reevaluate your datatype
Does it help you?
The only thing that worked was to cast a Description column in Stored Procedure as varchar(1000). I checked the max length of this field and it was about 300 characters. So I made it varchar(1000) and in Derived column Unicode string [DT_WSTR]. This was a workaround, but I still want to know how to make it in ssis package without converting data type in Stored Procedure.
I'm a rookie when it comes to XML data.
I currently have a database with xml data being stored in a ntext column and this database appears to be taking up too much space. I'm trying to improve the way the data is stored, to reduce the overall size of the DB.
The way I see it, I have two options:
nvarchar(max)
xml
I will need to test the two options above by importing some data into those columns.
The problem I am having is, the XML data in the ntext column is currently stored as utf-8. In order for me to import it into the XML data type column, I will need to CAST/CONVERT the data to UTF-16?
Is this right?
Storing you data as datatype XML has two major benefits:
since it's stored as a native XML, you can do things like XQuery on top of it
since it's stored as XML it's stored in an optimized (tokenized) way, taking up less space than what the equivalent nvarchar(max) column would use up.
To convert your existing NTEXT column: just do a CAST on it.
What results do you get frmo this:
SELECT
id, ntextColumn, CAST(ntextColumn AS XML)
FROM
dbo.YourTable
I am almost sure this will work - just like that. SQL Server doesn't support UTF-8 - so your data even in the ntext column is most likely not really stored as UTF-8 (it's already been converted to SQL Server's Unicode - UCS-2/UTF-16) so I don't see any issue with converting this to datatype XML, really.
There is a video file named ♥-You-Got-Me-♥[www.savevid.com].mp4. But as the file with this name is inserted into a SQL Server 2005 database the hearts change to ?.
So the name turns into ?-You-Got-Me-?[www.savevid.com].mp4.
I don't know how to change the character set of the database? How do I change the char set of my table so that it can over all the characters ?
It will be great if along with the command,graphical method to do so is included in the answer.
You don't need to change the character set of the database. As long as you are using the NVARCHAR type, you should be good on the database side. However, you have to make sure that however you get the data into the table takes Unicode into account:
DECLARE #VAR VARCHAR(100) = N'♥-You-Got-Me-♥[www.savevid.com].mp4'
, #NVAR NVARCHAR(100) = N'♥-You-Got-Me-♥[www.savevid.com].mp4'
, #oops NVARCHAR(100) = '♥-You-Got-Me-♥[www.savevid.com].mp4'
SELECT
#VAR
, #NVAR
, #oops;
Returns:
?-You-Got-Me-?[www.savevid.com].mp4 ♥-You-Got-Me-♥[www.savevid.com].mp4 ?-You-Got-Me-?[www.savevid.com].mp4
The last declaration omits the N in front of the literal. There are similar ways to mess this up in your front end. Even if the DB stores Unicode, you have to make sure that everything between input and the DB, and then back out to your UI, handles multi-byte characters properly.
It isn't a CHARSET problem but a datatype problem in SQL Server. SQL Server doesn't have CHARSET as such like MySQL and Collations are for code page, sorting and comparing
You need to use nvarchar to store unicode (basically non-latin) data properly.
The problem is likely using VARCHAR, if possible changing to a NVARCHAR type should resolve the problem for new entries. If you cannot change the column type it may get more complicated.
SQL Fiddle
Change the type of the field storing your filename from varchar to nvarchar.
For example:
Table:
FilenameId INT IDENTITY
Filename NVARCHAR(200)
SQL to insert data:
INSERT INTO TestTable ([Filename]) VALUES(N'♥-You-Got-Me-♥[www.savevid.com].mp4')
When I upsize from Access2007 to SQL Server 2008, I have few issues...
1. text to nvarchar(255)
fields with text data type in Access are automatically converted to nvarchar(255)(I have unicode data) in sql server, but in reality the column-length is not that big so can I change the data type to nvarchar(55) or varchar(100)? Will there be any problem?
2. Date stored as text
Some tables throwed an error when tried to upsize because of the date column(mm/dd/yyyy), what I did is I changed the date/time column data type to text datatype in access, then the upsizing was successful, it converted to nvarchar(255) in sql server. I have converted nvarchar data type to date data type in sql server, but that does not show me a calendar symbol in access front-end. How to get a calendar symbol in the date field in my access front end?
I have tried the solution given in this link, but it did not work... Please give me some suggestions
text in sql server is deprecated, use nvarchar if you need to store unicode (multi lang support). Otherwise you can use varchar.
What I have is a staging table that is all nvarchar (so i can load it easily). In my live table i have a bunch of ntext items. I have the following:
obviously this isnt the whole query:
update
SLTDS_C69_Stdtable
set
[AARIssue] = convert(ntext, st.[AARIssue]),
[AttachmentIDs] = convert (ntext, st.[AttachmentIDs])
I get this error returned:
types ntext and nvarchar are incompatible in the equal to operator.
ANy idea how to fix this?
Do you want to replace the text or add to it?
INthe first case you don't need to convert at all, just set the filed to the value of the filed inthe other table. INthe second case you need to use UPDATE text.
However, you have a problem in that ntext is deprecated, you should consider converting these fields to nvarchar(max) as soon as possible unless you are still running SQL Server 2000.
Is this a repeat of this: How to update a text or ntext field in SQL Server 2000
The live table should use UPDATETEXT?