How to insert a line break in a SQL Server VARCHAR/NVARCHAR string(如何在 SQL Server VARCHAR/NVARCHAR 字符串中插入换行符)
问题描述
我没有看到有人问过关于此主题的任何类似问题,因此我必须针对我目前正在研究的内容对此进行研究.我想我会发布答案,以防其他人有同样的问题.
I didn't see any similar questions asked on this topic, and I had to research this for something I'm working on right now. Thought I would post the answer for it in case anyone else had the same question.
推荐答案
我在这里找到了答案:http://blog.sqlauthority.com/2007/08/22/sql-server-t-sql-script-to-insert-carriage-return-and-new-line-feed-in-code/
您只需连接字符串并在您想要换行的地方插入一个 CHAR(13).
You just concatenate the string and insert a CHAR(13) where you want your line break.
示例:
DECLARE @text NVARCHAR(100)
SET @text = 'This is line 1.' + CHAR(13) + 'This is line 2.'
SELECT @text
这会打印出以下内容:
这是第 1 行.
这是第 2 行.
This is line 1.
This is line 2.
这篇关于如何在 SQL Server VARCHAR/NVARCHAR 字符串中插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 SQL Server VARCHAR/NVARCHAR 字符串中插入换行符
基础教程推荐
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 无法解决整理冲突 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
