Adam
Adam

Reputation: 2455

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."

Upvotes: 7

Views: 9782

Answers (2)

user5184173
user5184173

Reputation:

Try this:

SELECT  
  CONVERT(INT,CONVERT(VARCHAR(20),Client_ID)) AS ClientID
FROM Client 

Upvotes: 1

Chaos Legion
Chaos Legion

Reputation: 2970

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

CONVERT(INT, CONVERT(NVARCHAR(100), CONTRACT_ID))

Upvotes: 13

Related Questions