sql server 2000 convert binary data into string or varchar - sql-server-2000

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 ?

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

Storing a UUlD as a VARCHAR in Postgresql WITHOUT any formatting

I am moving data between two tables.
The first column is a UNIQUEIDENTIFIER in a SQL Server database.
The second column is a VARCHAR in a Postgresql database.
After the transfer:
The SQL Server UNIQUEIDENTIFIER value: 27E66FD9-79B8-4342-92A9-3CA87E497E69
The Postgresql VARCHAR value: b'27E66FD9-79B8-4342-92A9-3CA87E497E69'
I need the Postgresql VARCHAR to store the exact value, without the extra formatting (b'....')
I am using DBeaver to edit the database. What can I do while keeping the column a VARCHAR (needed for the underlying code) ?

Change date format for multiple records SQL Query

I'm having old system which is developed in MS Access and I've a requirement to convert it a web application.
In the old application we have a MS Access Database and we need to import it to SQL Server.
Now there are many tables which have datetime columns with datatype as below:
Access: LongText
SQL Server: nvarchar(MAX)
I've successfully imported the MS Access database to SQL Server but now I'm stuck in datetime conversion issue.
There is a table which have around 86000 records and we need to convert it column to datatype datetime.
currently column have nvarchar(MAX) datatype with
"dd-mm-yyyy" and here is the screenshot for the same:
https://www.screencast.com/t/OP9edlsTdbR
I've tried to fix it by doing google but nothing work as expected.
convert your all string values to appropriate style : 105 : dd-mm-yyyy
ALTER TABLE dbo.TableName ALTER COLUMN DateNeed DATETIME NULL[NOT NULL]
GO
UPDATE TableName SET DateNeed = CONVERT(DATETIME, DateNeed , 105)

Blob column - SQL Server 2014

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.

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