如何在 sql server 中的查询中连接文本? [英] How do I concatenate text in a query in sql server?

查看:40
本文介绍了如何在 sql server 中的查询中连接文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 SQL:

SELECT notes + 'SomeText'
FROM NotesTable a 

给出错误:

数据类型 nvarchar 和 text 在加法运算符中不兼容.

The data types nvarchar and text are incompatible in the add operator.

推荐答案

唯一的方法是将文本字段转换为 nvarchar 字段.

The only way would be to convert your text field into an nvarchar field.

Select Cast(notes as nvarchar(4000)) + 'SomeText'
From NotesTable a

否则,我建议在您的应用程序中进行串联.

Otherwise, I suggest doing the concatenation in your application.

这篇关于如何在 sql server 中的查询中连接文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆