开发者

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:

  1. You have plenty of functions that work with nvarchar as compared to those that can handle ntext.
  2. The types 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜