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."
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.
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).
You first convert it to NVARCHAR and then to INT. As follows:
CONVERT(INT, CONVERT(NVARCHAR(100), CONTRACT_ID))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With