Blob column - SQL Server 2014 - sql

I have a column stored as blob data type in SQL Server 2014. I want to extract the blob column into a string. I tried the following SQL statement, but long string is getting truncated by varchar(max) (due that the maximum storage size is 2^31-1 bytes (2 GB))
SELECT CONVERT(VarChar(max), blobfield)
Is there a way in SQL Server to view complete string on blob to text conversion?
Thanks in advance.

Related

Converted data with NUMBER in Oracle to NUMERIC in SQL Server with openquery

I have a linked server to Oracle database in SQL server and retrieve data to local SQL server database every day by scheduling, the problem is: one of the Oracle database column has holding number with 18 fixed digits which type is NUMBER(18) and when I am trying converting that column to numeric(18,0) or numeric(38,0) and so on, the data converted but for many of them, last digit is different with source data, for example:
data in Oracle database(source): 100002345678912345
data in SQL database (destination): 100002345678912348
Thanks to #Jeroen Mostert.
I used DBCC TRACEON (7314) before INSERT INTO and my data is changed to DOUBLE type, after that to solve the problem I used SELECT CAST(COLUMN_NAME AS numeric(18,0))
for example:
My Real Data:100002345678912345
My Data (wrong data): 100002345678912348
My Data after using DBCC TRACEON (7314):
100002345678912345.0000000000
My Data after using SELECT CAST(COLUMN_NAME AS NUMERIC(18,0)):
100002345678912345

How to load proper data with openrowset in sql server

Data is like below in CVS file, Loading to SQL server using openrowset. Number rows are converted fine but number with text(xy1468028906,ab1468028906) rows converted to null.
1468028906
1783084622
xy1468028906
AB1783084622
Column data type in the tabel is nvarchar(max)
So, the data is loaded into table like below
1468028906
1783084622
null
null
How can we load data properly, any suggest.

Distinct error with image field

I have table which contains a Image column. Now I want to select distinct value of image column, but it gives error. Column name is also Image.
My query is: select Image from tbl1
Error is: The image data type cannot be selected as DISTINCT because it is not comparable.
So how to select distinct value from tb1 table
Image data types in a SELECT statement that contains the DISTINCT clause. Depending on the version of SQL Server being used, there are a few ways of overcoming this restriction.
For SQL Server 2000, a TEXT column can be converted to a VARCHAR data type, an NTEXT column can be converted to an NVARCHAR data type while an IMAGE data type can be converted to VARBINARY data type. The SELECT statements earlier which contain the DISTINCT clause can be rewritten as follows and avoid the error message:
SELECT DISTINCT [BookTitle], CAST([BookSummary] AS NVARCHAR(4000)) AS [BookSummary]
FROM [dbo].[Book]
SELECT DISTINCT [BookTitle], CAST([BookImage] AS VARBINARY(8000)) AS [BookImage]
FROM [dbo].[Book]
For SQL Server 2005 and SQL Server 2008 (and later), instead of limiting the NVARCHAR to 4000 characters or the VARCHAR or VARBINARY to 8000 characters, the MAX specifier can be used in its place, as can be seen in the following SELECT statements:
SELECT DISTINCT [BookTitle], CAST([BookSummary] AS NVARCHAR(MAX)) AS [BookSummary]
FROM [dbo].[Book]
SELECT DISTINCT [BookTitle], CAST([BookImage] AS VARBINARY(MAX)) AS [BookImage]
FROM [dbo].[Book]
If using SQL Server 2005 or SQL Server 2008 (or later), another way of overcoming this restriction and this error message without using the CAST or CONVERT function to convert the text, ntext and image data types to varchar, nvarchar and varbinary, respectively, is to change the data types of the columns to VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX). TEXT, NTEXT and IMAGE data types will be removed in a future version of Microsoft SQL Server and use of these data types should be avoided.
Reference:
http://www.sql-server-helper.com/error-messages/msg-421.aspx

Oracle SQL display blob contents greater than varchar2 max limit

How do I display the rest of the xml for this sql query since varchar2 is only limited to 2000?
Column msg is a blob which contains compressed XML
Each row will have different msg length ranging from 500 to 6000 bytes as least
select utl_raw.cast_to_varchar2(dbms_lob.substr(utl_compress.lz_uncompress(xml.msg),2000,1)) as XML_Msg from xml_table xml;
This could be a possible solution Convert Blob to Varchar datatype but I don't know what it would do to my database.
In Oracle the MAX you can retrieve from blob data type is 4000 bytes , below is statment that can do the job. I ran into the same problem two weeks ago , please refer to my post for more details. Java Class for retrieving Large String from Oracle_db of LOB dataType
Select dbms_lob.substr( BLOB_FieldName, 4000, 1 )
from Database name Where [Condition];

sql server 2000 convert binary data into string or varchar

i have some data in my SQL Server 2000 of type binary(16) that i need to convert into varchar or string.
What i have tried (i found it here):
sys.fn_sqlvarbasetostr(My_Binary_Data)
But this dose not work in SQL Server 2000 so what are the other options or solutions i have to convert binary data into varchar ?