我需要将类似1005
int
字段转换为类似于Alarm1005
ntext
,但是CAST(ID as ntext)
不起作用,所以如何将int
转换(cast)为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:
nvarchar
as compared to those that can handle ntext
. ntext
, text
and image
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.