Convert VarBinary RTF blob to text in MS SQL - sql

I am using SQL server - 2008.
Column Datatype - VarBinary
RTF File is compressed and saved to this varbinary column.
Now how to access and view data in RTF file using SQL ?
it's returns this: 㠰た㠴弰巎楛㵤㠵㜸ㄲ㠴. etc.
Sample Tried Code here:
http://rextester.com/YOFHK34016
any solution to this.
in 2008 Decompress and compress function not work.
how i can get RTF file as it is to text.

That's works for me:
select convert(varchar(max),convert(varbinary(max),bv.value)) from blobValue bv
Instead using nvarchar try to use varchar.
But I shuld say that this will return rtf formated text, something like:
"{\rtf1\ansi\ansicpg1251\deff0\deflang1049{\fonttbl{\f0\fnil MS Sans Serif;}{\f1\fswiss\fcharset0 Arial;}"
To get actual text from it you can use .Net dll to convert it.
You can add .net dll to your database and than call it's functions from Sql script. More detailed about it: Call dll function from sql stored procedure using the current connection

It worked for me, thanks a bunch.
I used:
SELECT convert(nvarchar(max),convert(varbinary(max),[FORMULATEXT]))

Related

SQL Convert from alphanumeric to numeric only

Ok, I have a table I am querying for an outside project. The table has a field that is alphanumeric but the external project can only support numeric data. The outside project is needing my data as an Excel spreadsheet so I am trying to just export my query to Excel which I can do but I can't seem to figure out if there is a simple convert feature to do this for me. The originating table has the field as VARCHAR(10). I tried CAST and CONVERT but no go. This is SQL Server 2012.
Thanks.

Use SQL Query to convert a base64 string back into an image

I'm trying to write a SQL statement that will convert an image in a base64 string format back to an image and save to the file system.
As per the comments above, I can't accomplish what I want using pure SQL. Will call C# code from SQL instead.

RTF to plain text in SQL with read only permissions

I have a MSSQL 2005 database which also stores RTF-like text format. I'd like to strip off all formatting code and just get the plain text. Now the tricky part; I only have read access to the database. So, unfortunately I can't use any CREATE FUNCTION solutions...
For example, a column starts with something like:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}} \viewkind4\uc1\pard\lang1043\ul\b\f0\fs22
Can this be done?

BULK INSERT is not working correctly

I used bulk insert into SQL Server Management Studio 2008 R2, 10 words from a text UTF-8 file, into single column.
However, the words do not appear correctly, I get extra space in front of some words.
Note: None of the answers have solved my problem, so far. :(
SCREENSHOT OF THE PROBLEM
This issue may occur if you are not using the correct collation (language settings). You need to use the appropriate collation in order to display your data in the correct format.
See the link http://technet.microsoft.com/en-us/library/ms187582(v=sql.105).aspx for more details.
You can also try using a different row terminator:
bulk insert table_name
from 'filename.txt' WITH (ROWTERMINATOR='\n')
Look at this post How to write UTF-8 characters using bulk insert in SQL Server?
Quote: You can't. You should first use a N type data field, convert
your file to UTF-16 and then import it. The database does not support
UTF-8.
Original answers
look at the encoding of youre text file. Should be utf8. If not this could cause problems.
Open with notepad, file-> save as and choose encoding
After this try to import as a bulk
secondly, make sure the column datatype is nvarchar and not varchar. Also see here

Can source code examples be kept in a SQL database while retaining all formatting? If so

Can source code examples be kept in a SQL database while retaining all formatting (tabs, newlines, etc.)? If so what data type would be used?
Yes, use a TEXT type (or MEDIUMTEXT or LONGTEXT - you get the idea)
A BLOB type (varbinary) would definitely work, although databases shouldn't mangle text that's stored as varchar either.
The best in Sql Server: nvarchar(max)
You can upload this into a blob data type. SQL 2008 comes with the capability of storing the entire executable file in the database.