首页 > 解决方案 > 从 C# 中的 SQL Server 中选择带有换行符 ("\n") 的记录

问题描述

我在 SQL Server 中有一条带有换行符(“\n”)的记录,我需要从 C# 中使用SqlCommand. 这是我的 SQL 语句:

select customer_id, customer_name 
from customer 
where customer_id = 'Customer 1\n';

该记录存在于数据库中,但是当尝试使用 C# 检索它时,它不会被返回。我尝试了以下查询及其结果:

--Return the record
select customer_id, customer_name 
from customer 
where customer_id '%' + char(10) + '%'

--Not returning the record
select customer_id, customer_name  
from customer 
where customer_id char(10) + '%'

select customer_id, customer_name  
from customer  
where customer_id '%' + char(10)

任何帮助高度赞赏。

标签: c#sql-server

解决方案


DECLARE @NewLineChar AS CHAR(2) = CHAR(13) + CHAR(10)
select customer_id,customer_name from customer where customer_id='Customer' + @NewLineChar;

推荐阅读