Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS SQL Server NTEXT to INT

How can I transform/convert/cast a column with type [ntext] into a column type [int]? Let's suppose the column name is Client_ID and the table is Client. I am using MS SQL Server 2014.

I tried with:

SELECT
CONVERT (INT, a.CONTRACT_ID)
FROM [dbo].[src_CONTRACT_CONFIGXML] as a

The error message I am getting is: "Explicit conversion from data type ntext to int is not allowed."

like image 616
Adam Avatar asked Jun 03 '16 07:06

Adam


People also ask

What does Ntext mean in SQL?

SQL Binary. NTEXT is a variable-length data type that can store long Unicode character strings. NTEXT can hold up to 2,147,483,647 bytes of data. The actual storage used depends on the length of the character string.

What is the difference between Ntext and Nvarchar Max?

ntext will always store its data in a separate database page, while nvarchar(max) will try to store the data within the database record itself. So nvarchar(max) is somewhat faster (if you have text that is smaller as 8 kB).


1 Answers

You first convert it to NVARCHAR and then to INT. As follows:

CONVERT(INT, CONVERT(NVARCHAR(100), CONTRACT_ID))
like image 118
Chaos Legion Avatar answered Jan 03 '23 05:01

Chaos Legion