Storing a UUlD as a VARCHAR in Postgresql WITHOUT any formatting - sql

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) ?

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

Changing a column type and keeping the data

I have a sql server 2005 database where one of the columns is an int. The database is full of data so I can't lose any of the data.
I need to change the the of the column from an int to a varchar(50) but this column is used in a lot of stored procedures where they are assigned to variables as int.
I want this column to store varchar now so how would I be able to do this?

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

Create table as select * from sql server with 'ntext' datatype

I have a db-link from an oracle 11 database to a SQL server database. I am trying to perform a ctas from a table in the SQL server database, however for every table with a column of datatype ntext I get the error:
ORA-00997: illegal use of LONG datatype.
How can I solve this issue? Even if I was willing to forget about those specific columns, I have about 300 tables to perform the same action on.

Use 'N at row start in SQL Server bulk statement

I am inserting data from a csv file into a SQL Server table using the bulk statement, there is some German characters in file, and I want to use 'N at start of the row (as we use it in insert statement).
How can I do this?
Thanks
You probably don't need N: this is for nvarchar columns.
The standard Latin1_General_CI_AS collation (includes varchar codepage) supports German characters already in varchar columns.