SQL:在 varchar 字符串中插入换行符 [英] SQL: Insert a linebreak in varchar string

查看:48
本文介绍了SQL:在 varchar 字符串中插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 StackOverflow 上搜索了有关如何在 SQL 文本字符串中插入换行符的所有可能解决方案.我已经提到了这个链接,但无济于事.

我为您的查询得到的结果如下(它们有效)

I've searched StackOverflow for all the possible solutions concerning how to insert a linebreak in a SQL text string. I've referred this link but to no avail. How to insert a line break in a SQL Server VARCHAR/NVARCHAR string

But none of the solutions are working for me.

This is what I'm trying to do:

insert into sample (dex, col) 
values (2, 'This is line 1.' + CHAR(13)+CHAR(10) + 'This is line 2.')

But this is the output generated: (Select Col from sample where dex = 2)

This is line 1. This is line 2.

This is the output that I desire:

This is line 1.
This is line 2.

I'm using SQL server and SSMS if that helps.

Any ideas why it isn't working?

解决方案

Well your query works perfectly fine. SSMS by default shows all query out put in the grid view, which does not display the line break character.

To see it you can switch to text view using cntrl + T shortcut or like below

The results I got for your query are below( and they work)

这篇关于SQL:在 varchar 字符串中插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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