How to convert (cast) int to ntext
I need to convert int
field like 1005
to ntext
alike Alarm1005
, but CAST(ID as ntex开发者_Python百科t)
doesn't work, so how can I convert(cast) int
to ntext
?
CAST(CAST(ID as nvarchar(10)) as ntext)
?
EDIT
As gbn has justly hinted, nvarchar(max)
is actually a much more preferable type for storing large string data.
Two reasons:
- You have plenty of functions that work with
nvarchar
as compared to those that can handlentext
. - The types
ntext
,text
andimage
are officially deprecated.
And one other tiny reason is, you wouldn't have to double cast. It would be as simple as CAST(ID AS nvarchar(10))
or CAST(ID AS nvarchar(max))
.
ALTER TABLE MyTable ADD new_column NTEXT
UPDATE MyTable SET new_column = cast(old_column as nvarchar(16))
ALTER TABLE MyTable DROP COLUMN old_column
精彩评论